List of usage examples for org.w3c.dom Element setAttribute
public void setAttribute(String name, String value) throws DOMException;
From source file:ru.itdsystems.alfresco.persistence.CrudPost.java
@Override public void execute(WebScriptRequest req, WebScriptResponse res) throws WebScriptException { // construct path elements array from request parameters List<String> pathElements = new ArrayList<String>(); Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); pathElements.add(templateVars.get("application_name")); pathElements.add(templateVars.get("form_name")); doBefore(pathElements, null);/*from ww w . java 2 s . co m*/ // parse xml from request and perform a search Document searchXML; DocumentBuilder xmlBuilder; DocumentBuilderFactory xmlFact; try { xmlFact = DocumentBuilderFactory.newInstance(); xmlFact.setNamespaceAware(true); xmlBuilder = xmlFact.newDocumentBuilder(); searchXML = xmlBuilder.parse(req.getContent().getInputStream()); } catch (Exception e) { throw new WebScriptException(500, "Error occured while parsing XML from request.", e); } XPath xpath = XPathFactory.newInstance().newXPath(); Integer pageSize; Integer pageNumber; String lang; // String applicationName; // String formName; NodeList queries; // extract search details try { pageSize = new Integer( ((Node) xpath.evaluate("/search/page-size/text()", searchXML, XPathConstants.NODE)) .getNodeValue()); pageNumber = new Integer( ((Node) xpath.evaluate("/search/page-number/text()", searchXML, XPathConstants.NODE)) .getNodeValue()); lang = ((Node) xpath.evaluate("/search/lang/text()", searchXML, XPathConstants.NODE)).getNodeValue(); // applicationName = ((Node) xpath.evaluate("/search/app/text()", // searchXML, XPathConstants.NODE)).getNodeValue(); // formName = ((Node) xpath.evaluate("/search/form/text()", // searchXML, // XPathConstants.NODE)).getNodeValue(); queries = (NodeList) xpath.evaluate("/search/query", searchXML, XPathConstants.NODESET); if (queries.getLength() == 0) throw new Exception("No queries found."); } catch (Exception e) { throw new WebScriptException(500, "XML in request is malformed.", e); } // check if requested query is supported if (!"".equals(queries.item(0).getTextContent())) throw new WebScriptException(500, "Freetext queries are not supported at the moment."); // resolve path to root data pathElements.add("data"); NodeRef nodeRef = getRootNodeRef(); // resolve path to file FileInfo fileInfo = null; Integer totalForms = 0; try { // fileInfo = fileFolderService.resolveNamePath(nodeRef, pathElements, false); fileInfo = fileFolderService.resolveNamePath(nodeRef, pathElements); } catch (FileNotFoundException e) { // do nothing here } if (fileInfo != null) { // iterate through all forms List<ChildAssociationRef> assocs = nodeService.getChildAssocs(fileInfo.getNodeRef()); List<String> details = new ArrayList<String>(); Document resultXML; try { resultXML = xmlBuilder.newDocument(); } catch (Exception e) { throw new WebScriptException(500, "Smth really strange happened o.O", e); } Element rootElement = resultXML.createElement("documents"); rootElement.setAttribute("page-size", pageSize.toString()); rootElement.setAttribute("page-number", pageNumber.toString()); rootElement.setAttribute("query", ""); resultXML.appendChild(rootElement); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZZ"); int skip = pageSize * (pageNumber - 1); Integer found = 0; Integer searchTotal = 0; for (ChildAssociationRef assoc : assocs) { if ((nodeRef = nodeService.getChildByName(assoc.getChildRef(), ContentModel.ASSOC_CONTAINS, "data.xml")) != null) { // parse file Document dataXML; try { dataXML = xmlBuilder.parse(fileFolderService.getReader(nodeRef).getContentInputStream()); } catch (Exception e) { throw new WebScriptException(500, "Form file is malformed.", e); } totalForms++; details.clear(); xpath.setNamespaceContext(new OrbeonNamespaceContext()); // execute search queries for (int i = 1; i < queries.getLength(); i++) { Node query = queries.item(i); String path = query.getAttributes().getNamedItem("path").getNodeValue(); String match = query.getAttributes().getNamedItem("match").getNodeValue(); String queryString = query.getTextContent(); if (path == null || match == null || queryString == null) throw new WebScriptException(500, "Search query XML is malformed."); path = path.replace("$fb-lang", "'" + lang + "'"); boolean exactMatch = "exact".equals(match); Node queryResult; try { queryResult = (Node) xpath.evaluate(path, dataXML.getDocumentElement(), XPathConstants.NODE); } catch (Exception e) { throw new WebScriptException(500, "Error in query xpath expression.", e); } if (queryResult == null) break; String textContent = queryResult.getTextContent(); // TODO // check type while comparing values if (exactMatch && queryString.equals(textContent) || !exactMatch && textContent != null && textContent.contains(queryString) || queryString.isEmpty()) details.add(textContent); else break; } // add document to response xml if (details.size() == queries.getLength() - 1) { searchTotal++; if (skip > 0) skip--; else if (++found <= pageSize) { Element item = resultXML.createElement("document"); String createdText = dateFormat .format(fileFolderService.getFileInfo(nodeRef).getCreatedDate()); item.setAttribute("created", createdText.substring(0, 26) + ":" + createdText.substring(26)); String modifiedText = dateFormat .format(fileFolderService.getFileInfo(nodeRef).getModifiedDate()); item.setAttribute("last-modified", modifiedText.substring(0, 26) + ":" + modifiedText.substring(26)); item.setAttribute("name", fileFolderService.getFileInfo(assoc.getChildRef()).getName()); resultXML.getDocumentElement().appendChild(item); Element detailsElement = resultXML.createElement("details"); item.appendChild(detailsElement); for (String detail : details) { Element detailElement = resultXML.createElement("detail"); detailElement.appendChild(resultXML.createTextNode(detail)); detailsElement.appendChild(detailElement); } } /* * else break; */ } } } rootElement.setAttribute("total", totalForms.toString()); rootElement.setAttribute("search-total", searchTotal.toString()); // stream output to client try { TransformerFactory.newInstance().newTransformer().transform(new DOMSource(resultXML), new StreamResult(res.getOutputStream())); } catch (Exception e) { throw new WebScriptException(500, "Error occured while streaming output to client.", e); } } }
From source file:com.dinstone.jrpc.spring.EndpointBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String id = element.getAttribute("id"); if (!StringUtils.hasText(id)) { id = endpointClass.getSimpleName() + "-" + count.incrementAndGet(); builder.addPropertyValue("id", id); element.setAttribute("id", id); } else {//from www . j av a 2s . c om builder.addPropertyValue("id", id); } String name = element.getAttribute("name"); if (!StringUtils.hasText(name)) { String[] pidName = ManagementFactory.getRuntimeMXBean().getName().split("@"); builder.addPropertyValue("name", pidName[1] + ":" + pidName[0]); } else { builder.addPropertyValue("name", name); } builder.addPropertyValue("transportBean", getConfigBeanDefinition(element, parserContext, "transport")); builder.addPropertyValue("registryBean", getConfigBeanDefinition(element, parserContext, "registry")); }
From source file:chat.viska.xmpp.plugins.webrtc.WebRtcPlugin.java
@Nonnull public Completable sendSdp(@Nonnull final Jid recipient, @Nonnull final String id, @Nonnull final SessionDescription sdp, final boolean creating) { final Document iq = Stanza.getIqTemplate(Stanza.IqType.SET, UUID.randomUUID().toString(), getSession().getNegotiatedJid(), recipient); final Element webrtcElement = (Element) iq.getDocumentElement() .appendChild(iq.createElementNS(XMLNS, "webrtc")); webrtcElement.setAttribute("id", id); if (creating) { webrtcElement.setAttribute("action", "create"); }//from w w w . j a v a 2 s . co m final Element sdpElement = (Element) webrtcElement.appendChild(iq.createElement("sdp")); if (sdp.type != null) { sdpElement.setAttribute("type", sdp.type.canonicalForm()); } for (String line : sdp.description.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:it.unibas.spicy.persistence.xml.operators.ExportXSD.java
private void verifyMaxOccurs(Element element, INode node) { if (node.getFather() instanceof SetNode) { element.setAttribute("maxOccurs", "unbounded"); if (logger.isDebugEnabled()) logger.debug(" Attribute MaxOccours for element: " + element.getNodeName() + "- Node analyzed : " + node.getLabel());//ww w.j a va 2s . c om if (logger.isDebugEnabled()) logger.debug(" maxOccurs = " + element.getAttribute("maxOccurs")); } }
From source file:com.nortal.jroad.wsdl.XTeeWsdlDefinition.java
private void addXRoadExtensions(Definition definition) throws WSDLException { definition.addNamespace(XROAD_PREFIX, XROAD_NAMESPACE); Message message = definition.createMessage(); message.setQName(new QName(definition.getTargetNamespace(), XROAD_HEADER)); addXroadHeaderPart(definition, message, XTeeHeader.CLIENT); addXroadHeaderPart(definition, message, XTeeHeader.SERVICE); addXroadHeaderPart(definition, message, XTeeHeader.ID); addXroadHeaderPart(definition, message, XTeeHeader.USER_ID); addXroadHeaderPart(definition, message, XTeeHeader.PROTOCOL_VERSION); message.setUndefined(false);//from w w w . java 2 s. c o m definition.addMessage(message); // Add XRoad schema import to the first schema for (Object ex : definition.getTypes().getExtensibilityElements()) { if (ex instanceof Schema) { Schema schema = (Schema) ex; Element xRoadImport = schema.getElement().getOwnerDocument() .createElement(schema.getElement().getPrefix() == null ? "import" : schema.getElement().getPrefix() + ":import"); xRoadImport.setAttribute("namespace", XROAD_NAMESPACE); xRoadImport.setAttribute("schemaLocation", XROAD_NAMESPACE); schema.getElement().insertBefore(xRoadImport, schema.getElement().getFirstChild()); break; } } }
From source file:eu.europa.esig.dss.xades.signature.XAdESLevelBaselineT.java
private void incorporateC14nMethod(final Element parentDom, final String signedInfoC14nMethod) { //<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> final Element canonicalizationMethodDom = documentDom.createElementNS(XMLNS, DS_CANONICALIZATION_METHOD); canonicalizationMethodDom.setAttribute(ALGORITHM, signedInfoC14nMethod); parentDom.appendChild(canonicalizationMethodDom); }
From source file:fr.aliasource.webmail.proxy.impl.ResponderImpl.java
/** * @param m/* www . j a v a 2 s . c o m*/ * @param me */ private void messageDetail(MailMessage m, Element me) { me.setAttribute("date", "" + (m.getDate() != null ? m.getDate().getTime() : 0)); me.setAttribute("read", "" + m.isRead()); me.setAttribute("starred", "" + m.isStarred()); me.setAttribute("answered", "" + m.isAnswered()); me.setAttribute("hp", "" + m.isHighPriority()); me.setAttribute("uid", "" + m.getUid()); String sub = m.getSubject(); if (sub == null) { sub = "[Empty Subject]"; } DOMUtils.createElementAndText(me, "subject", sub); Address sender = m.getSender(); Element from = DOMUtils.createElement(me, "from"); if (sender != null) { String ma = sender.getMail().replace("<", "").replace(">", ""); from.setAttribute("addr", ma); from.setAttribute("displayName", "" + sender.getDisplayName()); } else { from.setAttribute("addr", "from@is.not.set"); from.setAttribute("displayName", "From not set"); } addRecipients(DOMUtils.createElement(me, "to"), m.getTo()); addRecipients(DOMUtils.createElement(me, "cc"), m.getCc()); addRecipients(DOMUtils.createElement(me, "bcc"), m.getBcc()); Element attachements = DOMUtils.createElement(me, "attachements"); for (String attach : m.getAttachements().keySet()) { Element ae = DOMUtils.createElement(attachements, "a"); ae.setAttribute("id", attach); } Element invitation = DOMUtils.createElement(me, "invitation"); if (m.getInvitation() != null) { invitation.setTextContent("true"); } else { invitation.setTextContent("false"); } if (!m.getDispositionNotificationTo().isEmpty()) { Element dispositionNotification = DOMUtils.createElement(me, "disposition-notification"); addRecipients(dispositionNotification, m.getDispositionNotificationTo()); } if (m.getBody() != null) { formatBody(m, me); } }
From source file:fr.aliasource.webmail.proxy.impl.ResponderImpl.java
public void sendConversationsPage(ConversationReferenceList listConversations) { try {/* w w w. j av a2s. com*/ Document doc = DOMUtils.createDoc("http://obm.aliasource.fr/xsd/conversations_page", "conversationsPage"); Element root = doc.getDocumentElement(); root.setAttribute("fullLength", "" + listConversations.getFullLength()); VersionnedList<ConversationReference> page = listConversations.getPage(); root.setAttribute("version", "" + page.getVersion()); if (logger.isDebugEnabled()) { logger.debug(page.size() + " conversations."); } for (ConversationReference cr : page) { appendConversation(root, cr); } sendDom(doc); } catch (Exception e) { logger.error(e.getMessage(), e); } }
From source file:com.icesoft.faces.component.ext.renderkit.GroupRenderer.java
protected Element createHiddenField(DOMContext domContext, FacesContext facesContext, UIComponent uiComponent, String name) {//from w ww . j a va 2 s .c om Element ele = domContext.createElement(HTML.INPUT_ELEM); ele.setAttribute(HTML.TYPE_ATTR, "hidden"); String n = ClientIdPool.get(getHiddenFieldName(facesContext, uiComponent, name)); ele.setAttribute(HTML.NAME_ATTR, n); ele.setAttribute(HTML.ID_ATTR, n); ele.setAttribute(HTML.VALUE_ATTR, ""); ele.setAttribute(HTML.AUTOCOMPLETE_ATTR, "off"); return ele; }
From source file:net.ion.radon.impl.let.webdav.FCKConnectorRestlet.java
protected Node createCommonXML(final Document doc, final String commandStr, final String typeStr, final String currentPath, final String currentUrl) { final Element root = doc.createElement("Connector"); root.setAttribute("command", commandStr); root.setAttribute("resourceType", typeStr); final Element myEl = doc.createElement("CurrentFolder"); myEl.setAttribute("path", currentPath); myEl.setAttribute("url", currentUrl); root.appendChild(myEl);/*w w w .j a va 2 s .c om*/ doc.appendChild(root); return root; }