List of usage examples for com.google.gwt.xml.client Attr getName
String getName();
From source file:com.calclab.emite.base.xml.XMLPacketImplGWT.java
License:Open Source License
@Override public ImmutableMap<String, String> getAttributes() { final ImmutableMap.Builder<String, String> result = ImmutableMap.builder(); final NamedNodeMap attribs = element.getAttributes(); for (int i = 0; i < attribs.getLength(); i++) { final Attr attrib = (Attr) attribs.item(i); result.put(attrib.getName(), attrib.getValue()); }//from w w w .ja v a 2 s.co m return result.build(); }
From source file:com.colinalworth.xmlview.client.ElementCell.java
License:Apache License
/** * @param context/* w w w. j ava 2s. c o m*/ * @param value */ private void finishEdit(Node value, com.google.gwt.dom.client.Element target) { ElementCell.ViewState state = updateViewState(lastKey, value, target); String newValue = target.<InputElement>cast().getValue(); boolean valid = true; Element parent = (Element) value.getParentNode(); switch (state.section) { case AttributeName: Attr attr = (Attr) value; //TODO this might lose namespace data parent.removeAttribute(attr.getName()); parent.setAttribute(newValue, attr.getValue()); valid = validator.isAttributeNameValid(parent.getAttributeNode(attr.getName()), parent); break; case AttributeValue: value.setNodeValue(newValue); valid = validator.isAttributeValueValid((Attr) value, parent); break; case Content: ((CharacterData) value).setData(newValue); valid = validator.isContentsValid((CharacterData) value); break; case TagName: Element elt = (Element) value; Element replacement = elt.getOwnerDocument().createElement(newValue); while (elt.getChildNodes().getLength() != 0) { replacement.appendChild(elt.getChildNodes().item(0)); } //TODO this might lose namespace data for (int i = 0; i < elt.getAttributes().getLength(); i++) { Attr a = (Attr) elt.getAttributes().item(i); replacement.setAttribute(a.getName(), a.getValue()); } parent.replaceChild(replacement, elt); valid = validator.isElementNameValid(replacement); } if (!valid) { Window.alert("Seems to be invalid: " + newValue + " in " + parent.getNodeName()); //TODO mark invalid } this.lastKey = null; target.blur(); }
From source file:com.colinalworth.xmlview.client.validator.SimpleRpcXmlValidator.java
License:Apache License
@Override public boolean isAttributeNameValid(Attr attr, Element parent) { //TODO make sure there are no attr duplicates (this is never legal, correct?) return schema.getAllowedAttributes().get(parent.getNodeName()).contains(attr.getName()); }
From source file:com.smartgwt.mobile.client.data.DataSource.java
License:Open Source License
private static Record extractRecord(Element recordEl, Map<String, DataSourceField> fields) { Map<String, ArrayList<Element>> collectedNestedRecordNodes = null; final Map<String, Object> attributes = new HashMap<String, Object>(); NodeList children = recordEl.getChildNodes(); for (int childIndex = 0; childIndex < children.getLength(); ++childIndex) { Node child = children.item(childIndex); if (!(child instanceof Element)) continue; Element childEl = (Element) child; String elementName = childEl.getTagName(); final DataSourceField field = fields.get(elementName); final String typeName = (field == null ? null : field.getType()); SimpleType type = (typeName == null ? null : SimpleType.getType(typeName)); final DataSource typeDS; if (type == null && field != null && (typeDS = field.getTypeAsDataSource()) != null) { final Map<String, DataSourceField> nestedFields = typeDS._getMergedFields(); if (collectedNestedRecordNodes == null) { collectedNestedRecordNodes = new HashMap<String, ArrayList<Element>>(); }/*from ww w . j a v a 2s . com*/ final Boolean multiple = field.isMultiple(); if (multiple != null && multiple.booleanValue()) { final String childTagName = field.getChildTagName(); if (childTagName == null) { ArrayList<Element> l = collectedNestedRecordNodes.get(elementName); if (l == null) { l = new ArrayList<Element>(); collectedNestedRecordNodes.put(elementName, l); } l.add(childEl); } else { List<Element> nestedRecordElements = new ArrayList<Element>(); NodeList innerChildren = childEl.getChildNodes(); for (int innerChildIndex = 0; innerChildIndex < innerChildren .getLength(); ++innerChildIndex) { Node innerChild = innerChildren.item(innerChildIndex); if (!(innerChild instanceof Element)) continue; Element innerChildEl = (Element) innerChildren.item(innerChildIndex); if (!childTagName.equals(innerChildEl.getTagName())) continue; nestedRecordElements.add(innerChildEl); } attributes.put(elementName, extractRecordList(nestedRecordElements, nestedFields)); } } else { attributes.put(elementName, extractRecord(childEl, nestedFields)); } } else { if (type == null) type = SimpleType.TEXT_TYPE; assert type != null; final Boolean multiple = (field == null ? null : field.isMultiple()); if (multiple != null && multiple.booleanValue()) { assert field != null; String childTagName = field.getChildTagName(); if (childTagName == null) childTagName = "value"; final List<Object> l = new ArrayList<Object>(); NodeList innerChildren = childEl.getChildNodes(); for (int innerChildIndex = 0; innerChildIndex < innerChildren.getLength(); ++innerChildIndex) { Node innerChild = innerChildren.item(innerChildIndex); if (!(innerChild instanceof Element)) continue; Element innerChildEl = (Element) innerChildren.item(innerChildIndex); if (!childTagName.equals(innerChildEl.getTagName())) continue; l.add(type._fromNode(innerChildEl)); } attributes.put(elementName, l); } else { attributes.put(elementName, type._fromNode(child)); } } } NamedNodeMap attrs = recordEl.getAttributes(); for (int attrIndex = 0; attrIndex < attrs.getLength(); ++attrIndex) { Attr attr = (Attr) attrs.item(attrIndex); String attrName = attr.getName(); DataSourceField field = fields.get(attrName); if (field != null && field.getName().equals(attrName)) { String typeName = field.getType(); SimpleType type = typeName == null ? null : SimpleType.getType(typeName); if (type == null) type = SimpleType.TEXT_TYPE; attributes.put(attrName, type.parseInput(attr.getValue().trim())); } } if (collectedNestedRecordNodes != null) { for (Map.Entry<String, ArrayList<Element>> e : collectedNestedRecordNodes.entrySet()) { final DataSourceField field = fields.get(e.getKey()); assert field != null; final DataSource typeDS = field.getTypeAsDataSource(); assert typeDS != null; final Map<String, DataSourceField> nestedFields = typeDS._getMergedFields(); assert nestedFields != null; attributes.put(e.getKey(), extractRecordList(e.getValue(), nestedFields)); } } final Record record = new Record(); record.putAll(attributes); return record; }
From source file:org.apache.solr.explorer.client.util.XmlViewPane.java
License:Apache License
private Widget createElementWidget(Element element) { DisclosurePanel panel = new DisclosurePanel(); panel.setAnimationEnabled(true);// ww w . ja v a2s . c o m panel.setOpen(true); StringBuilder stringBuilder = new StringBuilder("<<span class='tagName'>").append(element.getTagName()) .append("</span>"); NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); String attrName = attr.getName(); String value = attr.getValue(); stringBuilder.append(" <span class='attrName'>").append(attrName).append("=</span>") .append("<span class='attrValue'>\"").append(value).append("\"</span>"); } if (!element.hasChildNodes()) { stringBuilder.append("/>"); return new HTML(stringBuilder.toString()); } stringBuilder.append(">"); String textValue = getTextValue(element, null); if (textValue != null && textValue.trim().length() > 0) { stringBuilder.append(textValue).append("</<span class='tagName'>").append(element.getTagName()) .append("</span>>"); return new HTML(stringBuilder.toString()); } HTML header = new HTML(stringBuilder.toString()); panel.setHeader(header); FlowPanel content = new FlowPanel(); content.getElement().getStyle().setPaddingLeft(30, Style.Unit.PX); panel.setContent(content); for (Element child : DOMUtils.children(element)) { Widget childPane = createElementWidget(child); content.add(childPane); } HTML footer = new HTML(new StringBuilder("</<span class='tagName'>").append(element.getTagName()) .append("</span>>").toString()); footer.getElement().getStyle().setMarginLeft(-34, Style.Unit.PX); content.add(footer); return panel; }
From source file:org.soa4all.dashboard.gwt.module.wsmolite.client.editor.model.ElementNode.java
License:Apache License
private void parseAttributes(NamedNodeMap nnm) { String allAttData = ""; for (int i = 0; i < nnm.getLength(); i++) { Attr attr = (Attr) nnm.item(i); if (attr.getName().startsWith("x")) { continue; }//from w w w . j av a 2 s . c o m if (isAnnotation(attr)) { String[] parts = attr.getValue().split(" |\\t|\\n|\\r"); for (int k = 0; k < parts.length; k++) { if (parts[k].length() > 0) { AnnotationNode annNode = new AnnotationNode(attr.getName(), parts[k]); add(annNode); } } } else { allAttData += " " + attr.getName() + "=\"" + attr.getValue() + "\""; if (attr.getName().startsWith("xmlns") && attr.getValue().equals(Constants.SAWSDL_NS)) { renamedSawsdlPrefix = (attr.getName().equals("xmlns")) ? "" : attr.getName().substring(6); } } } if (allAttData.length() > 0) { set("attrs", allAttData); } }
From source file:org.soa4all.dashboard.gwt.module.wsmolite.client.editor.model.ElementNode.java
License:Apache License
public static boolean isAnnotation(Attr attr) { return Constants.SAWSDL_NS.equals(attr.getNamespaceURI()) && (attr.getName().endsWith("modelReference") || attr.getName().endsWith("loweringSchemaMapping") || attr.getName().endsWith("liftingSchemaMapping")); }
From source file:org.soa4all.dashboard.gwt.module.wsmolite.client.editor.model.ModelBuilder.java
License:Apache License
public static String findSAWSDLPrefix(Element root) { NamedNodeMap nnm = root.getAttributes(); if (nnm == null) { return null; }/*from w w w . ja v a2 s. c o m*/ for (int i = 0; i < nnm.getLength(); i++) { Attr attr = (Attr) nnm.item(i); if (false == attr.getName().startsWith("xmlns")) { continue; } if (attr.getValue().equals(Constants.SAWSDL_NS)) { return (attr.getName().equals("xmlns")) ? "" : attr.getName().substring(6); } } return null; }