Gets the xml signature insert location.

@param elem the elem
@return the xml signature insert location
184871
private static Node getXmlSignatureInsertLocation(final Element elem) {
        val nodeListExtensions = elem.getElementsByTagNameNS(SAMLConstants.SAML20P_NS, "Extensions");
        if (nodeListExtensions.getLength() != 0) {
            return nodeListExtensions.item(nodeListExtensions.getLength() - 1);
        }
        val nodeListStatus = elem.getElementsByTagNameNS(SAMLConstants.SAML20P_NS, "Status");
        return nodeListStatus.item(nodeListStatus.getLength() - 1);
    }
114521
function (elem)
    {
        var nsMatch;
        var from = null;

        if (this.options.matchBare) {
            from = Strophe.getBareJidFromJid(elem.getAttribute('from'));
        } else {
            from = elem.getAttribute('from');
        }

        nsMatch = false;
        if (!this.ns) {
            nsMatch = true;
        } else {
            var that = this;
            Strophe.forEachChild(elem, null, function (elem) {
                if (elem.getAttribute("xmlns") == that.ns) {
                    nsMatch = true;
                }
            });

            nsMatch = nsMatch || elem.getAttribute("xmlns") == this.ns;
        }

        var elem_type = elem.getAttribute("type");
        if (nsMatch &&
            (!this.name || Strophe.isTagEqual(elem, this.name)) &&
            (!this.type || (Array.isArray(this.type) ? this.type.indexOf(elem_type) != -1 : elem_type == this.type)) &&
            (!this.id || elem.getAttribute("id") == this.id) &&
            (!this.from || from == this.from)) {
                return true;
        }

        return false;
    }
604834
private boolean fallbackToNavtitleOrHref(final Element elem) {
        final String hrefValue = elem.getAttribute(ATTRIBUTE_NAME_HREF);
        final String locktitleValue = elem.getAttribute(ATTRIBUTE_NAME_LOCKTITLE);
        return ((ATTRIBUTE_NAME_LOCKTITLE_VALUE_YES.equals(locktitleValue)) ||
                ("".equals(hrefValue)) ||
                !(isLocalDita(elem)));
    }
647633
def load(self, elem):
        
        self.testTag(elem, 'set')
        out = set()
        for xitem in elem:
            out.add(XmlDataIO.fromXml(xitem))
        return out
1197962
@SuppressWarnings({"rawtypes"})
    private Map.Entry getMapEntry(XmlNode node) {
        String keyName = node.getName();
        Object value = null;
        XmlMapEntry xmlMapEntry = this.mapSpecification.get(keyName);
        switch (node.getType()) {
            case XmlNode.ATTRIBUTE_NODE:
                value = node.getValue();
                break;
            case XmlNode.ELEMENT_NODE: {
                if (xmlMapEntry == null) {
                    value = new XmlNodeArray(node.getChildren());
                } else {
                    XmlMapFacet valueFacet = xmlMapEntry.getValue();
                    switch (valueFacet.getType()) {
                        case ELEMENT:
                            value = keyName;
                            break;
                        case CONTENT: {
                            List<XmlNode> nodeList = node.getChildren();
                            if (nodeList.size() > 0) {
                                value = new XmlNodeArray(nodeList);
                            }
                        }
                            break;
                        case ATTRIBUTE: {
                            Map<String, XmlNode> attributes = node.getAttributes();
                            XmlNode attribute = attributes.get(valueFacet.getName());
                            if (attribute != null) {
                                value = attribute.getValue();
                            } else {
                            }
                        }
                            break;
                        default:
                            throw new IllegalStateException();
                    }
                    XmlMapFacet keyFacet = xmlMapEntry.getKey();
                    switch (keyFacet.getType()) {
                        case ELEMENT:
                            // keyName is already set
                            break;
                        case CONTENT: {
                            List<XmlNode> nodeList = node.getChildren();
                            if (nodeList.size() > 0) {
                                keyName = getStringValue((XmlNode) nodeList.get(0));
                            } else {
                                keyName = null;
                            }
                        }
                            break;
                        case ATTRIBUTE: {
                            Map<String, XmlNode> attributes = node.getAttributes();
                            XmlNode attribute = attributes.get(keyFacet.getName());
                            if (attribute != null) {
                                keyName = attribute.getValue();
                            } else {
                                keyName = null;
                            }
                            break;
                        }
                        default:
                            throw new IllegalStateException();
                    }
                }
            }
        }
        if (keyName == null) {
            return null;
        } else {
            final Object _key = keyName;
            final Object _value = value;
            return new Map.Entry() {

                @Override
                public Object getKey() {
                    return _key;
                }

                @Override
                public Object getValue() {
                    return _value;
                }

                @Override
                public Object setValue(Object object) {
                    return null;
                }

            };
        }
    }
