@Override public void insert(ProjectModuleBO module) { Element rootElement = getRootElement(); if (rootElement == null) return; // 创建module节点 Element moduleElement = new Element(NODE_MODULE); moduleElement.setAttribute(ATTR_ID, GuidUtil.getGUID() + ""); moduleElement.setAttribute(ATTR_NAME, module.getModuleName()); moduleElement.setAttribute(ATTR_REMARK, module.getRemark()); moduleElement.setAttribute(IBaseDao.FIELD_DELETEFLAG, IBaseDao.UNDELETE_SIGNE + ""); // 创建developers节点 Element developerElement = new Element(NODE_DEV); developerElement.setAttribute(ATTR_ID, module.getDevelopers()); moduleElement.addContent(developerElement); // 创建package节点 Element pakageElement = new Element(NODE_PACKAGE); Element srcElement = new Element(NODE_SRC); srcElement.setAttribute(ATTR_NAME, module.getSrcPackage()); Element jspElement = new Element(NODE_JSP); jspElement.setAttribute(ATTR_NAME, module.getJspPackage()); Element hbmElement = new Element(NODE_HBM); hbmElement.setAttribute(ATTR_NAME, module.getHbmPackage()); Element springElement = new Element(NODE_SPRING); springElement.setAttribute(ATTR_NAME, module.getSpringPackage()); Element pageflowElement = new Element(NODE_PAGEFLOW); pageflowElement.setAttribute(ATTR_NAME, module.getPageflowPackage()); Element varElement = new Element(NODE_VAR); varElement.setAttribute(ATTR_NAME, module.getVarPackage()); Element i18nElement = new Element(NODE_I18N); i18nElement.setAttribute(ATTR_NAME, module.getI18nPackage()); pakageElement.addContent(srcElement); pakageElement.addContent(jspElement); pakageElement.addContent(hbmElement); pakageElement.addContent(springElement); pakageElement.addContent(pageflowElement); pakageElement.addContent(varElement); pakageElement.addContent(i18nElement); moduleElement.addContent(pakageElement); rootElement.addContent(0, moduleElement); saveXML(rootElement); }
@SuppressWarnings("unchecked") @Override public void update(ProjectModuleBO module) { Element rootElement = getRootElement(); if (rootElement == null) return; List<Element> elements = getElmentsByXpath(getXPath_ModuleId(module.getId()), rootElement); if (ContainerUtil.isNull(elements)) return; // 修改moduleElement节点 Element moduleElement = elements.get(0); moduleElement.setAttribute(ATTR_NAME, module.getModuleName()); moduleElement.setAttribute(ATTR_REMARK, module.getRemark()); // 修改developers节点 Element developElement = moduleElement.getChild(NODE_DEV); developElement.setAttribute(ATTR_ID, module.getDevelopers()); // 修改package节点 Element packageElement = moduleElement.getChild(NODE_PACKAGE); List<Element> childElements = packageElement.getChildren(); for (Element packElement : childElements) { if (StringUtils.isEqual(NODE_SRC, packElement.getName())) packElement.setAttribute(ATTR_NAME, module.getSrcPackage()); else if (StringUtils.isEqual(NODE_JSP, packElement.getName())) packElement.setAttribute(ATTR_NAME, module.getJspPackage()); else if (StringUtils.isEqual(NODE_HBM, packElement.getName())) packElement.setAttribute(ATTR_NAME, module.getHbmPackage()); else if (StringUtils.isEqual(NODE_SPRING, packElement.getName())) packElement.setAttribute(ATTR_NAME, module.getSpringPackage()); else if (StringUtils.isEqual(NODE_PAGEFLOW, packElement.getName())) packElement.setAttribute(ATTR_NAME, module.getPageflowPackage()); else if (StringUtils.isEqual(NODE_VAR, packElement.getName())) packElement.setAttribute(ATTR_NAME, module.getVarPackage()); else if (StringUtils.isEqual(NODE_I18N, packElement.getName())) packElement.setAttribute(ATTR_NAME, module.getI18nPackage()); } saveXML(rootElement); }