* single value and saves it back to the db.
*/
public void updateAttributeValue(Integer userPropertiesId, String attributeName, String attributeValue) throws SystemException, Bug
{
UserPropertiesVO userPropertiesVO = getUserPropertiesVOWithId(userPropertiesId);
if(userPropertiesVO != null)
{
try
{
logger.info("attributeName:" + attributeName);
logger.info("versionValue:" + userPropertiesVO.getValue());
logger.info("attributeValue:" + attributeValue);
InputSource inputSource = new InputSource(new StringReader(userPropertiesVO.getValue()));
DOMParser parser = new DOMParser();
parser.parse(inputSource);
Document document = parser.getDocument();
NodeList nl = document.getDocumentElement().getChildNodes();
Node attributesNode = nl.item(0);
boolean existed = false;
nl = attributesNode.getChildNodes();
for(int i=0; i<nl.getLength(); i++)
{
Node n = nl.item(i);
if(n.getNodeName().equalsIgnoreCase(attributeName))
{
if(n.getFirstChild() != null && n.getFirstChild().getNodeValue() != null)
{
n.getFirstChild().setNodeValue(attributeValue);
existed = true;
break;
}
else
{
CDATASection cdata = document.createCDATASection(attributeValue);
n.appendChild(cdata);
existed = true;
break;
}
}
}
if(existed == false)
{
org.w3c.dom.Element attributeElement = document.createElement(attributeName);
attributesNode.appendChild(attributeElement);
CDATASection cdata = document.createCDATASection(attributeValue);
attributeElement.appendChild(cdata);
}
StringBuffer sb = new StringBuffer();
org.infoglue.cms.util.XMLHelper.serializeDom(document.getDocumentElement(), sb);
logger.info("sb:" + sb);
userPropertiesVO.setValue(sb.toString());
update(userPropertiesVO.getLanguageId(), userPropertiesVO.getContentTypeDefinitionId(), userPropertiesVO);
}
catch(Exception e)
{
e.printStackTrace();
}