List of usage examples for org.w3c.dom Element getLocalName
public String getLocalName();
From source file:nl.b3p.viewer.admin.stripes.GeoServiceActionBean.java
public Resolution validateSldXml() { Resolution jsp = new ForwardResolution(JSP_EDIT_SLD); Document sldXmlDoc = null;/* w ww .j a va 2 s.c o m*/ String stage = "Fout bij parsen XML document"; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); sldXmlDoc = db.parse(new ByteArrayInputStream(sld.getSldBody().getBytes("UTF-8"))); stage = "Fout bij controleren SLD"; Element root = sldXmlDoc.getDocumentElement(); if (!"StyledLayerDescriptor".equals(root.getLocalName())) { throw new Exception("Root element moet StyledLayerDescriptor zijn"); } String version = root.getAttribute("version"); if (version == null || !("1.0.0".equals(version) || "1.1.0".equals(version))) { throw new Exception("Geen of ongeldige SLD versie!"); } SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema s = sf .newSchema(new URL("http://schemas.opengis.net/sld/" + version + "/StyledLayerDescriptor.xsd")); s.newValidator().validate(new DOMSource(sldXmlDoc)); } catch (Exception e) { String extra = ""; if (e instanceof SAXParseException) { SAXParseException spe = (SAXParseException) e; if (spe.getLineNumber() != -1) { extra = " (regel " + spe.getLineNumber(); if (spe.getColumnNumber() != -1) { extra += ", kolom " + spe.getColumnNumber(); } extra += ")"; } } getContext().getValidationErrors() .addGlobalError(new SimpleError("{2}: {3}{4}", stage, ExceptionUtils.getMessage(e), extra)); return jsp; } getContext().getMessages().add(new SimpleMessage("SLD is valide!")); return jsp; }
From source file:org.alfresco.web.forms.xforms.Schema2XForms.java
protected String setXFormsId(final Element el, String id) { if (el.hasAttributeNS(null, "id")) { el.removeAttributeNS(null, "id"); }/* w w w . j a va 2s . c om*/ if (id == null) { final String name = el.getLocalName(); final Long l = this.counter.get(name); final long count = (l != null) ? l : 0; // increment the counter this.counter.put(name, new Long(count + 1)); id = name + "_" + count; } el.setAttributeNS(null, "id", id); return id; }
From source file:org.alfresco.web.forms.xforms.Schema2XForms.java
/** * Add a repeat section if maxOccurs > 1. *///from ww w.j a v a2 s . c o m private Element addRepeatIfNecessary(final Document xformsDocument, final Element modelSection, final Element formSection, final XSTypeDefinition controlType, final String pathToRoot, final SchemaUtil.Occurrence o) { // add xforms:repeat section if this element re-occurs if ((o.isOptional() && (controlType instanceof XSSimpleTypeDefinition || "anyType".equals(controlType.getName()))) || (o.maximum == 1 && o.minimum == 1) || (controlType instanceof XSComplexTypeDefinition && pathToRoot.equals(""))) { return formSection; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("[addRepeatIfNecessary] for multiple element for type " + controlType.getName() + ", maxOccurs = " + o.maximum); } final Element repeatSection = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":repeat"); //bind instead of repeat //repeatSection.setAttributeNS(NamespaceConstants.XFORMS_NS,NamespaceConstants.XFORMS_PREFIX + ":nodeset",pathToRoot); // bind -> last element in the modelSection Element bind = DOMUtil.getLastChildElement(modelSection); // ALF-9524 fix, previously we've added extra bind element, so last child is not correct for repeatable switch String attribute = bind.getAttribute(NamespaceConstants.XFORMS_PREFIX + ":relevant"); if (controlType instanceof XSComplexTypeDefinition && ((XSComplexTypeDefinition) controlType).getDerivationMethod() == XSConstants.DERIVATION_EXTENSION && attribute != null && !attribute.isEmpty()) { bind = modelSection; } String bindId = null; if (bind != null && bind.getLocalName() != null && "bind".equals(bind.getLocalName())) { bindId = bind.getAttributeNS(null, "id"); } else { LOGGER.warn("[addRepeatIfNecessary] bind not found: " + bind + " (model selection name = " + modelSection.getNodeName() + ")"); //if no bind is found -> modelSection is already a bind, get its parent last child bind = DOMUtil.getLastChildElement(modelSection.getParentNode()); if (bind != null && bind.getLocalName() != null && "bind".equals(bind.getLocalName())) { bindId = bind.getAttributeNS(null, "id"); } else { LOGGER.warn("[addRepeatIfNecessary] bind really not found"); } } repeatSection.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":bind", bindId); this.setXFormsId(repeatSection); //appearance=full is more user friendly repeatSection.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":appearance", "full"); formSection.appendChild(repeatSection); //add a group inside the repeat? final Element group = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":group"); group.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":appearance", "repeated"); this.setXFormsId(group); repeatSection.appendChild(group); return group; }
From source file:org.alfresco.web.forms.xforms.XFormsBean.java
private Node getEventLog() { final Document result = XMLUtil.newDocument(); final Element eventsElement = result.createElement("events"); result.appendChild(eventsElement);/* ww w.j a va2s .co m*/ for (XMLEvent xfe : this.getXformsSession().getEventLog()) { final String type = xfe.getType(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("adding event " + type + " to the event log"); } final Element target = (Element) xfe.getTarget(); final Element eventElement = result.createElement(type); eventsElement.appendChild(eventElement); eventElement.setAttribute("targetId", target.getAttributeNS(null, "id")); eventElement.setAttribute("targetName", target.getLocalName()); final Collection properties = xfe.getPropertyNames(); if (properties != null) { for (Object name : properties) { final Object value = xfe.getContextInfo((String) name); if (LOGGER.isDebugEnabled()) { LOGGER.debug("adding property {" + name + ":" + value + "} to event " + type); } final Element propertyElement = result.createElement("property"); eventElement.appendChild(propertyElement); propertyElement.setAttribute("name", name.toString()); propertyElement.setAttribute("value", value != null ? value.toString() : null); } } if (LOGGER.isDebugEnabled() && XFormsEventNames.SUBMIT_ERROR.equals(type)) { // debug for figuring out which elements aren't valid for submit LOGGER.debug("performing full revalidate"); try { final Model model = this.getXformsSession().getChibaBean().getContainer().getDefaultModel(); final Instance instance = model.getDefaultInstance(); model.getValidator().validate(instance, "/", new DefaultValidatorMode()); final Iterator<ModelItem> it = instance.iterateModelItems("/"); while (it.hasNext()) { final ModelItem modelItem = it.next(); if (!modelItem.isValid()) { LOGGER.debug("model node " + modelItem.getNode() + " is invalid"); } if (modelItem.isRequired() && modelItem.getValue().length() == 0) { LOGGER.debug("model node " + modelItem.getNode() + " is empty and required"); } } } catch (final XFormsException xfe2) { LOGGER.debug("error performing revaliation", xfe2); } } } this.xformsSession.eventLog.clear(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("generated event log:\n" + XMLUtil.toString(result)); } return result; }
From source file:org.apache.axis.AxisFault.java
/** * turn the fault and details into a string, with XML escaping. * subclassers: for security (cross-site-scripting) reasons, * escape everything that could contain caller-supplied data. * @return stringified fault details//from ww w . j av a2 s .co m */ public String dumpToString() { StringBuffer buf = new StringBuffer("AxisFault"); buf.append(JavaUtils.LS); buf.append(" faultCode: "); buf.append(XMLUtils.xmlEncodeString(faultCode.toString())); buf.append(JavaUtils.LS); buf.append(" faultSubcode: "); if (faultSubCode != null) { for (int i = 0; i < faultSubCode.size(); i++) { buf.append(JavaUtils.LS); buf.append(faultSubCode.elementAt(i).toString()); } } buf.append(JavaUtils.LS); buf.append(" faultString: "); try { buf.append(XMLUtils.xmlEncodeString(faultString)); } catch (RuntimeException re) { buf.append(re.getMessage()); } buf.append(JavaUtils.LS); buf.append(" faultActor: "); buf.append(XMLUtils.xmlEncodeString(faultActor)); buf.append(JavaUtils.LS); buf.append(" faultNode: "); buf.append(XMLUtils.xmlEncodeString(faultNode)); buf.append(JavaUtils.LS); buf.append(" faultDetail: "); if (faultDetails != null) { for (int i = 0; i < faultDetails.size(); i++) { Element e = (Element) faultDetails.get(i); buf.append(JavaUtils.LS); buf.append("\t{"); buf.append(null == e.getNamespaceURI() ? "" : e.getNamespaceURI()); buf.append("}"); buf.append(null == e.getLocalName() ? "" : e.getLocalName()); buf.append(":"); buf.append(XMLUtils.getInnerXMLString(e)); } } buf.append(JavaUtils.LS); return buf.toString(); }
From source file:org.apache.axis.AxisFault.java
/** * Find a fault detail element by its qname. * @param qname name of the node to look for * @return the matching element or null/* w w w. j a v a2s. c om*/ * @since axis1.1 */ public Element lookupFaultDetail(QName qname) { if (faultDetails != null) { //extract details from the qname. the empty namespace is represented //by the empty string String searchNamespace = qname.getNamespaceURI(); String searchLocalpart = qname.getLocalPart(); //now spin through the elements, seeking a match Iterator it = faultDetails.iterator(); while (it.hasNext()) { Element e = (Element) it.next(); String localpart = e.getLocalName(); if (localpart == null) { localpart = e.getNodeName(); } String namespace = e.getNamespaceURI(); if (namespace == null) { namespace = ""; } //we match on matching namespace and local part; empty namespace //in an element may be null, which matches QName's "" if (searchNamespace.equals(namespace) && searchLocalpart.equals(localpart)) { return e; } } } return null; }
From source file:org.apache.axis.deployment.wsdd.WSDDDocument.java
/** * bind to a sub-element in a document.//ww w. jav a 2s . co m * @param e (Element) XXX */ public WSDDDocument(Element e) throws WSDDException { doc = e.getOwnerDocument(); if (ELEM_WSDD_UNDEPLOY.equals(e.getLocalName())) { undeployment = new WSDDUndeployment(e); } else { deployment = new WSDDDeployment(e); } }
From source file:org.apache.axis.deployment.wsdd.WSDDDocument.java
/** * Bind to a new document, setting the undeployment nodes if it is an undeployment, * the deployment tree if it is anything else. * @param document XXX//from w ww . j a va2 s. c o m */ public void setDocument(Document document) throws WSDDException { this.doc = document; Element docEl = doc.getDocumentElement(); if (ELEM_WSDD_UNDEPLOY.equals(docEl.getLocalName())) { undeployment = new WSDDUndeployment(docEl); } else { deployment = new WSDDDeployment(docEl); } }
From source file:org.apache.axis.encoding.SerializationContext.java
/** * Output a DOM representation to a SerializationContext * @param el is a DOM Element/*from w w w .j av a 2s . co m*/ */ public void writeDOMElement(Element el) throws IOException { if (startOfDocument && sendXMLDecl) { writeXMLDeclaration(); } // If el is a Text element, write the text and exit if (el instanceof org.apache.axis.message.Text) { writeSafeString(((Text) el).getData()); return; } AttributesImpl attributes = null; NamedNodeMap attrMap = el.getAttributes(); if (attrMap.getLength() > 0) { attributes = new AttributesImpl(); for (int i = 0; i < attrMap.getLength(); i++) { Attr attr = (Attr) attrMap.item(i); String tmp = attr.getNamespaceURI(); if (tmp != null && tmp.equals(Constants.NS_URI_XMLNS)) { String prefix = attr.getLocalName(); if (prefix != null) { if (prefix.equals("xmlns")) prefix = ""; String nsURI = attr.getValue(); registerPrefixForURI(prefix, nsURI); } continue; } attributes.addAttribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getName(), "CDATA", attr.getValue()); } } String namespaceURI = el.getNamespaceURI(); String localPart = el.getLocalName(); if (namespaceURI == null || namespaceURI.length() == 0) localPart = el.getNodeName(); QName qName = new QName(namespaceURI, localPart); startElement(qName, attributes); NodeList children = el.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { writeDOMElement((Element) child); } else if (child instanceof CDATASection) { writeString("<![CDATA["); writeString(((Text) child).getData()); writeString("]]>"); } else if (child instanceof Comment) { writeString("<!--"); writeString(((CharacterData) child).getData()); writeString("-->"); } else if (child instanceof Text) { writeSafeString(((Text) child).getData()); } } endElement(); }
From source file:org.apache.axis.encoding.SerializationContextImpl.java
/** * Output a DOM representation to a SerializationContext * @param el is a DOM Element//from ww w . j a v a 2 s .c o m */ public void writeDOMElement(Element el) throws IOException { AttributesImpl attributes = null; NamedNodeMap attrMap = el.getAttributes(); if (attrMap.getLength() > 0) { attributes = new AttributesImpl(); for (int i = 0; i < attrMap.getLength(); i++) { Attr attr = (Attr)attrMap.item(i); String tmp = attr.getNamespaceURI(); if ( tmp != null && tmp.equals(Constants.NS_URI_XMLNS) ) { String prefix = attr.getLocalName(); if (prefix != null) { if (prefix.equals("xmlns")) prefix = ""; String nsURI = attr.getValue(); registerPrefixForURI(prefix, nsURI); } continue; } attributes.addAttribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getName(), "CDATA", attr.getValue()); } } String namespaceURI = el.getNamespaceURI(); String localPart = el.getLocalName(); if(namespaceURI == null || namespaceURI.length()==0) localPart = el.getNodeName(); QName qName = new QName(namespaceURI, localPart); startElement(qName, attributes); NodeList children = el.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { writeDOMElement((Element)child); } else if (child instanceof CDATASection) { writeString("<![CDATA["); writeString(((Text)child).getData()); writeString("]]>"); } else if (child instanceof Comment) { writeString("<!--"); writeString(((CharacterData)child).getData()); writeString("-->"); } else if (child instanceof Text) { writeSafeString(((Text)child).getData()); } } endElement(); }