Search in sources :

Example 1 with XmlNamespace

use of nokogiri.XmlNamespace in project gocd by gocd.

the class NokogiriHelpers method getCachedNodeOrCreate.

/**
     * Get the XmlNode associated with the underlying
     * <code>node</code>. Creates a new XmlNode (or appropriate subclass)
     * or XmlNamespace wrapping <code>node</code> if there is no cached
     * value.
     */
public static IRubyObject getCachedNodeOrCreate(Ruby ruby, Node node) {
    if (node == null)
        return ruby.getNil();
    if (node.getNodeType() == Node.ATTRIBUTE_NODE && isNamespace(node.getNodeName())) {
        XmlDocument xmlDocument = (XmlDocument) node.getOwnerDocument().getUserData(CACHED_NODE);
        if (!(xmlDocument instanceof HtmlDocument)) {
            String prefix = getLocalNameForNamespace(((Attr) node).getName());
            prefix = prefix != null ? prefix : "";
            String href = ((Attr) node).getValue();
            XmlNamespace xmlNamespace = xmlDocument.getNamespaceCache().get(prefix, href);
            if (xmlNamespace != null)
                return xmlNamespace;
            else
                return XmlNamespace.createFromAttr(ruby, (Attr) node);
        }
    }
    XmlNode xmlNode = getCachedNode(node);
    if (xmlNode == null) {
        xmlNode = (XmlNode) constructNode(ruby, node);
        node.setUserData(CACHED_NODE, xmlNode, null);
    }
    return xmlNode;
}
Also used : XmlNode(nokogiri.XmlNode) HtmlDocument(nokogiri.HtmlDocument) XmlNamespace(nokogiri.XmlNamespace) XmlDocument(nokogiri.XmlDocument) RubyString(org.jruby.RubyString) Attr(org.w3c.dom.Attr) XmlAttr(nokogiri.XmlAttr)

Example 2 with XmlNamespace

use of nokogiri.XmlNamespace in project nokogiri by sparklemotion.

the class NokogiriHelpers method getCachedNodeOrCreate.

/**
     * Get the XmlNode associated with the underlying
     * <code>node</code>. Creates a new XmlNode (or appropriate subclass)
     * or XmlNamespace wrapping <code>node</code> if there is no cached
     * value.
     */
public static IRubyObject getCachedNodeOrCreate(Ruby ruby, Node node) {
    if (node == null)
        return ruby.getNil();
    if (node.getNodeType() == Node.ATTRIBUTE_NODE && isNamespace(node.getNodeName())) {
        XmlDocument xmlDocument = (XmlDocument) node.getOwnerDocument().getUserData(CACHED_NODE);
        if (!(xmlDocument instanceof HtmlDocument)) {
            String prefix = getLocalNameForNamespace(((Attr) node).getName());
            prefix = prefix != null ? prefix : "";
            String href = ((Attr) node).getValue();
            XmlNamespace xmlNamespace = xmlDocument.getNamespaceCache().get(prefix, href);
            if (xmlNamespace != null)
                return xmlNamespace;
            else
                return XmlNamespace.createFromAttr(ruby, (Attr) node);
        }
    }
    XmlNode xmlNode = getCachedNode(node);
    if (xmlNode == null) {
        xmlNode = (XmlNode) constructNode(ruby, node);
        node.setUserData(CACHED_NODE, xmlNode, null);
    }
    return xmlNode;
}
Also used : XmlNode(nokogiri.XmlNode) HtmlDocument(nokogiri.HtmlDocument) XmlNamespace(nokogiri.XmlNamespace) XmlDocument(nokogiri.XmlDocument) RubyString(org.jruby.RubyString) Attr(org.w3c.dom.Attr) XmlAttr(nokogiri.XmlAttr)

Aggregations

HtmlDocument (nokogiri.HtmlDocument)2 XmlAttr (nokogiri.XmlAttr)2 XmlDocument (nokogiri.XmlDocument)2 XmlNamespace (nokogiri.XmlNamespace)2 XmlNode (nokogiri.XmlNode)2 RubyString (org.jruby.RubyString)2 Attr (org.w3c.dom.Attr)2