List of usage examples for org.dom4j Attribute getValue
String getValue();
From source file:com.globalsight.terminology.importer.MtfReaderThread.java
License:Apache License
/** * Converts a MultiTerm MTF concept group to a GlobalSight concept * group. Differences:/*from w w w . j a v a 2 s. c om*/ * * - <system type="entryClass|status"> --> * <descrip type="entryClass|status"> * * - <language type="English" lang="EN" /> --> * <language name="English" locale="en_US" /> * * - <descripGrp><descrip type="note"> --> * <noteGrp><note> * * - <descripGrp><descrip type="source"> --> * <sourceGrp><source> * * - descripGrp is recursive, must map to noteGrps or delete. * * - remove empty descripGrp <descrip type="Graphic"/> */ private Element convertMtf(Element p_elem) { List nodes; Node node; Element elem; Iterator it; ListIterator lit; // fix <system> nodes = p_elem.elements("system"); for (it = nodes.iterator(); it.hasNext();) { elem = (Element) it.next(); p_elem.remove(elem); p_elem.addElement("descrip").addAttribute("type", elem.attributeValue("type")).addText(elem.getText()); } // fix Graphic; we cannot handle them, so remove them nodes = p_elem.selectNodes("descripGrp[descrip/@type='Graphic']"); for (it = nodes.iterator(); it.hasNext();) { elem = (Element) it.next(); p_elem.remove(elem); } // convert <descripGrp><descrip type="note"> to noteGrp nodes = p_elem.selectNodes(".//descripGrp[descrip/@type='note']"); for (it = nodes.iterator(); it.hasNext();) { elem = (Element) it.next(); convertToNoteGrp(elem); } // convert <descripGrp><descrip type="source"> to sourceGrp nodes = p_elem.selectNodes(".//descripGrp[descrip/@type='source']"); for (it = nodes.iterator(); it.hasNext();) { elem = (Element) it.next(); convertToSourceGrp(elem); } // Convert recursive descripGrps to noteGrps if possible. convertRecursiveDescripGrps(p_elem, ".//conceptGrp/descripGrp"); convertRecursiveDescripGrps(p_elem, ".//languageGrp/descripGrp"); convertRecursiveDescripGrps(p_elem, ".//termGrp/descripGrp"); // Remove the recursive descripGrps that are left over. // (In case there are doubly recursive descrips and stuff.) removeRecursiveDescripGrps(p_elem); // fix <language> nodes = p_elem.selectNodes("languageGrp/language"); for (it = nodes.iterator(); it.hasNext();) { elem = (Element) it.next(); Attribute nameAttr = elem.attribute("type"); Attribute langAttr = elem.attribute("lang"); String langName = nameAttr.getValue(); String langLocale = langAttr.getValue(); // locales in entries consist of 2 letter codes. langLocale = langLocale.substring(0, 2).toLowerCase(); elem.remove(nameAttr); elem.remove(langAttr); elem.addAttribute("name", langName); elem.addAttribute("locale", langLocale); } return p_elem; }
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 ww .j a v a 2s . 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.core.global.filter.FilterParser.java
License:Apache License
protected Condition createCondition(Element conditionElement) { Condition condition;/*from w ww . j a v a 2 s . c om*/ String conditionName; if (conditionElement.attributeValue("locCaption") == null) { conditionName = conditionElement.attributeValue("name"); } else { conditionName = conditionElement.attributeValue("locCaption"); } if ("c".equals(conditionElement.getName())) { condition = new Clause(conditionName, conditionElement.getText(), getJoinValue(conditionElement), conditionElement.attributeValue("operatorType"), conditionElement.attributeValue("type")); // support unary conditions without parameters in text (e.g. "is null") for (Element paramElem : Dom4j.elements(conditionElement, "param")) { Set<ParameterInfo> params = ParametersHelper.parseQuery(":" + paramElem.attributeValue("name")); Attribute javaClass = paramElem.attribute("javaClass"); if (javaClass != null) { for (ParameterInfo param : params) { try { param.setJavaClass(Class.forName(javaClass.getValue())); param.setConditionName(conditionName); param.setValue(paramElem.getText()); } catch (ClassNotFoundException e) { //do not fail } if (condition.getParameters().contains(param)) { for (ParameterInfo parameterInfo : condition.getParameters()) { if (parameterInfo.equals(param)) { parameterInfo.setJavaClass(param.getJavaClass()); parameterInfo.setConditionName(param.getConditionName()); parameterInfo.setValue(param.getValue()); } } } } } condition.getParameters().addAll(params); } } else { condition = new LogicalCondition(conditionName, LogicalOp.fromString(conditionElement.getName())); } return condition; }
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 .j a v a 2s.c om 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.gui.xml.layout.loaders.AbstractComponentLoader.java
License:Apache License
protected void loadActionConstraint(Action action, Element element) { if (action instanceof Action.HasSecurityConstraint) { Action.HasSecurityConstraint itemTrackingAction = (Action.HasSecurityConstraint) action; Attribute operationTypeAttribute = element.attribute("constraintOperationType"); if (operationTypeAttribute != null) { ConstraintOperationType operationType = ConstraintOperationType .fromId(operationTypeAttribute.getValue()); itemTrackingAction.setConstraintOperationType(operationType); }//from w w w . j a v a 2 s . c o m String constraintCode = element.attributeValue("constraintCode"); itemTrackingAction.setConstraintCode(constraintCode); } }
From source file:com.haulmont.cuba.gui.xml.XmlInheritanceProcessor.java
License:Apache License
private void process(Element resultElem, Element extElem) { // set text//from www .j a v a 2 s. c om if (!StringUtils.isBlank(extElem.getText())) resultElem.setText(extElem.getText()); // add all attributes from extension for (Attribute attribute : Dom4j.attributes(extElem)) { if (resultElem == document.getRootElement() && attribute.getName().equals("extends")) { // ignore "extends" in root element continue; } resultElem.addAttribute(attribute.getName(), attribute.getValue()); } String idx = extElem.attributeValue(new QName("index", extNs)); if (resultElem != document.getRootElement() && StringUtils.isNotBlank(idx)) { int index = Integer.parseInt(idx); Element parent = resultElem.getParent(); if (index < 0 || index > parent.elements().size()) { String message = String.format( "Incorrect extension XML for screen. Could not move existing element %s to position %s", resultElem.getName(), index); throw new DevelopmentException(message, ParamsMap.of("element", resultElem.getName(), "index", index)); } parent.remove(resultElem); //noinspection unchecked parent.elements().add(index, resultElem); } // add and process elements Set<Element> justAdded = new HashSet<>(); for (Element element : Dom4j.elements(extElem)) { // look for suitable locator ElementTargetLocator locator = null; for (ElementTargetLocator l : targetLocators) { if (l.suitableFor(element)) { locator = l; break; } } if (locator != null) { Element target = locator.locate(resultElem, element); // process target or a new element if target not found if (target != null) { process(target, element); } else { addNewElement(resultElem, element, justAdded); } } else { // if no suitable locator found, look for a single element with the same name List<Element> list = Dom4j.elements(resultElem, element.getName()); if (list.size() == 1 && !justAdded.contains(list.get(0))) { process(list.get(0), element); } else { addNewElement(resultElem, element, justAdded); } } } }
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 ww w .ja v a2s. co m*/ 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 w w w .j a va 2 s. c o m * * @param element * * @param attributeName * ?? * @return */ public String getAttributeValue(Element element, String attributeName) { Attribute Attribute = element.attribute(attributeName); String attributeValue = Attribute.getValue(); return attributeValue; }
From source file:com.hihframework.osplugins.dom4j.XmlParseUtil.java
License:Apache License
/** * ??//from w w w. jav a2s . com * * @param element * * @return */ public HashMap<String, String> attributeMap(Element element) { HashMap<String, String> attributeHah = new HashMap<String, String>(); Iterator<?> elemIterator = element.attributeIterator(); while (elemIterator.hasNext()) { Attribute attribute = (Attribute) elemIterator.next(); String attributeName = attribute.getName(); String attributeValue = attribute.getValue(); attributeHah.put(attributeName, attributeValue); } return attributeHah; }
From source file:com.hyron.poscafe.util.ConfigurationWithWildcard.java
License:Open Source License
private void parseSessionFactory(Element sfNode, String name) { Iterator elements = sfNode.elementIterator(); while (elements.hasNext()) { Element subelement = (Element) elements.next(); String subelementName = subelement.getName(); if ("mapping".equals(subelementName)) { parseMappingElement(subelement, name); } else if ("class-cache".equals(subelementName)) { String className = subelement.attributeValue("class"); Attribute regionNode = subelement.attribute("region"); final String region = (regionNode == null) ? className : regionNode.getValue(); boolean includeLazy = !"non-lazy".equals(subelement.attributeValue("include")); setCacheConcurrencyStrategy(className, subelement.attributeValue("usage"), region, includeLazy); } else if ("collection-cache".equals(subelementName)) { String role = subelement.attributeValue("collection"); Attribute regionNode = subelement.attribute("region"); final String region = (regionNode == null) ? role : regionNode.getValue(); setCollectionCacheConcurrencyStrategy(role, subelement.attributeValue("usage"), region); } else if ("listener".equals(subelementName)) { parseListener(subelement);//w ww . java 2s .c o m } else if ("event".equals(subelementName)) { parseEvent(subelement); } } }