List of usage examples for org.dom4j Attribute setValue
void setValue(String value);
UnsupportedOperationException
if it is read-only. From source file:com.glaf.core.xml.XmlBuilder.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" }) protected void processForEachNode(Element element, Map<String, DatasetModel> dataSetMap, Map<String, Object> myDataMap, String systemName, Map<String, Object> params) { //LOG.debug("---------------------processForEachNode-----------------------"); Element parent = element.getParent(); String dsId = element.attributeValue("DataSetId"); if (StringUtils.isNotEmpty(dsId)) { if (myDataMap != null && !myDataMap.isEmpty()) { params.putAll(myDataMap);/*from w ww. j a v a2 s. c om*/ } DatasetModel dsm = dataSetMap.get(dsId); String sql = dsm.getSql(); String queryId = dsm.getQueryId(); List<Map<String, Object>> rows = null; if (StringUtils.isNotEmpty(queryId)) { Environment.setCurrentSystemName(systemName); List<Object> list = entityService.getList(queryId, params); if (list != null && !list.isEmpty()) { rows = new ArrayList<Map<String, Object>>(); for (Object object : list) { if (object instanceof Map) { Map dataMap = (Map) object; rows.add(dataMap); } else { try { Map dataMap = BeanUtils.describe(object); rows.add(dataMap); } catch (Exception e) { } } } } } else if (StringUtils.isNotEmpty(sql)) { LOG.debug("sql:" + sql); LOG.debug("params:" + params); rows = queryHelper.getResultList(systemName, sql, params); // ITablePageService tablePageService = // ContextFactory.getBean("tablePageService"); // rows = queryHelper.getResultList(systemName, sql, params); // Environment.setCurrentSystemName(systemName); // rows = tablePageService.getListData(sql, params); LOG.debug("#1 rows:" + rows.size()); } if (rows != null && !rows.isEmpty()) { int sortNo = 0; List<?> elements = element.elements(); if (elements != null && elements.size() == 1) { Element elem = (Element) elements.get(0); LOG.debug("name:" + elem.getName()); for (Map<String, Object> dataMap : rows) { sortNo = sortNo + 1; dataMap.put("sortNo", sortNo); Element e = elem.createCopy(); if (dsm.getControllers() != null && !dsm.getControllers().isEmpty()) { List<FieldController> controllers = dsm.getControllers(); for (FieldController c : controllers) { Class<?> x = ClassUtils.classForName(c.getProvider()); FieldConverter fp = (FieldConverter) ReflectUtils.newInstance(x); fp.convert(c.getFromName(), c.getToName(), dataMap); } } if (e.isTextOnly()) { String value = e.getStringValue(); if (StringUtils.contains(value, "#{") && StringUtils.contains(value, "}")) { String text = QueryUtils.replaceBlankParas(value, dataMap); e.setText(text); } } List<?> attrs = e.attributes(); Iterator<?> iter = attrs.iterator(); while (iter.hasNext()) { Attribute attr = (Attribute) iter.next(); String value = attr.getValue(); if (StringUtils.contains(value, "#{") && StringUtils.contains(value, "}")) { String text = QueryUtils.replaceBlankParas(value, dataMap); attr.setValue(text); } } e.setParent(null); parent.add(e); } } } } parent.remove(element); }
From source file:com.glaf.core.xml.XmlBuilder.java
License:Apache License
protected void processTextNode(Element element, Map<String, DatasetModel> dataSetMap, Map<String, Object> dataMap, String systemName, Map<String, Object> params) { //LOG.debug("---------------------processTextNode-----------------------"); if (StringUtils.equals(element.getName(), "foreach")) { this.processForEachNode(element, dataSetMap, dataMap, systemName, params); return;/*from ww w . j av a 2 s. c o m*/ } String dsId = element.attributeValue("DataSetId"); if (StringUtils.isNotEmpty(dsId)) { if (dataMap != null && !dataMap.isEmpty()) { params.putAll(dataMap); } this.processNode(element, dataSetMap, systemName, params); return; } if (element.isTextOnly()) { String value = element.getStringValue(); if (StringUtils.contains(value, "#{") && StringUtils.contains(value, "}")) { String text = QueryUtils.replaceBlankParas(value, dataMap); element.setText(text); } } List<?> attrs = element.attributes(); Iterator<?> iter = attrs.iterator(); while (iter.hasNext()) { Attribute attr = (Attribute) iter.next(); String value = attr.getValue(); if (StringUtils.contains(value, "#{") && StringUtils.contains(value, "}")) { String text = QueryUtils.replaceBlankParas(value, dataMap); attr.setValue(text); } } List<?> elements = element.elements(); Iterator<?> iterator = elements.iterator(); while (iterator.hasNext()) { Element elem = (Element) iterator.next(); if (StringUtils.equals(elem.getName(), "foreach")) { this.processForEachNode(elem, dataSetMap, dataMap, systemName, params); } else { String dsId2 = elem.attributeValue("DataSetId"); if (StringUtils.isNotEmpty(dsId2)) { if (dataMap != null && !dataMap.isEmpty()) { params.putAll(dataMap); } this.processNode(elem, dataSetMap, systemName, params); } else { this.processTextNode(elem, dataSetMap, dataMap, systemName, params); } } } }
From source file:com.globalsight.everest.projecthandler.ProjectHandlerLocal.java
License:Apache License
/** * Import a workflow template info object based on the given new name * // w ww. ja v a 2s .c o m * @param p_newName * - The new name given to the workflow template info. * * @exception RemoteException * System or network related exception. * @exception ProjectHandlerException * Component specific exception */ public void importWorkflowTemplates(Document doc, String p_newName, Collection p_localePairs, String p_displayRoleName, String projectId) throws RemoteException, ProjectHandlerException { Session session = HibernateUtil.getSession(); Transaction tx = session.beginTransaction(); WorkflowTemplate workflowTemplate = new WorkflowTemplate(); try { Iterator it = p_localePairs.iterator(); // UnitOfWork uow = PersistenceService.getInstance() // .acquireUnitOfWork(); while (it.hasNext()) { LocalePair localePair = (LocalePair) it.next(); List rolesNodes = doc.selectNodes("/process-definition/task-node/task/assignment/roles"); GlobalSightLocale source = localePair.getSource(); GlobalSightLocale target = localePair.getTarget(); Iterator iter = rolesNodes.iterator(); while (iter.hasNext()) { Element rolesElement = (Element) iter.next(); String content = rolesElement.getText(); content = content.substring(0, content.indexOf(source.toString()) + source.toString().length()); rolesElement.setText(content + " " + target.toString()); } List rolesNameNodes = doc.selectNodes("/process-definition/task-node/task/assignment/role_name"); Iterator ite = rolesNameNodes.iterator(); while (ite.hasNext()) { Element element = (Element) ite.next(); element.setText(p_displayRoleName); } List rolesTypeNodes = doc.selectNodes("/process-definition/task-node/task/assignment/role_type"); ite = rolesTypeNodes.iterator(); while (ite.hasNext()) { Element element = (Element) ite.next(); element.setText("false"); } String name = generateAutoName(p_newName, localePair); c_category.info("The value of name is " + name); Attribute attribute = (Attribute) doc.selectSingleNode("/process-definition/@name"); attribute.setValue(name); workflowTemplate.setName(name); WorkflowTemplateInfo workflowTemplateInfo = createNewWorkflowTemplateInfo(name, localePair, projectId); WorkflowTemplate jbpmTemp = ServerProxy.getWorkflowServer().importWorkflowTemplate(workflowTemplate, doc); workflowTemplateInfo.setWorkflowTemplate(jbpmTemp); // uow.registerObject(dupWorkflowTemplateInfo); session.save(workflowTemplateInfo); } // uow.commit(); tx.commit(); } catch (Exception e) { String[] args = new String[1]; args[0] = workflowTemplate.getName(); tx.rollback(); throw new ProjectHandlerException(ProjectHandlerException.MSG_FAILED_TO_DUPLICATE_WFI, args, e); } }
From source file:com.globalsight.everest.tm.exporter.TmxChecker.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" }) public String fixSegment(String segment) { Document dom = getDom(segment); Element root = dom.getRootElement(); Iterator ite = dtdMap.entrySet().iterator(); while (ite.hasNext()) { Map.Entry entry = (Map.Entry) ite.next(); String key = (String) entry.getKey(); ArrayList array = (ArrayList) entry.getValue(); String nodeName = "//" + key; List nodes = root.selectNodes(nodeName); for (int x = 0; x < nodes.size(); x++) { Element node = (Element) nodes.get(x); Attribute internalAttr = node.attribute("internal"); Attribute typeAttr = node.attribute("type"); ArrayList list = new ArrayList(); list.addAll(node.attributes()); resetXAttribute(key, list);/*from w w w . j av a 2 s.co m*/ for (int y = 0; y < list.size(); y++) { Attribute temp = (Attribute) list.get(y); String name = temp.getName(); if (!array.contains(name)) { node.remove(temp); } } // GBS-3537 & GBS-3691 if (internalAttr != null && "yes".equalsIgnoreCase(internalAttr.getValue())) { String exportedType = "x-internal"; if (typeAttr != null) { String type = typeAttr.getValue(); if (StringUtil.isNotEmpty(type)) { exportedType += "-" + type.trim().toLowerCase(); } typeAttr.setValue(exportedType); } else { node.add(new DefaultAttribute("type", exportedType)); } } } } return root.asXML(); }
From source file:com.globalsight.everest.tm.exporter.TmxChecker.java
License:Apache License
/** * When export TM, "internal='yes' type='style'" will be merged to * "type='x-internal-style'"; When import back, need revert back. * * @param segment/*w ww.j a v a 2 s . co m*/ * @return */ public String revertInternalTag(String segment) { Document dom = getDom(segment); Element root = dom.getRootElement(); for (String tag : dtdMap.keySet()) { String nodeName = "//" + tag; List nodes = root.selectNodes(nodeName); for (int x = 0; x < nodes.size(); x++) { Element node = (Element) nodes.get(x); if (node.attribute("type") != null && node.attribute("type").getValue() != null) { Attribute typeAttr = node.attribute("type"); String type = typeAttr.getValue(); if ("x-internal".equalsIgnoreCase(type)) { node.remove(typeAttr); node.add(new DefaultAttribute("internal", "yes")); } else if (type.startsWith("x-internal")) { String realTypeValue = type.substring("x-internal".length() + 1); typeAttr.setValue(realTypeValue); node.add(new DefaultAttribute("internal", "yes")); } } } } return root.asXML(); }
From source file:com.globalsight.everest.tm.exporter.TmxChecker.java
License:Apache License
private void resetXAttribute(String name, List list) { if (name == null || !needCheckXAttribute.contains(name)) { return;/*from w w w.java 2 s . c om*/ } Attribute idAttr = null; Attribute xAttr = null; for (int x = 0; x < list.size(); x++) { Attribute temp = (Attribute) list.get(x); if (temp.getName().equals("id")) { idAttr = temp; } else if (temp.getName().equals("x")) { xAttr = temp; } } if (idAttr != null && xAttr != null) { try { Integer.parseInt(xAttr.getValue()); } catch (NumberFormatException nfe) { xAttr.setValue(idAttr.getValue()); } } }
From source file:com.haulmont.cuba.core.app.EntitySnapshotManager.java
License:Apache License
protected void replaceClasses(Element element, Map<Class, Class> classMapping) { // translate XML for (Map.Entry<Class, Class> classEntry : classMapping.entrySet()) { Class beforeClass = classEntry.getKey(); Class afterClass = classEntry.getValue(); checkNotNull(beforeClass);/*from w w w. j ava 2 s . c om*/ checkNotNull(afterClass); // If BeforeClass != AfterClass if (!beforeClass.equals(afterClass)) { String beforeClassName = beforeClass.getCanonicalName(); String afterClassName = afterClass.getCanonicalName(); if (beforeClassName.equals(element.getName())) { element.setName(afterClassName); } Attribute classAttribute = element.attribute("class"); if ((classAttribute != null) && beforeClassName.equals(classAttribute.getValue())) { classAttribute.setValue(afterClassName); } } } }
From source file:com.haulmont.cuba.gui.components.filter.FilterDelegateImpl.java
License:Apache License
@Override public boolean saveSettings(Element element) { Boolean changed = false;/*from w w w .ja va 2s . c o m*/ Element e = element.element("defaultFilter"); if (e == null) e = element.addElement("defaultFilter"); UUID defaultId = null; Boolean applyDefault = false; for (FilterEntity filter : filterEntities) { if (BooleanUtils.isTrue(filter.getIsDefault())) { defaultId = filter.getId(); applyDefault = filter.getApplyDefault(); break; } } String newDef = defaultId != null ? defaultId.toString() : null; Attribute attr = e.attribute("id"); String oldDef = attr != null ? attr.getValue() : null; if (!Objects.equals(oldDef, newDef)) { if (newDef == null && attr != null) { e.remove(attr); } else { if (attr == null) e.addAttribute("id", newDef); else attr.setValue(newDef); } changed = true; } Boolean newApplyDef = BooleanUtils.isTrue(applyDefault); Attribute applyDefaultAttr = e.attribute("applyDefault"); Boolean oldApplyDef = applyDefaultAttr != null ? Boolean.valueOf(applyDefaultAttr.getValue()) : false; if (!Objects.equals(oldApplyDef, newApplyDef)) { if (applyDefaultAttr != null) { applyDefaultAttr.setValue(newApplyDef.toString()); } else { e.addAttribute("applyDefault", newApplyDef.toString()); } changed = true; } Element groupBoxExpandedEl = element.element("groupBoxExpanded"); if (groupBoxExpandedEl == null) groupBoxExpandedEl = element.addElement("groupBoxExpanded"); Boolean oldGroupBoxExpandedValue = Boolean.valueOf(groupBoxExpandedEl.getText()); Boolean newGroupBoxExpandedValue = groupBoxLayout.isExpanded(); if (!Objects.equals(oldGroupBoxExpandedValue, newGroupBoxExpandedValue)) { groupBoxExpandedEl.setText(newGroupBoxExpandedValue.toString()); changed = true; } return changed; }
From source file:com.haulmont.cuba.security.app.UserSettingServiceBean.java
License:Apache License
@Override public void copySettings(User fromUser, User toUser) { MetaClass metaClass = metadata.getClassNN(UserSetting.class); Security security = AppBeans.get(Security.NAME); if (!security.isEntityOpPermitted(metaClass, EntityOp.CREATE)) { throw new AccessDeniedException(PermissionType.ENTITY_OP, metaClass.getName()); }/*from w w w. j a va2 s.c om*/ Map<UUID, Presentation> presentationsMap = copyPresentations(fromUser, toUser); copyUserFolders(fromUser, toUser, presentationsMap); Map<UUID, FilterEntity> filtersMap = copyFilters(fromUser, toUser); try (Transaction tx = persistence.createTransaction()) { EntityManager em = persistence.getEntityManager(); Query deleteSettingsQuery = em.createQuery("delete from sec$UserSetting s where s.user.id = ?1"); deleteSettingsQuery.setParameter(1, toUser); deleteSettingsQuery.executeUpdate(); tx.commitRetaining(); em = persistence.getEntityManager(); TypedQuery<UserSetting> q = em.createQuery("select s from sec$UserSetting s where s.user.id = ?1", UserSetting.class); q.setParameter(1, fromUser); List<UserSetting> fromUserSettings = q.getResultList(); for (UserSetting currSetting : fromUserSettings) { UserSetting newSetting = metadata.create(UserSetting.class); newSetting.setUser(toUser); newSetting.setClientType(currSetting.getClientType()); newSetting.setName(currSetting.getName()); try { Document doc = Dom4j.readDocument(currSetting.getValue()); List<Element> components = doc.getRootElement().element("components").elements("component"); for (Element component : components) { Attribute presentationAttr = component.attribute("presentation"); if (presentationAttr != null) { UUID presentationId = UuidProvider.fromString(presentationAttr.getValue()); Presentation newPresentation = presentationsMap.get(presentationId); if (newPresentation != null) { presentationAttr.setValue(newPresentation.getId().toString()); } } Element defaultFilterEl = component.element("defaultFilter"); if (defaultFilterEl != null) { Attribute idAttr = defaultFilterEl.attribute("id"); if (idAttr != null) { UUID filterId = UuidProvider.fromString(idAttr.getValue()); FilterEntity newFilter = filtersMap.get(filterId); if (newFilter != null) { idAttr.setValue(newFilter.getId().toString()); } } } } newSetting.setValue(Dom4j.writeDocument(doc, true)); } catch (Exception e) { newSetting.setValue(currSetting.getValue()); } em.persist(newSetting); } tx.commit(); } }
From source file:com.hihframework.osplugins.dom4j.XmlParseUtil.java
License:Apache License
/** * ???/*from www.j ava 2 s . c o m*/ * * @param element * * @param attributeName * ?? * @return ? */ public void setAttributeValue(Element element, String attributeName, String attributeValue) { Attribute attribute = element.attribute(attributeName); attribute.setValue(attributeValue); }