List of usage examples for org.dom4j Element clearContent
void clearContent();
Node
instances this branch may contain. From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java
License:Apache License
/** * Add revision property if needed.// w w w.j a v a 2s . c om */ private void addRevision() { if (!propsPart.getRevisionProperty().hasValue()) return; Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_REVISION, namespaceCoreProperties)); if (elem == null) { // missing, we add it elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_REVISION, namespaceCoreProperties)); } else { elem.clearContent();// clear the old value } elem.addText(propsPart.getRevisionProperty().getValue()); }
From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java
License:Apache License
/** * Add subject property if needed./*from ww w . jav a 2 s. c o m*/ */ private void addSubject() { if (!propsPart.getSubjectProperty().hasValue()) return; Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_SUBJECT, namespaceDC)); if (elem == null) { // missing, we add it elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_SUBJECT, namespaceDC)); } else { elem.clearContent();// clear the old value } elem.addText(propsPart.getSubjectProperty().getValue()); }
From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java
License:Apache License
/** * Add title property if needed./* w ww. j a v a2s . c o m*/ */ private void addTitle() { if (!propsPart.getTitleProperty().hasValue()) return; Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_TITLE, namespaceDC)); if (elem == null) { // missing, we add it elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_TITLE, namespaceDC)); } else { elem.clearContent();// clear the old value } elem.addText(propsPart.getTitleProperty().getValue()); }
From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java
License:Apache License
private void addVersion() { if (!propsPart.getVersionProperty().hasValue()) return;//from www . j av a2 s . c om Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_VERSION, namespaceCoreProperties)); if (elem == null) { // missing, we add it elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_VERSION, namespaceCoreProperties)); } else { elem.clearContent();// clear the old value } elem.addText(propsPart.getVersionProperty().getValue()); }
From source file:org.firesoa.common.jxpath.model.dom4j.Dom4JNodePointer.java
License:Open Source License
@Override public void setValue(Object value) { if (value == null) value = "";//null?? if ((node instanceof org.dom4j.CharacterData || node instanceof Attribute || node instanceof DocumentType || node instanceof Entity || node instanceof ProcessingInstruction)) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { ((Node) node).setText(string); } else {//from w w w.j a v a 2 s. c om ((Node) node).getParent().remove((Node) node); } } else if (node instanceof Document) { Document theOriginalDoc = (Document) node; Element theOrigialRoot = theOriginalDoc.getRootElement(); if (value instanceof Document) {//?document Document valueDoc = (Document) value; Element valueRoot = valueDoc.getRootElement(); if (theOrigialRoot == null || valueRoot == null || theOrigialRoot.getQName().equals(valueRoot.getQName())) { theOriginalDoc.clearContent(); List content = valueDoc.content(); if (content != null) { for (int i = 0; i < content.size(); i++) { Node dom4jNode = (Node) content.get(i); Node newDom4jNode = (Node) dom4jNode.clone(); theOriginalDoc.add(newDom4jNode); } } } else { throw new RuntimeException( "Can NOT assign " + valueRoot.getQName() + " to " + theOrigialRoot.getQName()); } } else if (value instanceof Element) { Element valueElem = (Element) value; if (valueElem.getQName().equals(theOrigialRoot.getQName())) { theOriginalDoc.clearContent(); Element newValueElem = (Element) valueElem.clone(); theOriginalDoc.setRootElement(newValueElem); } else { throw new RuntimeException( "Can NOT assign " + valueElem.getQName() + " to " + theOrigialRoot.getQName()); } } else { throw new RuntimeException("Can NOT assign " + value + " to " + theOrigialRoot.getQName()); } // else if (value instanceof Comment){ // Comment cmmt = (Comment)((Comment)value).clone(); // theOriginalDoc.add(cmmt); // // }else if (value instanceof ProcessingInstruction){ // ProcessingInstruction instru = (ProcessingInstruction)((ProcessingInstruction)value).clone(); // theOriginalDoc.add(instru); // } } else if (node instanceof Element) { Element originalElem = ((Element) node); if (value != null && value instanceof Element) { Element valueElm = (Element) value; if (originalElem.getQName().equals(valueElm.getQName())) { originalElem.clearContent(); List content = valueElm.content(); if (content != null) { for (int i = 0; i < content.size(); i++) { Node dom4jNode = (Node) content.get(i); Node newDom4jNode = (Node) dom4jNode.clone(); originalElem.add(newDom4jNode); } } } else { throw new RuntimeException( "Can NOT assign " + valueElm.getQName() + " to " + originalElem.getQName()); } } else if (value != null && value instanceof Text) { originalElem.clearContent(); Text txt = (Text) ((Text) value).clone(); originalElem.add(txt); } else if (value != null && value instanceof CDATA) { originalElem.clearContent(); CDATA cdata = (CDATA) ((CDATA) value).clone(); originalElem.add(cdata); } else if (value != null && value instanceof java.util.Date) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateStr = format.format((java.util.Date) value); originalElem.clearContent(); originalElem.addText(dateStr); } else { String string = (String) TypeUtils.convert(value, String.class); originalElem.clearContent(); originalElem.addText(string); } } }
From source file:org.infoglue.cms.webservices.RemoteContentServiceImpl.java
License:Open Source License
/** * Updates a content./* w w w. j av a 2 s . com*/ */ public Boolean updateContentVersion(final String principalName, final Object[] inputsArray) { if (!ServerNodeController.getController().getIsIPAllowed(getRequest())) { logger.error("A client with IP " + getRequest().getRemoteAddr() + " was denied access to the webservice. Could be a hack attempt or you have just not configured the allowed IP-addresses correct."); return new Boolean(false); } Boolean status = new Boolean(true); logger.info("****************************************"); logger.info("Updating content versions through webservice...."); logger.info("****************************************"); logger.info("principalName:" + principalName); logger.info("inputsArray:" + inputsArray); //logger.warn("contents:" + contents); try { final DynamicWebserviceSerializer serializer = new DynamicWebserviceSerializer(); Map contentVersion = (Map) serializer.deserialize(inputsArray); logger.info("contentVersion:" + contentVersion); initializePrincipal(principalName); Integer contentVersionId = (Integer) contentVersion.get("contentVersionId"); Integer contentId = (Integer) contentVersion.get("contentId"); Integer languageId = (Integer) contentVersion.get("languageId"); Integer stateId = (Integer) contentVersion.get("stateId"); String versionComment = (String) contentVersion.get("versionComment"); Boolean allowHTMLContent = (Boolean) contentVersion.get("allowHTMLContent"); Boolean allowExternalLinks = (Boolean) contentVersion.get("allowExternalLinks"); Boolean allowDollarSigns = (Boolean) contentVersion.get("allowDollarSigns"); Boolean allowAnchorSigns = (Boolean) contentVersion.get("allowAnchorSigns"); Boolean keepExistingAttributes = (Boolean) contentVersion.get("keepExistingAttributes"); Boolean keepExistingCategories = (Boolean) contentVersion.get("keepExistingCategories"); Boolean updateExistingAssets = (Boolean) contentVersion.get("updateExistingAssets"); Boolean createVersionIfNotExists = (Boolean) contentVersion.get("createVersionIfNotExists"); if (allowHTMLContent == null) allowHTMLContent = new Boolean(false); if (allowExternalLinks == null) allowExternalLinks = new Boolean(false); if (keepExistingCategories == null) keepExistingCategories = new Boolean(true); if (updateExistingAssets == null) updateExistingAssets = new Boolean(true); if (allowDollarSigns == null) allowDollarSigns = new Boolean(false); if (allowAnchorSigns == null) allowAnchorSigns = new Boolean(true); if (createVersionIfNotExists == null) createVersionIfNotExists = new Boolean(true); logger.info("contentVersionId:" + contentVersionId); logger.info("contentId:" + contentId); logger.info("languageId:" + languageId); logger.info("stateId:" + stateId); logger.info("keepExistingAttributes:" + keepExistingAttributes); logger.info("keepExistingCategories:" + keepExistingCategories); logger.info("updateExistingAssets:" + updateExistingAssets); logger.info("versionComment:" + versionComment); logger.info("allowHTMLContent:" + allowHTMLContent); logger.info("allowExternalLinks:" + allowExternalLinks); logger.info("allowDollarSigns:" + allowDollarSigns); logger.info("allowAnchorSigns:" + allowAnchorSigns); logger.info("createVersionIfNotExists:" + createVersionIfNotExists); ContentVersionVO contentVersionVO = null; if (contentVersionId != null) contentVersionVO = ContentVersionController.getContentVersionController() .getContentVersionVOWithId(contentVersionId); else contentVersionVO = ContentVersionController.getContentVersionController() .getLatestActiveContentVersionVO(contentId, languageId); if (contentVersionVO != null) { try { logger.info("contentVersionVO:" + contentVersionVO); contentVersionVO = ContentStateController.changeState(contentVersionVO.getId(), ContentVersionVO.WORKING_STATE, "Remote update from deliver", false, this.principal, contentVersionVO.getContentId(), new ArrayList()); } catch (Exception e) { logger.error("Error when changing state to working: " + e.getMessage(), e); } } logger.info("contentVersionVO:" + contentVersionVO); boolean isNewlyCreatedVersion; if (contentVersionVO == null) { logger.info("createVersionIfNotExists:" + createVersionIfNotExists); if (createVersionIfNotExists) { ContentVersionVO newContentVersionVO = new ContentVersionVO(); newContentVersionVO.setVersionComment(versionComment); newContentVersionVO.setModifiedDateTime(new Date()); newContentVersionVO.setVersionModifier("" + principalName); contentVersionVO = contentVersionControllerProxy.acCreate(this.principal, contentId, languageId, newContentVersionVO); isNewlyCreatedVersion = true; logger.info("contentVersionVO (newly created):" + contentVersionVO); } else return new Boolean(false); } else { contentVersionVO.setVersionComment(versionComment); contentVersionVO.setModifiedDateTime(new Date()); contentVersionVO.setVersionModifier("" + principalName); isNewlyCreatedVersion = false; } Map attributes = (Map) contentVersion.get("contentVersionAttributes"); if (attributes != null && attributes.size() > 0) { DOMBuilder domBuilder = new DOMBuilder(); Element attributesRoot = null; Document document = null; if (keepExistingAttributes && !isNewlyCreatedVersion) { String existingXML = contentVersionVO.getVersionValue(); document = domBuilder.getDocument(existingXML); attributesRoot = (Element) document.getRootElement().element("attributes"); } else { document = domBuilder.createDocument(); Element rootElement = domBuilder.addElement(document, "root"); domBuilder.addAttribute(rootElement, "xmlns", "x-schema:Schema.xml"); attributesRoot = domBuilder.addElement(rootElement, "attributes"); } if (logger.isDebugEnabled()) logger.info("attributesRoot:" + attributesRoot); Iterator attributesIterator = attributes.keySet().iterator(); while (attributesIterator.hasNext()) { String attributeName = (String) attributesIterator.next(); String attributeValue = (String) attributes.get(attributeName); attributeValue = cleanAttributeValue(attributeValue, allowHTMLContent, allowExternalLinks, allowDollarSigns, allowAnchorSigns); if (keepExistingAttributes) { Element attribute = attributesRoot.element(attributeName); if (attribute == null) { attribute = domBuilder.addElement(attributesRoot, attributeName); } attribute.clearContent(); domBuilder.addCDATAElement(attribute, attributeValue); } else { Element attribute = domBuilder.addElement(attributesRoot, attributeName); domBuilder.addCDATAElement(attribute, attributeValue); } } contentVersionVO.setVersionValue(document.asXML()); } ContentVersionControllerProxy.getController().acUpdate(principal, contentId, languageId, contentVersionVO); //Assets now List digitalAssets = (List) contentVersion.get("digitalAssets"); if (digitalAssets != null) { logger.info("digitalAssets:" + digitalAssets.size()); Iterator digitalAssetIterator = digitalAssets.iterator(); while (digitalAssetIterator.hasNext()) { RemoteAttachment remoteAttachment = (RemoteAttachment) digitalAssetIterator.next(); logger.info("digitalAssets in ws:" + remoteAttachment); /* DigitalAssetVO newAsset = new DigitalAssetVO(); newAsset.setAssetContentType(remoteAttachment.getContentType()); newAsset.setAssetKey(remoteAttachment.getName()); newAsset.setAssetFileName(remoteAttachment.getFileName()); newAsset.setAssetFilePath(remoteAttachment.getFilePath()); newAsset.setAssetFileSize(new Integer(new Long(remoteAttachment.getBytes().length).intValue())); */ InputStream is = new ByteArrayInputStream(remoteAttachment.getBytes()); DigitalAssetVO existingAssetVO = DigitalAssetController .getLatestDigitalAssetVO(contentVersionVO.getId(), remoteAttachment.getName()); if (updateExistingAssets && existingAssetVO != null) { ContentVersionController.getContentVersionController().deleteDigitalAssetRelation( contentVersionVO.getId(), existingAssetVO.getId(), principal); DigitalAssetVO digitalAssetVO = new DigitalAssetVO(); digitalAssetVO.setAssetContentType(remoteAttachment.getContentType()); digitalAssetVO.setAssetKey(remoteAttachment.getName()); digitalAssetVO.setAssetFileName(remoteAttachment.getFileName()); digitalAssetVO.setAssetFilePath(remoteAttachment.getFilePath()); digitalAssetVO.setAssetFileSize( new Integer(new Long(remoteAttachment.getBytes().length).intValue())); DigitalAssetController.create(digitalAssetVO, is, contentVersionVO.getContentVersionId(), principal); } else { DigitalAssetVO newAsset = new DigitalAssetVO(); newAsset.setAssetContentType(remoteAttachment.getContentType()); newAsset.setAssetKey(remoteAttachment.getName()); newAsset.setAssetFileName(remoteAttachment.getFileName()); newAsset.setAssetFilePath(remoteAttachment.getFilePath()); newAsset.setAssetFileSize( new Integer(new Long(remoteAttachment.getBytes().length).intValue())); DigitalAssetController.create(newAsset, is, contentVersionVO.getContentVersionId(), principal); } } } if (!keepExistingCategories) { ContentCategoryController.getController().deleteByContentVersion(contentVersionVO.getId()); // .deleteByContentVersion(contentVersionVO.getId(), db); } List contentCategories = (List) contentVersion.get("contentCategories"); logger.info("contentCategories:" + contentCategories); if (contentCategories != null) { Iterator contentCategoriesIterator = contentCategories.iterator(); while (contentCategoriesIterator.hasNext()) { String contentCategoryString = (String) contentCategoriesIterator.next(); String[] split = contentCategoryString.split("="); String categoryKey = split[0]; String fullCategoryName = split[1]; logger.info("categoryKey:" + categoryKey); logger.info("fullCategoryName:" + fullCategoryName); CategoryVO categoryVO = CategoryController.getController().findByPath(fullCategoryName); logger.info("categoryVO:" + categoryVO); List categoryVOList = new ArrayList(); categoryVOList.add(categoryVO); Database db = beginTransaction(); try { ContentVersion latestContentVersion = ContentVersionController.getContentVersionController() .getContentVersionWithId(contentVersionVO.getId(), db); logger.info("Adding categoryKey:" + categoryKey + " to " + contentVersionVO.getId() + ":" + categoryVO); //ContentCategoryController.getController().create(categoryVOList, newContentVersionVO, categoryKey); final List categories = categoryVOListToCategoryList(categoryVOList, db); ContentCategoryController.getController().create(categories, latestContentVersion, categoryKey, db); commitTransaction(db); } catch (Exception e) { logger.warn("An error occurred so we should not complete the transaction:" + e); rollbackTransaction(db); throw new SystemException(e.getMessage()); } } } //Should we also change state on newly created content version? if (stateId != null && !stateId.equals(ContentVersionVO.WORKING_STATE)) { List events = new ArrayList(); ContentStateController.changeState(contentVersionVO.getId(), stateId, "Remote update from deliver", false, this.principal, contentVersionVO.getContentId(), events); if (stateId.equals(ContentVersionVO.PUBLISHED_STATE)) { PublicationVO publicationVO = new PublicationVO(); publicationVO.setName("Direct publication by " + this.principal.getName()); publicationVO.setDescription("Direct publication from deliver"); ContentVO contentVO = ContentController.getContentController() .getContentVOWithId(contentVersionVO.getContentId()); publicationVO.setRepositoryId(contentVO.getRepositoryId()); publicationVO = PublicationController.getController().createAndPublish(publicationVO, events, false, this.principal); } } logger.info("Done with contentVersion.."); } catch (Throwable e) { status = new Boolean(false); logger.error("En error occurred when we tried to create a new content:" + e.getMessage()); logger.warn("En error occurred when we tried to create a new content:" + e.getMessage(), e); } updateCaches(); return status; }
From source file:org.infoglue.common.labels.controllers.LabelsController.java
License:Open Source License
public void updateLabels(String nameSpace, String languageCode, Map properties, Session session) throws Exception { Document document = getPropertyDocument(nameSpace, session); //String xml1 = domBuilder.getFormattedDocument(document, "UTF-8"); //log.debug("xml1:" + xml1); String xpath = "/languages/language[@languageCode='" + languageCode + "']/labels"; //String xpath = "/languages/language[@languageCode='" + languageCode +"']/labels"; //log.debug("xpath:" + xpath); Element labelsElement = (Element) document.selectSingleNode(xpath); //log.debug("labelsElement:" + labelsElement); Iterator keyInterator = properties.keySet().iterator(); while (keyInterator.hasNext()) { String key = (String) keyInterator.next(); String value = (String) properties.get(key); if (!Character.isLetter(key.charAt(0))) key = "NP" + key; if (key != null && value != null) { Element labelElement = labelsElement.element(key); if (labelElement == null) labelElement = domBuilder.addElement(labelsElement, key); labelElement.clearContent(); List elements = labelElement.elements(); Iterator elementsIterator = elements.iterator(); while (elementsIterator.hasNext()) { Element element = (Element) elementsIterator.next(); //log.debug("Removing element:" + element.asXML()); labelElement.remove(element); }/* w w w .j a v a 2s. c o m*/ domBuilder.addCDATAElement(labelElement, value); } } String xml = domBuilder.getFormattedDocument(document, "UTF-8"); //log.debug("xml:" + xml); labelsPersister.updateProperty(nameSpace, "systemLabels", xml, session); CacheController.clearCache(LABELSPROPERTIESCACHENAME); }
From source file:org.infoglue.common.settings.controllers.CastorSettingsController.java
License:Open Source License
public void updateSettings(String nameSpace, String name, String id, Map properties, Database database) throws Exception { if (id == null || id.equals("-1")) id = "default"; Document document = getPropertyDocument(nameSpace, name, database); //String xml1 = domBuilder.getFormattedDocument(document, "UTF-8"); //log.debug("xml1:" + xml1); String xpath = "/variations/variation[@id='" + id + "']/setting"; //log.debug("xpath:" + xpath); Element labelsElement = (Element) document.selectSingleNode(xpath); //log.debug("labelsElement:" + labelsElement); Iterator keyInterator = properties.keySet().iterator(); while (keyInterator.hasNext()) { String key = (String) keyInterator.next(); String value = (String) properties.get(key); if (!Character.isLetter(key.charAt(0))) key = "NP" + key; if (key != null && value != null && labelsElement != null) { Element labelElement = labelsElement.element(key); if (labelElement == null) { labelElement = domBuilder.addElement(labelsElement, key); } else { labelElement.clearContent(); List elements = labelElement.elements(); Iterator elementsIterator = elements.iterator(); while (elementsIterator.hasNext()) { Element element = (Element) elementsIterator.next(); //log.debug("Removing element:" + element.asXML()); labelElement.remove(element); }//from www.j av a 2 s. c om } domBuilder.addCDATAElement(labelElement, value); } } String xml = domBuilder.getFormattedDocument(document, "UTF-8"); settingsPersister.updateProperty(nameSpace, name, xml, database); CacheController.clearCache(CacheController.SETTINGSPROPERTIESCACHENAME); CacheController.clearCache(CacheController.SETTINGSPROPERTIESDOCUMENTCACHENAME); }
From source file:org.infoglue.common.settings.controllers.SettingsController.java
License:Open Source License
public void updateSettings(String nameSpace, String id, Map properties, Session session) throws Exception { Document document = getPropertyDocument(nameSpace, session); //String xml1 = domBuilder.getFormattedDocument(document, "UTF-8"); //log.debug("xml1:" + xml1); String xpath = "/variations/variation[@id='" + id + "']/setting"; //String xpath = "/languages/language[@languageCode='" + languageCode +"']/labels"; //log.debug("xpath:" + xpath); Element labelsElement = (Element) document.selectSingleNode(xpath); //log.debug("labelsElement:" + labelsElement); Iterator keyInterator = properties.keySet().iterator(); while (keyInterator.hasNext()) { String key = (String) keyInterator.next(); String value = (String) properties.get(key); if (!Character.isLetter(key.charAt(0))) key = "NP" + key; if (key != null && value != null && labelsElement != null) { Element labelElement = labelsElement.element(key); if (labelElement == null) labelElement = domBuilder.addElement(labelsElement, key); labelElement.clearContent(); List elements = labelElement.elements(); Iterator elementsIterator = elements.iterator(); while (elementsIterator.hasNext()) { Element element = (Element) elementsIterator.next(); //log.debug("Removing element:" + element.asXML()); labelElement.remove(element); }//ww w .j a v a 2s . com domBuilder.addCDATAElement(labelElement, value); } } String xml = domBuilder.getFormattedDocument(document, "UTF-8"); //log.debug("xml:" + xml); labelsPersister.updateProperty(nameSpace, "systemSettings", xml, session); CacheController.clearCache(SETTINGSPROPERTIESCACHENAME); }
From source file:org.infoglue.igide.editor.IGMultiPageEditor.java
License:Open Source License
/** * Saves the multi-page editor's document. *///from www.j a va 2 s .c o m public void doSave(IProgressMonitor monitor) { Logger.logConsole("YES - doSave: " + monitor + ":" + isReloadCMSPushCall); saving = true; boolean dirtyflag = isDirty(); Utils.getMonitor(monitor).beginTask("Saving content to CMS", 100); for (int i = 0; i < getPageCount(); i++) { IEditorPart editor = getEditor(i); editor.doSave(monitor); } Logger.logConsole("Saved each editor part..."); Utils.getMonitor(monitor).worked(25); InfoglueEditorInput input = getInfoglueEditorInput(); Logger.logConsole("input: " + input); input.getContent().doSave(monitor); System.out.println("isReloadCMSPushCall: " + isReloadCMSPushCall); if (!isReloadCMSPushCall) try { Logger.logConsole("saveLocalXML called"); ContentVersion cv = InfoglueCMS.getProjectContentVersion( input.getContent().getNode().getProject().getName(), input.getContent().getNode().getId()); SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(cv.getValue())); Map<String, String> namespaceUris = new HashMap<String, String>(); namespaceUris.put("art", "x-schema:ArticleSchema.xml"); XPath xPath = DocumentHelper.createXPath("/art:article/art:attributes"); xPath.setNamespaceURIs(namespaceUris); Element attributesNode = (Element) xPath.selectSingleNode(document); //(Element)document.selectSingleNode("/article/attributes"); @SuppressWarnings("unchecked") List<Element> attributes = attributesNode.elements();//document.selectNodes("//attributes/*"); EditableInfoglueContent content = input.getContent(); final ArrayList<String> contentAttributes = content.getAttributesOrder(); Map<String, Element> attributeMap = new HashMap<String, Element>(); // This loop remove elements from the DOM element for (Element attribute : attributes) { // DOM4j will shorten empty attributes, which is not good for InfoGlue if ("".equals(attribute.getText())) { attribute.clearContent(); attribute.addCDATA(""); } if (attributeMap.containsKey(attribute.getName())) { Logger.logConsole("Found duplicate attribute. Removing it. Name: " + attribute.getName()); attributesNode.remove(attribute); } else { String attributeName = attribute.getName(); if (contentAttributes.contains(attributeName)) { attributeMap.put(attributeName, attribute); } else if (!"IGAuthorFullName".equals(attributeName) && !"IGAuthorEmail".equals(attributeName)) { Logger.logConsole( "Found attribute in version that is not in the content type. Removing. Name: " + attributeName); attributesNode.remove(attribute); } } } // This loop add elements to the DOM element for (int i = 0; i < getPageCount(); i++) { IEditorPart editor = getEditor(i); editor.doSave(monitor); IEditorInput editorInput = editor.getEditorInput(); AttributeEditorInput attributeInput = null; if (editorInput instanceof AttributeEditorInput) { attributeInput = (AttributeEditorInput) editorInput; ContentTypeAttribute cta = attributeInput.getAttribute(); Element attributeNode = attributeMap.get(cta.getName()); if (attributeNode == null) { Logger.logConsole("Found no attribute for editor, name: " + cta.getName()); Element attributeElement = attributesNode.addElement(cta.getName()); attributeElement.clearContent(); attributeElement.addCDATA(cta.getValue()); } else { System.out.println("Setting value: " + cta.getValue() + " on node: " + cta.getName()); attributeNode.clearContent(); attributeNode.addCDATA(cta.getValue()); } } } // Sort the attributes attributes = (List<Element>) attributesNode.elements(); Collections.sort(attributes, new Comparator<Element>() { @Override public int compare(Element element1, Element element2) { int index1 = contentAttributes.indexOf(element1); int index2 = contentAttributes.indexOf(element2); if (index1 != -1 && index2 != -1) { return index1 - index2; } else if (index1 == -1 && index2 != -1) { return 1; } else if (index1 != -1 && index2 == -1) { return -1; } else { return 0; } } }); // Re-set the attributes after manipulation and sorting attributesNode.setContent(attributes); cv.setValue(document.asXML()); InfoglueCMS.saveLocalXML(input.getContent().getNode(), cv); Logger.logConsole((new StringBuilder("Part in doSave:")).append(cv.getValue().substring(113, 200)) .toString()); } catch (Exception e) { Logger.logConsole("Error in saveLocal"); System.out.println("Exception: " + e.getMessage() + ", class: " + e.getClass()); e.printStackTrace(); } Utils.getMonitor(monitor).worked(100); Utils.getMonitor(monitor).done(); saving = false; }