754710
private Element getRootElement(String fileName) throws
      IOException, SAXException, ParserConfigurationException {
    DocumentBuilderFactory docBuilderFactory =
      DocumentBuilderFactory.newInstance();
    docBuilderFactory.setIgnoringComments(true);
    DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
    Document doc = builder.parse(new File(fileName));
    Element root = doc.getDocumentElement();
    if (!matched(root, CONFIGURATION_TAG_NAME)) {
      throw new IOException("Bad " + fileName);
    }
    return root;
  }
1346287
public String toXML()
    {
        RepositoryTags tags = RepositoryTags.getInstance();
        String eol = SystemUtils.LINE_SEPARATOR;

        //opening tag + attributes
        StringBuffer result = new StringBuffer( 1024 );
        result.append( "      " );
        result.append( tags.getOpeningTagNonClosingById( FIELD_DESCRIPTOR ) );
        result.append( " " );
        result.append( eol );

        //        // id
        //        String id = new Integer(getColNo()).toString();
        //        result += /*"        " +*/ tags.getAttribute(ID, id) + eol;

        // name
        result.append( "        " );
        result.append( tags.getAttribute( FIELD_NAME, this.getAttributeName() ) );
        result.append( eol );

        // table not yet implemented

        // column
        result.append( "        " );
        result.append( tags.getAttribute( COLUMN_NAME, this.getColumnName() ) );
        result.append( eol );

        // jdbc-type
        result.append( "        " );
        result.append( tags.getAttribute( JDBC_TYPE, this.getColumnType() ) );
        result.append( eol );

        // primarykey
        if( this.isPrimaryKey() )
        {
            result.append( "        " );
            result.append( tags.getAttribute( PRIMARY_KEY, "true" ) );
            result.append( eol );
        }

        // nullable
        if( this.isRequired() )
        {
            result.append( "        " );
            result.append( tags.getAttribute( NULLABLE, "false" ) );
            result.append( eol );
        }

        // indexed not yet implemented

        // autoincrement
        if( this.isAutoIncrement() )
        {
            result.append( "        " );
            result.append( tags.getAttribute( AUTO_INCREMENT, "true" ) );
            result.append( eol );
        }

        // locking
        if( this.isLocking() )
        {
            result.append( "        " );
            result.append( tags.getAttribute( LOCKING, "true" ) );
            result.append( eol );
        }

        // updateLock
        // default is true so only write if false
        if( !this.isUpdateLock() )
        {
            result.append( "        " );
            result.append( tags.getAttribute( UPDATE_LOCK, "false" ) );
            result.append( eol );
        }

        // default-fetch not yet implemented

        // conversion
        if( this.getFieldConversion().getClass() != FieldConversionDefaultImpl.class )
        {
            result.append( "        " );
            result.append( tags.getAttribute( FIELD_CONVERSION, getFieldConversion().getClass().getName() ) );
            result.append( eol );
        }

        // length
        if( this.isLengthSpecified() )
        {
            result.append( "        " );
            result.append( tags.getAttribute( LENGTH, "" + getLength() ) );
            result.append( eol );
        }

        // precision
        if( this.isPrecisionSpecified() )
        {
            result.append( "        " );
            result.append( tags.getAttribute( PRECISION, "" + getPrecision() ) );
            result.append( eol );
        }

        // scale
        if( this.isScaleSpecified() )
        {
            result.append( "        " );
            result.append( tags.getAttribute( SCALE, "" + getScale() ) );
            result.append( eol );
        }

        // access
        result.append( "        " );
        result.append( tags.getAttribute( ACCESS, this.getAccess() ) );
        result.append( eol );

        result.append( "      />" );
        result.append( eol );
        return result.toString();
    }
