private void gatherNamespaces(Element element, List<URI> namespaceSources) throws SAXException { NamedNodeMap attributes = element.getAttributes(); int attributeCount = attributes.getLength(); for (int i = 0; i < attributeCount; i++) { Attr attribute = (Attr) attributes.item(i); String namespace = attribute.getNamespaceURI(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespace)) { try { namespaceSources.add(new URI(attribute.getValue())); } catch (URISyntaxException e) { throw new SAXException( "Cannot validate this document with this class. Namespaces must be valid URIs. Found Namespace: '" + attribute.getValue() + "'.", e); } } } NodeList childNodes = element.getChildNodes(); int childCount = childNodes.getLength(); for (int i = 0; i < childCount; i++) { Node child = childNodes.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { gatherNamespaces((Element) child, namespaceSources); } } }
private SingletonMap moveNsDeclaration(BpelEntity entity, Attr attr) throws InvalidNamespaceException { String namespaceURI = attr.getValue(); ExNamespaceContext context = entity.getNamespaceContext(); /* * Fantom addition of namespace. This call will not do anything, * it just check correcttness of namespaceURI. If it bad then * InvalidNamespaceException will appear and we go to catch. */ context.addNamespace(namespaceURI); // here we remove namespace declararation ((BpelEntityImpl) entity) .setAttribute(attr.getName(), new PrefixAttribute(attr.getName()), null); String localName = attr.getLocalName(); Iterator<String> iterator = context.getPrefixes(); boolean usePrefix = true; while (iterator.hasNext() && localName != null) { String prefix = iterator.next(); if (localName.equals(prefix)) { usePrefix = false; } } String prefix = null; if (XMLNS.equals(attr.getName()) || localName == null || !usePrefix) { prefix = context.addNamespace(attr.getValue()); } else { prefix = localName; context.addNamespace(localName, attr.getValue()); } return new SingletonMap(localName, prefix); }
@Override public void apply(Element e) { if (e.getTagName().equals("property")) { Element parent = (Element) e.getParentNode(); if (parent != null && parent.getTagName().equals("ndbx")) { Attr name = e.getAttributeNode("name"); Attr value = e.getAttributeNode("value"); if (name != null && name.getValue().equals("oscPort")) { if (value != null) { Element device = e.getOwnerDocument().createElement("device"); device.setAttribute("name", "osc1"); device.setAttribute("type", "osc"); Element portProperty = e.getOwnerDocument().createElement("property"); portProperty.setAttribute("name", "port"); portProperty.setAttribute("value", value.getValue()); device.appendChild(portProperty); Element autostartProperty = e.getOwnerDocument().createElement("property"); autostartProperty.setAttribute("name", "autostart"); autostartProperty.setAttribute("value", "true"); device.appendChild(autostartProperty); parent.replaceChild(device, e); } else { parent.removeChild(e); } } } } }
Shuttle(Shuttle cp, Element e) { this.node = e; this.g = cp.g; this.svgRoot = cp.svgRoot; this.shape = cp.shape; this.clip = cp.clip; this.fontSize = cp.fontSize; this.fontFamily = cp.fontFamily; this.stroke = cp.stroke; this.fill = cp.fill; this.strokeWidth = cp.strokeWidth; this.transform = new AffineTransform(cp.transform); this.opacity = cp.opacity; if (e.hasAttributes()) { NamedNodeMap atts = e.getAttributes(); for (int i = 0; i < atts.getLength(); ++i) { Attr att = Attr.class.cast(atts.item(i)); if (att.getNamespaceURI() != null) continue; String s = att.getName(); String value = att.getValue(); if (s.equals("style")) { for (String styles : value.split("[;]+")) { int j = styles.indexOf(':'); if (j != -1) { applyStyle(styles.substring(0, j).trim(), styles.substring(j + 1).trim()); } } } else { applyStyle(s, att.getValue()); } } } }
/** {@inheritDoc} */ protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException { AttributeDesignatorType attributeDesignatorType = (AttributeDesignatorType) xmlObject; if (attribute.getLocalName().equals(AttributeDesignatorType.ATTRIBUTE_ID_ATTRIB_NAME)) { attributeDesignatorType.setAttribtueId( DatatypeHelper.safeTrimOrNullString(attribute.getValue())); } else if (attribute.getLocalName().equals(AttributeDesignatorType.DATA_TYPE_ATTRIB_NAME)) { attributeDesignatorType.setDataType( DatatypeHelper.safeTrimOrNullString(attribute.getValue())); } else if (attribute.getLocalName().equals(AttributeDesignatorType.ISSUER_ATTRIB_NAME)) { attributeDesignatorType.setIssuer(DatatypeHelper.safeTrimOrNullString(attribute.getValue())); } else if (attribute .getLocalName() .equals(AttributeDesignatorType.MUST_BE_PRESENT_ATTRIB_NAME)) { if (attribute.getValue().equals("True") || attribute.getValue().equals("true")) { attributeDesignatorType.setMustBePresentXSBoolean(XSBooleanValue.valueOf("1")); } else { attributeDesignatorType.setMustBePresentXSBoolean(XSBooleanValue.valueOf("0")); } } else { super.processAttribute(xmlObject, attribute); } }
public static void updateGmlIDs(final Node node, final String gmlID, String oldGmlID) { // check this node's attributes if (node != null) { final String nodeNamespace = node.getNamespaceURI(); final NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { for (int i = 0, len = attributes.getLength(); i < len; i++) { final Attr attr = (Attr) attributes.item(i); if (attr.getLocalName().equals(GmlConstants.AN_ID)) { if (checkAttributeForGmlId(attr, nodeNamespace)) { if (oldGmlID == null) { oldGmlID = attr.getValue(); attr.setValue((gmlID)); } else { String helperString = attr.getValue(); helperString = helperString.replace(oldGmlID, gmlID); attr.setValue(helperString); } } } } // recurse this node's children final NodeList children = node.getChildNodes(); if (children != null) { for (int i = 0, len = children.getLength(); i < len; i++) { updateGmlIDs(children.item(i), gmlID, oldGmlID); } } } } }
/** * @param result * @param element * @param dataList */ public void processRepeat( Node result, Element element, Iterable<?> dataList, Runnable onEachLoop) { if (dataList == null) { return; } // Compute list size int size = Iterables.size(dataList); if (size > 0) { // Save the initial EL state Map<String, ? extends Object> oldContext = templateContext.getContext(); Object oldCur = templateContext.getCur(); ValueExpression oldVarExpression = null; // Set the new Context variable. Copy the old context to preserve // any existing "index" variable Map<String, Object> loopData = Maps.newHashMap(oldContext); loopData.put(PROPERTY_COUNT, size); templateContext.setContext(loopData); // TODO: This means that any loop with @var doesn't make the loop // variable available in the default expression context. // Update the specification to make this explicit. Attr varAttr = element.getAttributeNode(ATTRIBUTE_VAR); if (varAttr == null) { oldCur = templateContext.getCur(); } else { oldVarExpression = elContext.getVariableMapper().resolveVariable(varAttr.getValue()); } Attr indexVarAttr = element.getAttributeNode(ATTRIBUTE_INDEX); String indexVar = indexVarAttr == null ? PROPERTY_INDEX : indexVarAttr.getValue(); int index = 0; for (Object data : dataList) { loopData.put(indexVar, index++); // Set up context for rendering inner node templateContext.setCur(data); if (varAttr != null) { ValueExpression varExpression = expressions.constant(data, Object.class); elContext.getVariableMapper().setVariable(varAttr.getValue(), varExpression); } onEachLoop.run(); } // Restore EL state if (varAttr == null) { templateContext.setCur(oldCur); } else { elContext.getVariableMapper().setVariable(varAttr.getValue(), oldVarExpression); } templateContext.setContext(oldContext); } }
public void prepareAttribute(ContextAtExist context, Attr attr) throws XPathException { String attr_name = attr.getLocalName(); if (attr_name.equals(NAME)) { name = attr.getValue(); } else if (attr_name.equals(USE_ATTRIBUTE_SETS)) { use_attribute_sets = attr.getValue(); } }
private static SimpleXMLElement buildNode( Env env, QuercusClass cls, SimpleXMLElement parent, Node node, String namespace, boolean isPrefix) { if (node.getNodeType() == Node.TEXT_NODE) { String value = node.getNodeValue(); if (parent != null) { parent.addChild(new SimpleXMLText(env, cls, env.createString(value))); if (!isWhitespace(value)) parent.addText(env.createString(value)); } return parent; } /* NamedNodeMap attrMap = node.getAttributes(); Node namespaceAttr = attrMap.getNamedItem("xmlns"); if (namespaceAttr != null) namespace = namespaceAttr.getNodeValue(); */ SimpleXMLElement elt = new SimpleXMLElement(env, cls, parent, node.getNodeName(), namespace); if (parent != null) parent.addChild(elt); NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int length = attrs.getLength(); for (int i = 0; i < length; i++) { Attr attr = (Attr) attrs.item(i); if (attr.getName().startsWith("xmlns")) { elt.addNamespaceAttribute(env, attr.getName(), attr.getValue()); } else { elt.addAttribute(env, attr.getName(), env.createString(attr.getValue()), namespace); } } } for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { buildNode(env, cls, elt, child, namespace, isPrefix); } return elt; }
protected void validateResourceAttribute(Element element, Attr attr) { int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_RESOURCE); if (severity != CompilerFlags.IGNORE && !resourceExists(attr.getValue())) { report( NLS.bind( MDECoreMessages.Builders_Manifest_resource, (new String[] {attr.getValue(), attr.getName()})), getLine(element, attr.getName()), severity, MDEMarkerFactory.CAT_OTHER); } }
/** {@inheritDoc} */ protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException { RetrievalMethod rm = (RetrievalMethod) xmlObject; if (attribute.getLocalName().equals(RetrievalMethod.URI_ATTRIB_NAME)) { rm.setURI(attribute.getValue()); } else if (attribute.getLocalName().equals(RetrievalMethod.TYPE_ATTRIB_NAME)) { rm.setType(attribute.getValue()); } else { super.processAttribute(xmlObject, attribute); } }
private void parseNamespaces(Element element) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); String name = attr.getName(); if (name.startsWith("xmlns:")) { String prefix = name.substring(6); namespaces.put(prefix, attr.getValue()); } else if (name.equals("xmlns")) { namespaces.put("", attr.getValue()); } } }
private void addLayoutReplacements( @NonNull List<TextEdit> edits, @NonNull Element element, @NonNull IStructuredDocument document) { String tag = element.getTagName(); if (tag.equals(mOldFqcn)) { int start = RefactoringUtil.getTagNameRangeStart(element, document); if (start != -1) { int end = start + mOldFqcn.length(); edits.add(new ReplaceEdit(start, end - start, mNewFqcn)); } } else if (tag.equals(VIEW_TAG)) { Attr classNode = element.getAttributeNode(ATTR_CLASS); if (classNode != null && classNode.getValue().equals(mOldFqcn)) { int start = RefactoringUtil.getAttributeValueRangeStart(classNode, document); if (start != -1) { int end = start + mOldFqcn.length(); edits.add(new ReplaceEdit(start, end - start, mNewFqcn)); } } } else if (tag.equals(VIEW_FRAGMENT)) { Attr classNode = element.getAttributeNode(ATTR_CLASS); if (classNode == null) { classNode = element.getAttributeNodeNS(ANDROID_URI, ATTR_NAME); } if (classNode != null && classNode.getValue().equals(mOldFqcn)) { int start = RefactoringUtil.getAttributeValueRangeStart(classNode, document); if (start != -1) { int end = start + mOldFqcn.length(); edits.add(new ReplaceEdit(start, end - start, mNewFqcn)); } } } else if (element.hasAttributeNS(TOOLS_URI, ATTR_CONTEXT)) { Attr classNode = element.getAttributeNodeNS(TOOLS_URI, ATTR_CONTEXT); if (classNode != null && classNode.getValue().equals(mOldFqcn)) { int start = RefactoringUtil.getAttributeValueRangeStart(classNode, document); if (start != -1) { int end = start + mOldFqcn.length(); edits.add(new ReplaceEdit(start, end - start, mNewFqcn)); } } } NodeList children = element.getChildNodes(); for (int i = 0, n = children.getLength(); i < n; i++) { Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { addLayoutReplacements(edits, (Element) child, document); } } }
/** Process conditionals and non-repeat attributes on an element */ private void processElementInner(Node result, Element element) { TagHandler handler = registry.getHandlerFor(element); // An ugly special-case: <os:Repeat> will re-evaluate the "if" attribute // (as it should) for each loop of the repeat. Don't evaluate it here. if (!(handler instanceof RepeatTagHandler)) { Attr ifAttribute = element.getAttributeNode(ATTRIBUTE_IF); if (ifAttribute != null) { if (!evaluate(ifAttribute.getValue(), Boolean.class, false)) { return; } } } // TODO: the spec is silent on order of evaluation of "cur" relative // to "if" and "repeat" Attr curAttribute = element.getAttributeNode(ATTRIBUTE_CUR); Object oldCur = templateContext.getCur(); if (curAttribute != null) { templateContext.setCur(evaluate(curAttribute.getValue(), Object.class, null)); } if (handler != null) { handler.process(result, element, this); } else { // Be careful cloning nodes! If a target node belongs to a different document than the // template node then use importNode rather than cloneNode as that avoids side-effects // in UserDataHandlers where the cloned template node would belong to its original // document before being adopted by the target document. Element resultNode; if (element.getOwnerDocument() != result.getOwnerDocument()) { resultNode = (Element) result.getOwnerDocument().importNode(element, false); } else { resultNode = (Element) element.cloneNode(false); } clearSpecialAttributes(resultNode); Node additionalNode = processAttributes(resultNode); processChildNodes(resultNode, element); result.appendChild(resultNode); if (additionalNode != null) { result.appendChild(additionalNode); } } if (curAttribute != null) { templateContext.setCur(oldCur); } }
/** {@inheritDoc} */ protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException { PolicyType policy = (PolicyType) xmlObject; if (attribute.getLocalName().equals(PolicyType.POLICY_ID_ATTRIB_NAME)) { policy.setPolicyId(attribute.getValue()); } else if (attribute.getLocalName().equals(PolicyType.VERSION_ATTRIB_NAME)) { policy.setVersion(attribute.getValue()); } else if (attribute.getLocalName().equals(PolicyType.RULE_COMBINING_ALG_ID_ATTRIB_NAME)) { policy.setRuleCombiningAlgoId(attribute.getValue()); } else { super.processAttribute(xmlObject, attribute); } }
@Override public void apply(Element e) { if (e.getTagName().equals("property")) { Element parent = (Element) e.getParentNode(); if (parent != null && parent.getTagName().equals("device")) { Attr type = parent.getAttributeNode("type"); if (type != null && type.getValue().equals(this.deviceType)) { Attr name = e.getAttributeNode("name"); if (name != null && name.getValue().equals(oldPropertyName)) name.setValue(newPropertyName); } } } }
private void processNode(org.w3c.dom.Node node, com.dragonflow.XmlApi.XmlApiObject xmlapiobject) { if (node.getNodeType() == 1) { String s = node.getNodeName(); if (s != null && s.length() > 0) { jgl.HashMap hashmap = new HashMap(); org.w3c.dom.NamedNodeMap namednodemap = node.getAttributes(); for (int i = 0; i < namednodemap.getLength(); i++) { org.w3c.dom.Attr attr = (org.w3c.dom.Attr) namednodemap.item(i); if (attr.getName() != null && attr.getName().equals("encodeValues") && attr.getValue() != null && (attr.getValue().equals("false") || attr.getValue().equals("true"))) { encodeValues = (new Boolean(attr.getValue())).booleanValue(); continue; } String s1 = attr.getValue(); if (s1 != null) { s1 = com.dragonflow.Utils.TextUtils.enlighten(s1); } hashmap.put(attr.getName(), s1); } org.w3c.dom.NodeList nodelist = node.getChildNodes(); java.util.Vector vector = findPropNodes(nodelist); for (int j = 0; j < vector.size(); j++) { org.w3c.dom.Node node1 = (org.w3c.dom.Node) vector.elementAt(j); org.w3c.dom.NodeList nodelist1 = node1.getChildNodes(); String s2 = findPropertyName(nodelist1); String as[] = findValueNodes(nodelist1); if (as.length > 1) { hashmap.put(s2, as); continue; } if (as.length == 1) { hashmap.put(s2, as[0]); } else { hashmap.put(s2, ""); } } xmlapiobject.setProperties(hashmap); xmlapiobject.setName(s); java.util.Vector vector1 = findChildrenNodes(nodelist); for (int k = 0; k < vector1.size(); k++) { org.w3c.dom.Node node2 = (org.w3c.dom.Node) vector1.elementAt(k); processNode(node2, xmlapiobject.add()); } } } }
private void validateFeatureID(Element element, Attr attr) { int severity = CompilerFlags.getFlag(fProject, CompilerFlags.F_UNRESOLVED_FEATURES); if (severity != CompilerFlags.IGNORE) { IFeatureModel[] models = PDECore.getDefault().getFeatureModelManager().findFeatureModels(attr.getValue()); if (models.length == 0) { report( NLS.bind(PDECoreMessages.Builders_Feature_freference, attr.getValue()), getLine(element, attr.getName()), severity, PDEMarkerFactory.CAT_OTHER); } } }
/** {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { Response response = (Response) samlObject; QName attrName = XMLHelper.getNodeQName(attribute); if (Response.SOAP11_MUST_UNDERSTAND_ATTR_NAME.equals(attrName)) { response.setSOAP11MustUnderstand(XSBooleanValue.valueOf(attribute.getValue())); } else if (Response.SOAP11_ACTOR_ATTR_NAME.equals(attrName)) { response.setSOAP11Actor(attribute.getValue()); } else if (Response.REF_TO_MESSAGE_ID_ATTRIB_NAME.equals(attribute.getLocalName())) { response.setRefToMessageID(attribute.getValue()); } else { super.processAttribute(samlObject, attribute); } }
private void validateImports(Element parent) { NodeList list = getChildrenByName(parent, "import"); // $NON-NLS-1$ for (int i = 0; i < list.getLength(); i++) { if (fMonitor.isCanceled()) return; Element element = (Element) list.item(i); Attr plugin = element.getAttributeNode("plugin"); // $NON-NLS-1$ Attr feature = element.getAttributeNode("feature"); // $NON-NLS-1$ if (plugin == null && feature == null) { assertAttributeDefined(element, "plugin", CompilerFlags.ERROR); // $NON-NLS-1$ } else if (plugin != null && feature != null) { reportExclusiveAttributes( element, "plugin", "feature", CompilerFlags.ERROR); // $NON-NLS-1$//$NON-NLS-2$ } else if (plugin != null) { validatePluginID(element, plugin, false); } else if (feature != null) { validateFeatureID(element, feature); } NamedNodeMap attributes = element.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { Attr attr = (Attr) attributes.item(j); String name = attr.getName(); if (name.equals("version")) { // $NON-NLS-1$ validateVersionAttribute(element, attr); } else if (name.equals("match")) { // $NON-NLS-1$ if (element.getAttributeNode("patch") != null) { // $NON-NLS-1$ report( NLS.bind(PDECoreMessages.Builders_Feature_patchedMatch, attr.getValue()), getLine(element, attr.getValue()), CompilerFlags.ERROR, PDEMarkerFactory.CAT_FATAL); } else { validateMatch(element, attr); } } else if (name.equals("patch")) { // $NON-NLS-1$ if ("true".equalsIgnoreCase(attr.getValue()) && feature == null) { // $NON-NLS-1$ report( NLS.bind(PDECoreMessages.Builders_Feature_patchPlugin, attr.getValue()), getLine(element, attr.getValue()), CompilerFlags.ERROR, PDEMarkerFactory.CAT_FATAL); } else if ("true".equalsIgnoreCase(attr.getValue()) && element.getAttributeNode("version") == null) { // $NON-NLS-1$ //$NON-NLS-2$ report( NLS.bind(PDECoreMessages.Builders_Feature_patchedVersion, attr.getValue()), getLine(element, attr.getValue()), CompilerFlags.ERROR, PDEMarkerFactory.CAT_FATAL); } else { validateBoolean(element, attr); } } else if (!name.equals("plugin") && !name.equals("feature") && !name.equals("filter")) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ reportUnknownAttribute(element, name, CompilerFlags.ERROR); } } } }
// Walk the tree from a specified element, // inserting data from a DicomObject where required. private static String getElementText(Element element, DicomObject dicomObject) { if (dicomTag(element)) return getDicomElementText(element, dicomObject); if (element.getTagName().equals("block")) return getBlockText(element, dicomObject); StringBuffer sb = new StringBuffer(); sb.append("<" + element.getTagName()); NamedNodeMap attributes = element.getAttributes(); Attr attr; for (int i = 0; i < attributes.getLength(); i++) { attr = (Attr) attributes.item(i); String attrValue = attr.getValue().trim(); if (dicomTag(attrValue)) { attrValue = getDicomElementText(attrValue, dicomObject); } sb.append(" " + attr.getName() + "=\"" + attrValue + "\""); } sb.append(">"); if (element.getTagName().equals("table")) sb.append(getTableText(element, dicomObject)); else if (element.getTagName().equals("publication-date")) sb.append(StringUtil.getDate()); else sb.append(getChildrenText(element, dicomObject)); sb.append("</" + element.getTagName() + ">"); return sb.toString(); }
/** * @param containingHtmlElement the name of the HTML element containing el. If the HTML element is * contained inside a template construct then this name may differ from el's immediate parent. */ private void inspectElement(JobEnvelope source, Element el, ElKey containingHtmlElement) { ElKey elKey = ElKey.forElement(el); // Recurse early so that ihtml:dynamic elements have been parsed before we // process the attributes element list. for (Node child : Nodes.childrenOf(el)) { inspect(source, child, elKey); } // For each attribute allowed on this element type, ensure that // (1) If it is not specified, and its default value is not allowed, then // it is added with a known safe value. // (2) Its value is rewritten as appropriate. // We don't have to worry about disallowed attributes since those will // not be present in scriptsPerNode. The TemplateSanitizer should have // stripped those out. The TemplateSanitizer should also have stripped out // disallowed elements. if (!htmlSchema.isElementAllowed(elKey)) { return; } HTML.Element elInfo = htmlSchema.lookupElement(elKey); List<HTML.Attribute> attrs = elInfo.getAttributes(); if (attrs != null) { for (HTML.Attribute a : attrs) { AttribKey attrKey = a.getKey(); if (!htmlSchema.isAttributeAllowed(attrKey)) { continue; } Attr attr = null; String aUri = attrKey.ns.uri; String aName = attrKey.localName; Attr unsafe = el.getAttributeNodeNS(aUri, aName); if (unsafe != null && a.getValueCriterion().accept(unsafe.getValue())) { attr = unsafe; } else if ((a.getDefaultValue() != null && !a.getValueCriterion().accept(a.getDefaultValue())) || !a.isOptional()) { attr = el.getOwnerDocument().createAttributeNS(aUri, aName); String safeValue; if (a.getType() == HTML.Attribute.Type.URI) { safeValue = "" + Nodes.getFilePositionFor(el).source().getUri(); } else { safeValue = a.getSafeValue(); } if (safeValue == null) { mq.addMessage( IhtmlMessageType.MISSING_ATTRIB, Nodes.getFilePositionFor(el), elKey, attrKey); continue; } attr.setNodeValue(safeValue); el.setAttributeNodeNS(attr); } if (attr != null) { inspectHtmlAttribute(source, attr, a); } } } scriptsPerNode.put(el, null); }
/** @since 3.4 */ public Boolean getBoolean(String key) { Attr attr = element.getAttributeNode(key); if (attr == null) { return null; } return Boolean.valueOf(attr.getValue()); }
/* * (non-Javadoc) Method declared in IMemento. */ public String getString(String key) { Attr attr = element.getAttributeNode(key); if (attr == null) { return null; } return attr.getValue(); }
void _serializeNumber(String key, Number value) { NodeList elements = numberElements.getElementsByTagName(ENTRY_FLAG); final int size = elements.getLength(); for (int i = 0; i < size; ++i) { Element e = (Element) elements.item(i); Attr nameAttr = e.getAttributeNode(KEY_FLAG); if (nameAttr == null) { throw newMalformedKeyAttrException(Repository.NUMBER); } if (key.equals(nameAttr.getValue())) { Attr valueAttr = e.getAttributeNode(VALUE_FLAG); if (valueAttr == null) { throw newMalformedValueAttrException(key, Repository.NUMBER); } Attr typeAttr = e.getAttributeNode(TYPE_FLAG); if (typeAttr == null) { throw newMalformedTypeAttrException(key, Repository.NUMBER); } typeAttr.setValue(Configs.resolveNumberType(value).name()); valueAttr.setValue(value.toString()); return; } } // no existing element found Element element = xmlDoc.createElement(ENTRY_FLAG); element.setAttribute(KEY_FLAG, key); element.setAttribute(VALUE_FLAG, value.toString()); element.setAttribute(TYPE_FLAG, Configs.resolveNumberType(value).name()); numberElements.appendChild(element); }
void _serializeString(String key, String value) { NodeList elements = stringElements.getElementsByTagName(ENTRY_FLAG); final int size = elements.getLength(); for (int i = 0; i < size; ++i) { Element e = (Element) elements.item(i); Attr nameAttr = e.getAttributeNode(KEY_FLAG); if (nameAttr == null) { throw newMalformedKeyAttrException(Repository.STRING); } if (key.equals(nameAttr.getValue())) { Attr valueAttr = e.getAttributeNode(VALUE_FLAG); if (valueAttr == null) { throw newMalformedValueAttrException(key, Repository.STRING); } valueAttr.setValue(value); return; } } // no existing element found Element element = xmlDoc.createElement(ENTRY_FLAG); element.setAttribute(KEY_FLAG, key); element.setAttribute(VALUE_FLAG, value); stringElements.appendChild(element); }
/** * Recurse through a node and its children and make all gml:ids unique * * @param node The node to examine */ public static void makeGmlIdsUnique(final Node node, final Map<String, Integer> foundIds) { // check this node's attributes final NamedNodeMap attributes = node.getAttributes(); final String nodeNamespace = node.getNamespaceURI(); if (attributes != null) { for (int i = 0, len = attributes.getLength(); i < len; i++) { final Attr attr = (Attr) attributes.item(i); if (attr.getLocalName().equals(GmlConstants.AN_ID)) { if (checkAttributeForGmlId(attr, nodeNamespace)) { final String gmlId = attr.getValue(); if (foundIds.containsKey(gmlId)) { /* * id has already been found, suffix this one with * the found count for this id */ attr.setValue(gmlId + foundIds.get(gmlId)); // increment the found count for this id foundIds.put(gmlId, foundIds.get(gmlId) + 1); } else { // id is new, add it to the foundIds map foundIds.put(gmlId, 1); } } } } } // recurse this node's children final NodeList children = node.getChildNodes(); if (children != null) { for (int i = 0, len = children.getLength(); i < len; i++) { makeGmlIdsUnique(children.item(i), foundIds); } } }
private void moveNSDeclarationToRoot(BpelEntity entity, Map<String, String> prefixMap) { if (!(entity instanceof BpelEntityImpl)) { return; } Element element = ((BpelEntityImpl) entity).getPeer(); NamedNodeMap map = element.getAttributes(); for (int i = 0; i < map.getLength(); i++) { Node node = map.item(i); assert node instanceof Attr; Attr attr = (Attr) node; if (attr.getValue() == null) { continue; } try { if (XMLNS.equals(attr.getName()) || (XMLNS.equals(attr.getPrefix()))) { SingletonMap pMap = moveNsDeclaration(entity, attr); if (!pMap.keyEqualsValue()) { prefixMap.put(pMap.getKey(), pMap.getValue()); } } } catch (InvalidNamespaceException e) { // This is the case // when namespace was originally incorrect and we do not move it // to root. We don't do anything. } } /* * we need to update prefixes for those declarations that changed * its perfix after lifing up decl. */ updatePrefixes(entity, prefixMap); for (BpelEntity child : entity.getChildren()) { moveNSDeclarationToRoot(child, prefixMap); } }
@Override public void init(Element element) { final Element settingsElement = (Element) element.getElementsByTagName("settings").item(0); final NamedNodeMap attributes = settingsElement.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { final Node node = attributes.item(i); if (node.getNodeType() == Node.ATTRIBUTE_NODE) { final Attr attr = (Attr) node; this.params.put(attr.getName(), Float.parseFloat(attr.getValue())); } } final float top = this.params.get("top"); final float left = this.params.get("left"); final float bottom = this.params.get("bottom"); final float right = this.params.get("right"); final float bWidth = this.params.get("blockWidth"); final float bHeight = this.params.get("blockHeight"); final List<XYZItem> truc = new LinkedList<XYZItem>(); for (float x = left; x < right; x += bWidth) { for (float y = bottom; y < top; y += bHeight) { truc.add(new XYZItem(x, y, getZValue(x, y))); } } this.map = new double[3][truc.size()]; int i = 0; for (XYZItem item : truc) { this.map[0][i] = item.getXValue(); this.map[1][i] = item.getYValue(); this.map[2][i] = item.getZValue(); i++; } }
private void handleNsAttribute( BpelEntity entity, BpelEntity parent, Map<String, String> prefixMap, Attr attr) { String namespaceURI = attr.getValue(); if (XMLNS.equals(attr.getName()) || (XMLNS.equals(attr.getPrefix()))) { if (namespaceURI.equals(entity.getPeer().getNamespaceURI())) { // do not touch namespace that correspond namespace of current element return; } ExNamespaceContext context = parent.getNamespaceContext(); Iterator<String> iterator = context.getPrefixes(); while (iterator.hasNext()) { String next = iterator.next(); String namespace = context.getNamespaceURI(next); if (namespaceURI.equals(namespace)) { String prefixName = attr.getLocalName(); // put prefix corresponding found namespace into map for changing it further if (!prefixName.equals(next)) { prefixMap.put(prefixName, next); } // remove namespace delcaration. ((BpelEntityImpl) entity) .setAttribute(attr.getName(), new PrefixAttribute(attr.getName()), null); } } } }