public void saveXml(XmlFile inFile, User inUser, Lock lock) throws OpenEditException { // Lock lock = getLockManager().lock("system", inFile.getPath(), null ); //this will retry 10 // times then timeout and throw an exception Page page = getPageManager().getPage(inFile.getPath(), false); ContentItem tmp = getPageManager().getRepository().getStub(inFile.getPath() + ".tmp.xml"); tmp.setMakeVersion(false); getXmlUtil().saveXml(inFile.getRoot(), tmp.getOutputStream(), page.getCharacterEncoding()); ContentItem xmlcontent = getPageManager().getRepository().getStub(inFile.getPath()); xmlcontent.setMakeVersion(false); getPageManager() .getRepository() .remove(xmlcontent); // might be a little faster to remove it first getPageManager().getRepository().move(tmp, xmlcontent); getPageManager().firePageModified(page); xmlcontent = getPageManager().getRepository().getStub(inFile.getPath()); inFile.setLastModified(xmlcontent.getLastModified()); inFile.setExist(true); // log.info("Save " + inFile.getPath()); }
protected XmlFile load(String inId, String path, String inElementName, ContentItem input) throws OpenEditException { // log.info("Loading " + path); boolean found = false; XmlFile element; Element root = null; if (!input.exists()) { if (inElementName == null) { root = DocumentHelper.createElement("root"); } else { if (inElementName.endsWith("y")) { root = DocumentHelper.createElement( inElementName.substring(0, inElementName.length() - 1) + "ies"); } else { root = DocumentHelper.createElement(inElementName + "s"); } } } else { found = true; InputStream in = input.getInputStream(); try { root = getXmlUtil().getXml(in, "UTF-8"); } catch (OpenEditException ex) { log.error("file problem: " + path, ex); throw ex; } finally { FileUtils.safeClose(in); } } element = new XmlFile(); element.setRoot(root); element.setExist(found); element.setElementName(inElementName); element.setPath(path); element.setLastModified(input.lastModified().getTime()); element.setId(inId); return element; }