519660
private static UNode parseXMLElement(Element elem) {
        assert elem != null;
        
        // Get the element's content and attributes, if any.
        String content = Utils.getElementText(elem);
        NamedNodeMap attrMap = elem.getAttributes();
        
        // Map the element's child elements, if any, into a UNode list. This also tells us
        // if there are any child nodes.
        List<UNode> childUNodeList = new ArrayList<UNode>();
        boolean bDupNodeNames = parseXMLChildElems(elem, childUNodeList);
        
        // Decide what the element becomes as documented above.
        UNode result = null;
        
        // Detect base64 encoding attribute and remove it.
        String encoding = elem.getAttribute("encoding");
        if (!Utils.isEmpty(encoding) && encoding.equalsIgnoreCase("base64")) {
            attrMap.removeNamedItem("encoding");
            content = Utils.base64ToString(content);
        }
        
        // Case 1): <key>Stellar1</key>
        if (attrMap.getLength() == 0 && childUNodeList.size() == 0) {
            // No attributes and no child elements. Use the tag name and the element
            // content (which may be empty) as the node value.
            result = createValueNode(elem.getTagName(), content);
        
        // Case 2): <field name="_ID">lollapalooza</field>
        } else if (attrMap.getLength() == 1 &&
                        elem.getAttribute("name").length() > 0 &&
                        childUNodeList.size() == 0) {
            // Only a "name" attribute and no child elements. Use attribute value as the
            // name and content as the value.
            result = createValueNode(elem.getAttribute("name"), content, elem.getTagName());
            
        // Case 3): <option name="AutoTables" value="false"/>
        } else if (attrMap.getLength() == 2 &&
                        elem.getAttribute("name").length() > 0 &&
                        elem.getAttribute("value").length() > 0 &&
                        childUNodeList.size() == 0) {
            // Use values of "name" and "value" attributes. No content allowed.
            assert content.length() == 0 : "Content is not allowed for 'name/value' element: " + content;
            result = createValueNode(elem.getAttribute("name"), elem.getAttribute("value"), elem.getTagName());
            
        // Case 4): All other cases generate a MAP or an ARRAY.
        } else {
            // We shouldn't have any content for these nodes.
            assert content.length() == 0 : "Unexpected content for element '" +
                                           elem.getTagName() + "': " + content;
            
            // Use the "name" attribute value for the UNode name, if present. Otherwise,
            // use the element name.
            if (elem.getAttribute("name").length() > 0) {
                if (bDupNodeNames) {
                    result = createArrayNode(elem.getAttribute("name"), elem.getTagName());
                } else {
                    result = createMapNode(elem.getAttribute("name"), elem.getTagName());
                }
                attrMap.removeNamedItem("name");
            } else {
                if (bDupNodeNames) {
                    result = createArrayNode(elem.getTagName());
                } else {
                    result = createMapNode(elem.getTagName());
                }
            }
            
            // Map remaining attributes, if any, into child UNode objects and add all
            // child UNodes to this node's list.
            parseXMLAttributes(attrMap, childUNodeList);
            result.addChildNodes(childUNodeList);
        }
        return result;
    }
1340060
private Node findEjbRefInsertPoint(Element parent) {

        Element e = DomUtils.getChildElementByName(parent, "ejb-local-ref");
        if (e != null)
            return e;

        return findEjbLocalRefInsertPoint(parent);
    }
1075966
def addSibling(self, elem):
        
        if elem is None: elem__o = None
        else: elem__o = elem._o
        ret = libxml2mod.xmlAddSibling(self._o, elem__o)
        if ret is None:raise treeError('xmlAddSibling() failed')
        __tmp = xmlNode(_obj=ret)
        return __tmp
1337375
@Override
    public boolean add(T elem) {
        /* First, check if we're completely out of space.  If so, do a resize
         * to ensure we do indeed have room.
         */
        if (size() == mArrays.length * mArrays.length)
            grow();

        /* Compute the (arr, index) pair for the next position.  The next
         * position is at the location indicated by size(), but we know that
         * space exists from the previous call.
         */
        final int offset = computeOffset(size());
        final int index = computeIndex(size());

        /* Check if an array exists here.  If not, make one up. */
        if (mArrays[offset] == null)
            mArrays[offset] = (T[]) new Object[mArrays.length];

        /* Write the element to its location. */
        mArrays[offset][index] = elem;

        /* Update the element count. */
        ++mSize;

        /* Per the Collections contract, return true to signal a successful
         * add.
         */
        return true;
    }
567323
public function getContentsByElem($elem) {
        $nodes = $this->_dom_x_path->query("//$elem");
        
        $contents = [];
        
        foreach ($nodes as $node) {
            array_push($contents, $node->nodeValue);
        }
        
        return $contents;
    }
388058
public static int getColumn(Element elem) {
		Attr attr = elem.getAttributeNodeNS(URI, COL_ATTR);
		return attr != null ? Integer.parseInt(attr.getValue()) : -1;
	}
1097220
private static org.jdom.Element signSamlElement(final org.jdom.Element element, final PrivateKey privKey, final PublicKey pubKey) {
        try {
            val providerName = System.getProperty("jsr105Provider", SIGNATURE_FACTORY_PROVIDER_CLASS);

            val clazz = Class.forName(providerName);
            val sigFactory = XMLSignatureFactory
                .getInstance("DOM", (Provider) clazz.getDeclaredConstructor().newInstance());

            val envelopedTransform = CollectionUtils.wrap(sigFactory.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null));

            val ref = sigFactory.newReference(StringUtils.EMPTY, sigFactory
                .newDigestMethod(DigestMethod.SHA1, null), envelopedTransform, null, null);

            val signatureMethod = getSignatureMethodFromPublicKey(pubKey, sigFactory);
            val canonicalizationMethod = sigFactory
                .newCanonicalizationMethod(
                    CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
                    (C14NMethodParameterSpec) null);

            val signedInfo = sigFactory.newSignedInfo(canonicalizationMethod, signatureMethod, CollectionUtils.wrap(ref));

            val keyInfoFactory = sigFactory.getKeyInfoFactory();
            val keyValuePair = keyInfoFactory.newKeyValue(pubKey);

            val keyInfo = keyInfoFactory.newKeyInfo(CollectionUtils.wrap(keyValuePair));
            val w3cElement = toDom(element);

            val dsc = new DOMSignContext(privKey, w3cElement);

            val xmlSigInsertionPoint = getXmlSignatureInsertLocation(w3cElement);
            dsc.setNextSibling(xmlSigInsertionPoint);

            val signature = sigFactory.newXMLSignature(signedInfo, keyInfo);
            signature.sign(dsc);

            return toJdom(w3cElement);

        } catch (final Exception e) {
            throw new IllegalArgumentException("Error signing SAML element: " + e.getMessage(), e);
        }
    }
64235
public static Optional<Element> getChildElement(final Element elem, final String ns, final String name) {
        final NodeList children = elem.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            final Node child = children.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                if (Objects.equals(child.getNamespaceURI(), ns) && name.equals(child.getLocalName())) {
                    return Optional.of((Element) child);
                }
            }
        }
        return Optional.empty();
    }
964805
def xml(self):
        
        tree = ElementTree.parse(METADATA_XML_TEMPLATE)
        root = tree.getroot()

        for name, prop in list(self.properties.items()):
            path = prop.xml_path
            elem = root.find(path, XML_NS)
            if elem is None:
                # create elem
                elem = insert_xml_element(root, path)
            elem.text = self.get_xml_value(name)

        return root
210808
function SignedXml(idMode, options) {
  this.options = options || {};
  this.idMode = idMode
  this.references = []
  this.id = 0
  this.signingKey = null
  this.signatureAlgorithm = this.options.signatureAlgorithm || "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
  this.keyInfoProvider = null
  this.canonicalizationAlgorithm = this.options.canonicalizationAlgorithm || "http://www.w3.org/2001/10/xml-exc-c14n#"
  this.signedXml = ""
  this.signatureXml = ""
  this.signatureNode = null
  this.signatureValue = ""
  this.originalXmlWithIds = ""
  this.validationErrors = []
  this.keyInfo = null
  this.idAttributes = [ 'Id', 'ID', 'id' ];
  if (this.options.idAttribute) this.idAttributes.splice(0, 0, this.options.idAttribute);
  this.implicitTransforms = this.options.implicitTransforms || [];
}