1 23 24 package org.infoglue.cms.applications.contenttool.actions; 25 26 import java.io.StringReader ; 27 28 import org.apache.log4j.Logger; 29 import org.apache.xerces.parsers.DOMParser; 30 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController; 31 import org.infoglue.cms.entities.content.ContentVersionVO; 32 import org.infoglue.cms.util.ConstraintExceptionBuffer; 33 import org.infoglue.cms.util.XMLHelper; 34 import org.w3c.dom.Document ; 35 import org.w3c.dom.Node ; 36 import org.w3c.dom.NodeList ; 37 import org.xml.sax.InputSource ; 38 39 44 45 public class UpdateContentVersionAttributeAction extends ViewContentVersionAction 46 { 47 private final static Logger logger = Logger.getLogger(UpdateContentVersionAttributeAction.class.getName()); 48 49 private static final long serialVersionUID = 1L; 50 51 private ContentVersionVO contentVersionVO; 52 private Integer contentId; 53 private Integer languageId; 54 private Integer contentVersionId; 55 private String attributeName; 56 57 private ConstraintExceptionBuffer ceb; 58 59 public UpdateContentVersionAttributeAction() 60 { 61 this(new ContentVersionVO()); 62 } 63 64 public UpdateContentVersionAttributeAction(ContentVersionVO contentVersionVO) 65 { 66 this.contentVersionVO = contentVersionVO; 67 this.ceb = new ConstraintExceptionBuffer(); 68 } 69 70 public String doExecute() throws Exception 71 { 72 super.initialize(this.contentVersionId, this.contentId, this.languageId); 73 74 this.contentVersionVO = this.getContentVersionVO(); 75 76 String attributeValue = getRequest().getParameter(this.attributeName); 77 if(attributeValue != null) 78 { 79 setAttributeValue(this.contentVersionVO, this.attributeName, attributeValue); 80 ceb.throwIfNotEmpty(); 81 82 this.contentVersionVO.setVersionModifier(this.getInfoGluePrincipal().getName()); 83 ContentVersionController.getContentVersionController().update(this.contentId, this.languageId, this.contentVersionVO); 84 } 85 86 return "success"; 87 } 88 89 90 93 94 private void setAttributeValue(ContentVersionVO contentVersionVO, String attributeName, String attributeValue) 95 { 96 String value = ""; 97 if(this.contentVersionVO != null) 98 { 99 try 100 { 101 logger.info("VersionValue:" + this.contentVersionVO.getVersionValue()); 102 InputSource inputSource = new InputSource (new StringReader (this.contentVersionVO.getVersionValue())); 103 104 DOMParser parser = new DOMParser(); 105 parser.parse(inputSource); 106 Document document = parser.getDocument(); 107 108 NodeList nl = document.getDocumentElement().getChildNodes(); 109 Node n = nl.item(0); 110 111 nl = n.getChildNodes(); 112 for(int i=0; i<nl.getLength(); i++) 113 { 114 n = nl.item(i); 115 if(n.getNodeName().equalsIgnoreCase(attributeName)) 116 { 117 logger.info("Setting attributeValue: " + attributeValue); 118 Node valueNode = n.getFirstChild(); 119 n.getFirstChild().setNodeValue(attributeValue); 120 break; 121 } 122 } 123 contentVersionVO.setVersionValue(XMLHelper.serializeDom(document, new StringBuffer ()).toString()); 124 } 125 catch(Exception e) 126 { 127 e.printStackTrace(); 128 } 129 } 130 } 131 132 133 public void setContentVersionId(Integer contentVersionId) 134 { 135 this.contentVersionVO.setContentVersionId(contentVersionId); 136 } 137 138 public java.lang.Integer getContentVersionId() 139 { 140 return this.contentVersionVO.getContentVersionId(); 141 } 142 143 public void setStateId(Integer stateId) 144 { 145 this.contentVersionVO.setStateId(stateId); 146 } 147 148 public java.lang.Integer getStateId() 149 { 150 return this.contentVersionVO.getStateId(); 151 } 152 153 public void setContentId(Integer contentId) 154 { 155 this.contentId = contentId; 156 } 157 158 public java.lang.Integer getContentId() 159 { 160 return this.contentId; 161 } 162 163 public void setLanguageId(Integer languageId) 164 { 165 this.languageId = languageId; 166 } 167 168 public java.lang.Integer getLanguageId() 169 { 170 return this.languageId; 171 } 172 173 public java.lang.String getVersionValue() 174 { 175 return this.contentVersionVO.getVersionValue(); 176 } 177 178 public void setVersionValue(java.lang.String versionValue) 179 { 180 this.contentVersionVO.setVersionValue(versionValue); 181 } 182 183 public String getAttributeName() 184 { 185 return attributeName; 186 } 187 188 public void setAttributeName(String attributeName) 189 { 190 this.attributeName = attributeName; 191 } 192 193 } 194 | Popular Tags |