Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions | Private Member Functions
nsSOAPUtils Class Reference

#include <nsSOAPUtils.h>

List of all members.

Static Public Member Functions

static void GetSpecificChildElement (nsISOAPEncoding *aEncoding, nsIDOMElement *aParent, const nsAString &aNamespace, const nsAString &aType, nsIDOMElement **aElement)
static void GetSpecificSiblingElement (nsISOAPEncoding *aEncoding, nsIDOMElement *aSibling, const nsAString &aNamespace, const nsAString &aType, nsIDOMElement **aElement)
static void GetFirstChildElement (nsIDOMElement *aParent, nsIDOMElement **aElement)
static void GetNextSiblingElement (nsIDOMElement *aStart, nsIDOMElement **aElement)
static nsresult GetElementTextContent (nsIDOMElement *aElement, nsAString &aText)
static PRBool HasChildElements (nsIDOMElement *aElement)
static void GetNextSibling (nsIDOMNode *aSibling, nsIDOMNode **aNext)
static nsresult MakeNamespacePrefix (nsISOAPEncoding *aEncoding, nsIDOMElement *aElement, const nsAString &aURI, nsAString &aPrefix)
static nsresult GetNamespaceURI (nsISOAPEncoding *aEncoding, nsIDOMElement *aElement, const nsAString &aQName, nsAString &aURI)
static nsresult GetLocalName (const nsAString &aQName, nsAString &aLocalName)
static PRBool GetAttribute (nsISOAPEncoding *aEncoding, nsIDOMElement *aElement, const nsAString &aNamespaceURI, const nsAString &aLocalName, nsAString &aValue)
 Get an attribute, keeping in mind that input NamespaceURIs may have all been mapped, so we don't know exactly what we are looking for.

Private Member Functions

 nsSOAPUtils ()
 ~nsSOAPUtils ()

Detailed Description

Definition at line 45 of file nsSOAPUtils.h.


Constructor & Destructor Documentation

nsSOAPUtils::nsSOAPUtils ( ) [inline, private]

Definition at line 47 of file nsSOAPUtils.h.

{}  //  Never create a member of this class
nsSOAPUtils::~nsSOAPUtils ( ) [inline, private]

Definition at line 48 of file nsSOAPUtils.h.

{}

Member Function Documentation

PRBool nsSOAPUtils::GetAttribute ( nsISOAPEncoding aEncoding,
nsIDOMElement aElement,
const nsAString &  aNamespaceURI,
const nsAString &  aLocalName,
nsAString &  aValue 
) [static]

Get an attribute, keeping in mind that input NamespaceURIs may have all been mapped, so we don't know exactly what we are looking for.

First, directly lookup what tyis type outputs as. If that fails, then loop through all attributes looking for one that matches after mapping to internal types. Fortunately, where these are used there are not many attributes.

Definition at line 505 of file nsSOAPUtils.cpp.

