瀏覽代碼

Fix based on feedback.
- Removed ForEach loop since only 1 iteration is needed
- Cleaned up StringBuffer assignment
- Add check for NULL pointer and will throw an exception if encountered

Signed-off-by: Gleb Aronsky <gleb.aronsky@lexisnexis.com>

Gleb Aronsky 13 年之前
父節點
當前提交
cf3f53005e
共有 1 個文件被更改,包括 12 次插入6 次删除
  1. 12 6
      esp/services/WsDeploy/WsDeployService.cpp

+ 12 - 6
esp/services/WsDeploy/WsDeployService.cpp

@@ -4176,18 +4176,20 @@ bool CWsDeployFileInfo::handleComponent(IEspContext &context, IEspHandleComponen
     StringBuffer xpath;
     StringBuffer xpath;
     Owned<IPropertyTreeIterator> iterComp = pComponents->getElements("*");
     Owned<IPropertyTreeIterator> iterComp = pComponents->getElements("*");
 
 
-    ForEach(*iterComp)
+    if (iterComp->first() && iterComp->isValid())
     {
     {
       IPropertyTree& pComp = iterComp->query();
       IPropertyTree& pComp = iterComp->query();
       const char* compName = pComp.queryProp(XML_ATTR_NAME);
       const char* compName = pComp.queryProp(XML_ATTR_NAME);
       const char* compType = pComp.queryProp(XML_ATTR_COMPTYPE);
       const char* compType = pComp.queryProp(XML_ATTR_COMPTYPE);
 
 
       sbNewName = compName;
       sbNewName = compName;
-      xpath.clear().appendf("%s", compType);
+      xpath = compType;
       getUniqueName(pEnvRoot, sbNewName, xpath.str(), XML_TAG_SOFTWARE);
       getUniqueName(pEnvRoot, sbNewName, xpath.str(), XML_TAG_SOFTWARE);
       xpath.clear().appendf("./%s/%s[%s=\"%s\"]", XML_TAG_SOFTWARE, compType, XML_ATTR_NAME, compName);
       xpath.clear().appendf("./%s/%s[%s=\"%s\"]", XML_TAG_SOFTWARE, compType, XML_ATTR_NAME, compName);
       IPropertyTree* pCompTree = pEnvRoot->queryPropTree(xpath.str());
       IPropertyTree* pCompTree = pEnvRoot->queryPropTree(xpath.str());
-      xpath.clear().appendf("./%s/%s[%s=\"%s\"]", XML_TAG_SOFTWARE, compType, XML_ATTR_NAME, sbNewName.str());
+
+      if (pCompTree == NULL)
+        throw MakeStringException(-1,"XPATH: %s is invalid.", xpath.str());
 
 
       StringBuffer xml;
       StringBuffer xml;
       toXML(pCompTree, xml);
       toXML(pCompTree, xml);
@@ -4195,15 +4197,19 @@ bool CWsDeployFileInfo::handleComponent(IEspContext &context, IEspHandleComponen
       IPropertyTree *dupTree = createPTreeFromXMLString(xml.str());
       IPropertyTree *dupTree = createPTreeFromXMLString(xml.str());
       dupTree->setProp(XML_ATTR_NAME, sbNewName.str());
       dupTree->setProp(XML_ATTR_NAME, sbNewName.str());
 
 
+      xpath.clear().appendf("./%s/%s[%s=\"%s\"]", XML_TAG_SOFTWARE, compType, XML_ATTR_NAME, sbNewName.str());
+
       if (pEnvRoot->addPropTree(xpath, dupTree))
       if (pEnvRoot->addPropTree(xpath, dupTree))
         resp.setStatus("true");
         resp.setStatus("true");
       else
       else
         resp.setStatus("false");
         resp.setStatus("false");
-
-      resp.setCompName(XML_TAG_SOFTWARE);
     }
     }
+    else
+    {
+      resp.setStatus("false");
+    }
+    resp.setCompName(XML_TAG_SOFTWARE);
   }
   }
-
   return true;
   return true;
 }
 }