{
  nsAutoString value;
  nsresult rc = aEncoding->GetExternalSchemaURI(aNamespaceURI, value);  //  Try most-likely result first.
  if (NS_FAILED(rc))
    return PR_FALSE;
  {
    nsCOMPtr<nsIDOMAttr> attr;
    rc = aElement->GetAttributeNodeNS(value, aLocalName, getter_AddRefs(attr));
    if (NS_FAILED(rc))
      return PR_FALSE;
    if (attr) {
      rc = attr->GetNodeValue(aValue);
      if (NS_FAILED(rc))
        return PR_FALSE;
      return PR_TRUE;
    }
  }
  nsCOMPtr<nsIDOMNamedNodeMap> attrs;
  rc = aElement->GetAttributes(getter_AddRefs(attrs));
  if (NS_FAILED(rc))
    return PR_FALSE;
  PRUint32 count;
  rc = attrs->GetLength(&count);
  if (NS_FAILED(rc))
    return PR_FALSE;
  PRUint32 i;
  for (i = 0; i < count; i++) {
    nsCOMPtr<nsIDOMNode> attrnode;
    rc = attrs->Item(i, getter_AddRefs(attrnode));
    if (NS_FAILED(rc))
      return PR_FALSE;
    rc = attrnode->GetLocalName(value);
    if (NS_FAILED(rc))
      return PR_FALSE;
    if (!aLocalName.Equals(value))
      continue;
    rc = attrnode->GetNamespaceURI(value);
    if (NS_FAILED(rc))
      return PR_FALSE;
    nsAutoString internal;
    rc = aEncoding->GetInternalSchemaURI(value, internal);
    if (NS_FAILED(rc))
      return PR_FALSE;
    if (!aNamespaceURI.Equals(internal))
      continue;
    rc = attrnode->GetNodeValue(aValue);
    if (NS_FAILED(rc))
      return PR_FALSE;
    return PR_TRUE;
  }
  SetAStringToNull(aValue);
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSOAPUtils::GetElementTextContent ( nsIDOMElement aElement,
nsAString &  aText 
) [static]

Definition at line 209 of file nsSOAPUtils.cpp.

{
  aText.Truncate();
  nsCOMPtr<nsIDOMNode> child;
  nsAutoString rtext;
  aElement->GetFirstChild(getter_AddRefs(child));
  while (child) {
    PRUint16 type;
    child->GetNodeType(&type);
    if (nsIDOMNode::TEXT_NODE == type
        || nsIDOMNode::CDATA_SECTION_NODE == type) {
      nsCOMPtr<nsIDOMText> text = do_QueryInterface(child);
      nsAutoString data;
      text->GetData(data);
      rtext.Append(data);
    } else if (nsIDOMNode::ELEMENT_NODE == type) {
      return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_UNEXPECTED_ELEMENT", "Unable to retrieve simple content because a child element was present.");
    }
    nsCOMPtr<nsIDOMNode> temp = child;
    GetNextSibling(temp, getter_AddRefs(child));
  }
  aText.Assign(rtext);
  return NS_OK;
}

Here is the call graph for this function:

void nsSOAPUtils::GetFirstChildElement ( nsIDOMElement aParent,
nsIDOMElement **  aElement 
) [static]

Definition at line 169 of file nsSOAPUtils.cpp.

{
  nsCOMPtr<nsIDOMNode> child;

  *aElement = nsnull;
  aParent->GetFirstChild(getter_AddRefs(child));
  while (child) {
    PRUint16 type;
    child->GetNodeType(&type);
    if (nsIDOMNode::ELEMENT_NODE == type) {
      child->QueryInterface(NS_GET_IID(nsIDOMElement), (void **) aElement);
      break;
    }
    nsCOMPtr<nsIDOMNode> temp = child;
    GetNextSibling(temp, getter_AddRefs(child));
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSOAPUtils::GetLocalName ( const nsAString &  aQName,
nsAString &  aLocalName 
) [static]

Definition at line 344 of file nsSOAPUtils.cpp.

{
  PRInt32 i = aQName.FindChar(':');
  if (i < 0)
    aLocalName = aQName;
  else
    aLocalName = Substring(aQName, i+1, aQName.Length() - (i+1));
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSOAPUtils::GetNamespaceURI ( nsISOAPEncoding aEncoding,
nsIDOMElement aElement,
const nsAString &  aQName,
nsAString &  aURI 
) [static]

Definition at line 288 of file nsSOAPUtils.cpp.

{
  aURI.Truncate();
  PRInt32 i = aQName.FindChar(':');
  if (i < 0) {
    return NS_OK;
  }
  nsAutoString prefix;
  prefix = Substring(aQName, 0, i);

  nsAutoString result;
  if (prefix.Equals(gSOAPStrings->kXMLPrefix)) {
    result.Assign(gSOAPStrings->kXMLNamespaceURI);
  }
  else {

    nsresult rc;
    nsCOMPtr<nsIDOMNode> current = aScope;
    nsCOMPtr<nsIDOMNamedNodeMap> attrs;
    nsCOMPtr<nsIDOMNode> temp;
    nsAutoString value;
    while (current) {
      rc = current->GetAttributes(getter_AddRefs(attrs));
      if (NS_FAILED(rc))
        return rc;
      if (attrs) {
        rc = attrs->GetNamedItemNS(gSOAPStrings->kXMLNamespaceNamespaceURI, prefix,
                                   getter_AddRefs(temp));
        if (NS_FAILED(rc))
          return rc;
        if (temp) {
          rc = temp->GetNodeValue(result);
          if (NS_FAILED(rc))
            return rc;
          break;
        }
      }
      rc = current->GetParentNode(getter_AddRefs(temp));
      if (NS_FAILED(rc))
        return rc;
      current = temp;
    }
    if (!current)
      return SOAP_EXCEPTION(NS_ERROR_FAILURE,"SOAP_NAMESPACE", "Unable to resolve prefix in attribute value to namespace URI");
  }
  if (aEncoding) {
    return aEncoding->GetInternalSchemaURI(result,aURI);
  }
  aURI.Assign(result);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsSOAPUtils::GetNextSibling ( nsIDOMNode aSibling,
nsIDOMNode **  aNext 
) [static]

Definition at line 253 of file nsSOAPUtils.cpp.

{
  nsCOMPtr<nsIDOMNode> last;
  nsCOMPtr<nsIDOMNode> current;
  PRUint16 type;

  *aNext = nsnull;
  last = aSibling;

  last->GetNodeType(&type);
  if (nsIDOMNode::ENTITY_REFERENCE_NODE == type) {
    last->GetFirstChild(getter_AddRefs(current));
    if (!last) {
      last->GetNextSibling(getter_AddRefs(current));
    }
  } else {
    last->GetNextSibling(getter_AddRefs(current));
  }
  while (!current) {
    last->GetParentNode(getter_AddRefs(current));
    current->GetNodeType(&type);
    if (nsIDOMNode::ENTITY_REFERENCE_NODE == type) {
      last = current;
      last->GetNextSibling(getter_AddRefs(current));
    } else {
      current = nsnull;
      break;
    }
  }
  *aNext = current;
  NS_IF_ADDREF(*aNext);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsSOAPUtils::GetNextSiblingElement ( nsIDOMElement aStart,
nsIDOMElement **  aElement 
) [static]

Definition at line 188 of file nsSOAPUtils.cpp.

{
  nsCOMPtr<nsIDOMNode> sibling;

  *aElement = nsnull;
  GetNextSibling(aStart, getter_AddRefs(sibling));
  while (sibling) {
    PRUint16 type;
    sibling->GetNodeType(&type);
    if (nsIDOMNode::ELEMENT_NODE == type) {
      sibling->QueryInterface(NS_GET_IID(nsIDOMElement),
                              (void **) aElement);
      break;
    }
    nsCOMPtr<nsIDOMNode> temp = sibling;
    GetNextSibling(temp, getter_AddRefs(sibling));
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsSOAPUtils::GetSpecificChildElement ( nsISOAPEncoding aEncoding,
nsIDOMElement aParent,
const nsAString &  aNamespace,
const nsAString &  aType,
nsIDOMElement **  aElement 
) [static]

Definition at line 121 of file nsSOAPUtils.cpp.

{
  nsCOMPtr<nsIDOMElement> sibling;

  *aElement = nsnull;
  GetFirstChildElement(aParent, getter_AddRefs(sibling));
  if (sibling) {
    GetSpecificSiblingElement(aEncoding, sibling, aNamespace, aType, aElement);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsSOAPUtils::GetSpecificSiblingElement ( nsISOAPEncoding aEncoding,
nsIDOMElement aSibling,
const nsAString &  aNamespace,
const nsAString &  aType,
nsIDOMElement **  aElement 
) [static]

Definition at line 136 of file nsSOAPUtils.cpp.

{
  nsCOMPtr<nsIDOMElement> sibling;

  *aElement = nsnull;
  sibling = aSibling;
  do {
    nsAutoString name, namespaceURI;
    sibling->GetLocalName(name);
    if (name.Equals(aType)) {
      if (aEncoding) {
        nsAutoString temp;
        sibling->GetNamespaceURI(temp);
        aEncoding->GetInternalSchemaURI(temp, namespaceURI);
      }
      else {
        sibling->GetNamespaceURI(namespaceURI);
      }
      if (namespaceURI.Equals(aNamespace)) {
        *aElement = sibling;
        NS_ADDREF(*aElement);
        return;
      }
    }
    nsCOMPtr<nsIDOMElement> temp = sibling;
    GetNextSiblingElement(temp, getter_AddRefs(sibling));
  } while (sibling);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 235 of file nsSOAPUtils.cpp.

{
  nsCOMPtr<nsIDOMNode> child;

  aElement->GetFirstChild(getter_AddRefs(child));
  while (child) {
    PRUint16 type;
    child->GetNodeType(&type);
    if (nsIDOMNode::ELEMENT_NODE == type) {
      return PR_TRUE;
    }
    nsCOMPtr<nsIDOMNode> temp = child;
    GetNextSibling(temp, getter_AddRefs(child));
  }

  return PR_FALSE;
}

Here is the call graph for this function:

nsresult nsSOAPUtils::MakeNamespacePrefix ( nsISOAPEncoding aEncoding,
nsIDOMElement aElement,
const nsAString &  aURI,
nsAString &  aPrefix 
) [static]

Definition at line 356 of file nsSOAPUtils.cpp.

{
//  This may change for level 3 serialization, so be sure to gut this
//  and call the standardized level 3 method when it is available.
  nsAutoString externalURI;
  if (aEncoding) {
    nsresult rc = aEncoding->GetExternalSchemaURI(aURI,externalURI);
    if (NS_FAILED(rc))
      return rc;
  }
  else {
    externalURI.Assign(aURI);
  }
  aPrefix.Truncate();
  if (externalURI.IsEmpty())
    return NS_OK;
  if (externalURI.Equals(gSOAPStrings->kXMLNamespaceURI)) {
    aPrefix.Assign(gSOAPStrings->kXMLPrefix);
    return NS_OK;
  }
  nsCOMPtr<nsIDOMNode> current = aScope;
  nsCOMPtr<nsIDOMNamedNodeMap> attrs;
  nsCOMPtr<nsIDOMNode> temp;
  nsAutoString tstr;
  nsresult rc;
  PRUint32 maxns = 0;                //  Keep track of max generated NS
  for (;;) {
    rc = current->GetAttributes(getter_AddRefs(attrs));
    if (NS_FAILED(rc))
      return rc;
    if (attrs) {
      PRUint32 i;
      PRUint32 count;
      rc = attrs->GetLength(&count);
      if (NS_FAILED(rc))
        return PR_FALSE;
      for (i = 0;i < count;i++) {
        attrs->Item(i, getter_AddRefs(temp));
        if (!temp)
          break;
        temp->GetNamespaceURI(tstr);
        if (!tstr.Equals(gSOAPStrings->kXMLNamespaceNamespaceURI))
          continue;
        temp->GetNodeValue(tstr);
        if (tstr.Equals(externalURI)) {
          nsAutoString prefix;
          rc = temp->GetLocalName(prefix);
          if (NS_FAILED(rc))
            return rc;
          nsCOMPtr<nsIDOMNode> check = aScope;
          PRBool hasDecl;
          nsCOMPtr<nsIDOMElement> echeck;
          while (check != current) {        // Make sure prefix is not overridden
            echeck = do_QueryInterface(check);
            if (echeck) {
              rc = echeck->
                  HasAttributeNS(gSOAPStrings->kXMLNamespaceNamespaceURI, prefix,
                                 &hasDecl);
              if (NS_FAILED(rc))
                return rc;
              if (hasDecl)
                break;
              echeck->GetParentNode(getter_AddRefs(check));
            }
          }
          if (check == current) {
            aPrefix.Assign(prefix);
            return NS_OK;
          }
        }
        rc = temp->GetLocalName(tstr);
        if (NS_FAILED(rc))
          return rc;
        else {                        //  Decode the generated namespace into a number
          nsReadingIterator < PRUnichar > i1;
          nsReadingIterator < PRUnichar > i2;
          tstr.BeginReading(i1);
          tstr.EndReading(i2);
          if (i1 == i2 || *i1 != 'n')
            continue;
          i1++;
          if (i1 == i2 || *i1 != 's')
            continue;
          i1++;
          PRUint32 n = 0;
          while (i1 != i2) {
            PRUnichar c = *i1;
            i1++;
            if (c < '0' || c > '9') {
              n = 0;
              break;
            }
            n = n * 10 + (c - '0');
          }
          if (n > maxns)
            maxns = n;
        }
      }
    }
    current->GetParentNode(getter_AddRefs(temp));
    if (temp)
      current = temp;
    else
      break;
  }
// Create a unique prefix...
  PRUint32 len = 3;
  PRUint32 c = maxns + 1;
  while (c >= 10) {
    c = c / 10;
    len++;
  }
// Set the length and write it backwards since that's the easiest way..
  aPrefix.SetLength(len);
  nsWritingIterator < PRUnichar > i2;
  aPrefix.EndWriting(i2);
  c = maxns + 1;
  while (c > 0) {
    PRUint32 r = c % 10;
    c = c / 10;
    i2--;
    *i2 = (PRUnichar) (r + '0');
  }
  i2--;
  *i2 = 's';
  i2--;
  *i2 = 'n';

  // Declare the fabricated prefix
  if (aScope) {
    tstr.Assign(gSOAPStrings->kXMLNamespacePrefix);
    tstr.Append(aPrefix);
    rc = aScope->SetAttributeNS(gSOAPStrings->kXMLNamespaceNamespaceURI,
                                tstr, externalURI);
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: