List of usage examples for org.dom4j Element attribute
Attribute attribute(QName qName);
From source file:gov.abrs.etms.tag.ProcessImageTag.java
License:Open Source License
private int[] extractBoxConstraint(Element root, Token token) { int[] result = new int[4]; String nodeName = token.getNode().getName(); XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']"); Element node = (Element) xPath.selectSingleNode(root); result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue(); result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue(); result[2] = Integer.valueOf(node.attribute("width").getValue()).intValue(); result[3] = Integer.valueOf(node.attribute("height").getValue()).intValue(); return result; }
From source file:gov.abrs.etms.tag.ProcessImageTag.java
License:Open Source License
private int[] extractImageDimension(Element root) { int[] result = new int[2]; result[0] = Integer.valueOf(root.attribute("width").getValue()).intValue(); result[1] = Integer.valueOf(root.attribute("height").getValue()).intValue(); return result; }
From source file:gov.guilin.util.SettingUtils.java
License:Open Source License
/** * /*from w w w . j a v a 2s . c om*/ * * @param setting * */ public static void set(Setting setting) { try { File guilinXmlFile = new ClassPathResource(CommonAttributes.XML_PATH).getFile(); Document document = new SAXReader().read(guilinXmlFile); List<Element> elements = document.selectNodes("/guilin/setting"); for (Element element : elements) { try { String name = element.attributeValue("name"); String value = beanUtils.getProperty(setting, name); Attribute attribute = element.attribute("value"); attribute.setValue(value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } FileOutputStream fileOutputStream = null; XMLWriter xmlWriter = null; try { OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding("UTF-8"); outputFormat.setIndent(true); outputFormat.setIndent(" "); outputFormat.setNewlines(true); fileOutputStream = new FileOutputStream(guilinXmlFile); xmlWriter = new XMLWriter(fileOutputStream, outputFormat); xmlWriter.write(document); } catch (Exception e) { e.printStackTrace(); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { } } IOUtils.closeQuietly(fileOutputStream); } Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME); cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting)); } catch (Exception e) { e.printStackTrace(); } }
From source file:gov.nih.nci.caarray.util.owlparser.AbstractOntologyOwlParser.java
License:BSD License
private String getIdentifier(Element e) { Attribute id = e.attribute(getIdAttributeName()); if (id != null) { return id.getValue(); }//w w w . j av a 2s. com Attribute about = e.attribute(getAboutAttributeName()); if (about != null) { return StringUtils.substringAfter(about.getValue(), FRAGMENT_SEPARATOR); } Attribute resource = e.attribute(getResourceAttributeName()); if (resource != null) { return StringUtils.substringAfter(resource.getValue(), FRAGMENT_SEPARATOR); } return null; }
From source file:gov.nih.nci.grididloader.Config.java
License:BSD License
/** * Loads the entity mapping from an XML document DOM. * @throws Exception/*w w w .j a v a 2 s . c o m*/ */ public void loadXMLMapping(Document xmlMappingDoc) throws Exception { final Element mapping = xmlMappingDoc.getRootElement(); final String mappingPackage = mapping.attribute("package").getText(); // Damn you 1.4 iteration API! Iterator elementIterator = mapping.elementIterator(); Map<String, BigEntity> entityMap = new HashMap<String, BigEntity>(); // for each <entity> while (elementIterator.hasNext()) { final Element entityElement = (Element) elementIterator.next(); final String className = entityElement.attribute("class").getText(); final String tableName = entityElement.attribute("table").getText(); final boolean serial = (entityElement.attribute("parallel") != null) && "false".equals(entityElement.attribute("parallel").getText()); final String primaryKey = entityElement.element("primary-key").getText(); final Element logicalElement = entityElement.element("logical-key"); final Map<String, Join> joinMap = new HashMap<String, Join>(); final Collection<Join> joins = new ArrayList<Join>(); final List<String> attributeList = new ArrayList<String>(); // use the sb to create commaDelimitedFields final StringBuffer sb = new StringBuffer(tableName); sb.append("."); sb.append(primaryKey); // for each <property> final Iterator logicalIterator = logicalElement.elementIterator(); while (logicalIterator.hasNext()) { final Element propertyElement = (Element) logicalIterator.next(); final String attr = propertyElement.getText(); final Attribute foreignTableAttr = propertyElement.attribute("table"); final Attribute foreignEntityAttr = propertyElement.attribute("entity"); // comma before every logical key property sb.append(","); // foreign attribute? if (foreignTableAttr != null) { final String foreignKey = propertyElement.attribute("foreign-key").getText(); final String foreignTable = foreignTableAttr.getText(); final String foreignTablePK = propertyElement.attribute("primary-key").getText(); TableJoin join = null; // have we already seen this join on this foreign key? String key = foreignTable + "~" + foreignKey; if (joinMap.containsKey(key)) { join = (TableJoin) joinMap.get(key); } else { join = new TableJoin(foreignKey, foreignTable, foreignTablePK); joinMap.put(key, join); joins.add(join); } // add this attribute to the join join.addAttribute(attr); } // join to an entire entity else if (foreignEntityAttr != null) { final String foreignKey = propertyElement.attribute("foreign-key").getText(); final String foreignEntity = foreignEntityAttr.getText(); BigEntity joinEntity = entityMap.get(foreignEntity); if (joinEntity == null) { System.err.println("ERROR: Invalid reference to " + foreignEntity + " in " + className); } else { Join join = new EntityJoin(foreignKey, joinEntity); joins.add(join); } } // a regular attribute else { attributeList.add(attr); } } String[] attributes = new String[attributeList.size()]; attributeList.toArray(attributes); BigEntity entity = new BigEntity(tableName, mappingPackage, className, primaryKey, attributes, joins, !serial); entities.add(entity); entityMap.put(entity.getClassName(), entity); } }
From source file:gr.abiss.calipso.domain.Field.java
License:Open Source License
public Field(Element e) { setName(e.attributeValue(NAME));/*from w w w .java 2s . c o m*/ label = e.attributeValue(LABEL); this.groupId = e.attributeValue(GROUP_ID); //logger.info("loaded field "+this.getName().getText()+" with group id: "+this.groupId); // TODO: we can use the same way to add a PK for database records or // drop-down options fieldType = e.attributeValue(FIELDTYPE); validationExpressionId = NumberUtils.toLong(e.attributeValue(VALIDATIONEXPR)); if (e.attribute(OPTIONAL) != null) { optional = BooleanUtils.toBoolean(e.attributeValue(OPTIONAL)); } if (e.attribute(PRIORITY) != null) { priority = NumberUtils.toInt(e.attributeValue(PRIORITY)); } if (this.getName().isFreeText()) { if (e.attribute(MULTIVALUE) != null) { this.multivalue = BooleanUtils.toBoolean(e.attributeValue(MULTIVALUE)); } if (e.attribute(LINECOUNT) != null) { this.lineCount = Short.parseShort(e.attributeValue(LINECOUNT)); } } if (e.attribute(DEFAULT_VALUE) != null) { this.defaultValueExpression = e.attributeValue(DEFAULT_VALUE); } if (e.element("field-config") != null) { this.xmlConfig = FieldConfig.fromXML(e.element("field-config").asXML()); } // TODO: remove this, we should only load options from database instead of tree for (Object o : e.elements(OPTION)) { addOption((Element) o); } }
From source file:gr.abiss.calipso.domain.Metadata.java
License:Open Source License
@SuppressWarnings("unchecked") public void setXmlString(String xmlString) { //init();//from w w w. j a va2 s.c o m //logger.info("setXmlString: "+xmlString); if (xmlString == null) { return; } Document document = XmlUtils.parse(xmlString); // date formats for (Element e : (List<Element>) document.selectNodes(DATEFORMATS_XPATH)) { String dfKey = e.attribute(NAME).getValue(); String dfExpression = e.attribute(EXPRESSION).getValue(); this.dateFormats.put(dfKey, dfExpression); } // field groups fieldGroups.clear(); for (Element e : (List<Element>) document.selectNodes(FIELD_GROUP_XPATH)) { FieldGroup fieldGroup = new FieldGroup(e); fieldGroups.add(fieldGroup); fieldGroupsById.put(fieldGroup.getId(), fieldGroup); } if (fieldGroups.isEmpty()) { addDefaultFieldGroup(); } // sort by priority TreeSet<FieldGroup> fieldGroupSet = new TreeSet<FieldGroup>(); fieldGroupSet.addAll(fieldGroups); fieldGroups.clear(); fieldGroups.addAll(fieldGroupSet); if (logger.isDebugEnabled()) logger.debug("Loaded fieldGroups:" + fieldGroups); for (Element e : (List<Element>) document.selectNodes(FIELD_XPATH)) { Field field = new Field(e); fields.put(field.getName(), field); fieldsByLabel.put(field.getLabel(), field); // link to full field group object or // of default if none is set //logger.info("field name: "+field.getName().getText()+", group id: "+field.getGroupId()+", group: "+fieldGroupsById.get(field.getGroupId()).getName()); if (field.getGroupId() != null) { FieldGroup fieldGroup = fieldGroupsById.get(field.getGroupId()); if (fieldGroup == null) { logger.warn("Field belongs to undefined field-group element with id: " + field.getGroupId() + ", adding to default group"); fieldGroup = fieldGroupsById.get("default"); } else { fieldGroup.addField(field); } } else { // add field to default group if it does not // belong to any FieldGroup defaultFieldGroup = fieldGroups.get(0); field.setGroup(defaultFieldGroup); defaultFieldGroup.addField(field); } } for (Element e : (List<Element>) document.selectNodes(ROLE_XPATH)) { Role role = new Role(e); roles.put(role.getName(), role); } for (Element e : (List<Element>) document.selectNodes(STATE_XPATH)) { String key = e.attributeValue(STATUS); String value = e.attributeValue(LABEL); states.put(Integer.parseInt(key), value); statesByName.put(value, Integer.parseInt(key)); statesPlugins.put(Integer.parseInt(key), e.attributeValue(PLUGIN)); String sDurations = e.attributeValue(MAX_DURATION); if (StringUtils.isNotBlank(sDurations)) { maxDurations.put(Integer.parseInt(key), NumberUtils.createLong(sDurations)); } String asTypeId = e.attributeValue(ASSET_TYPE_ID); if (StringUtils.isNotBlank(asTypeId)) { assetTypeIdMap.put(Integer.parseInt(key), NumberUtils.createLong(asTypeId)); } String existingAssetTypeId = e.attributeValue(EXISTING_ASSET_TYPE_ID); if (StringUtils.isNotBlank(existingAssetTypeId)) { existingAssetTypeIdsMap.put(Integer.parseInt(key), NumberUtils.createLong(existingAssetTypeId)); } String existingAssetTypeMultiple = e.attributeValue(EXISTING_ASSET_TYPE_MULTIPLE); if (StringUtils.isNotBlank(existingAssetTypeMultiple)) { existingAssetTypeMultipleMap.put(Integer.parseInt(key), BooleanUtils.toBoolean(existingAssetTypeMultiple)); } } fieldOrder.clear(); for (Element e : (List<Element>) document.selectNodes(FIELD_ORDER_XPATH)) { String fieldName = e.attributeValue(NAME); fieldOrder.add(Field.convertToName(fieldName)); } }
From source file:hello.SampleSimpleApplication.java
License:Apache License
private void changeImgUrl(Element autoTileElement) { List<Element> selectNodes = autoTileElement.selectNodes(".//img"); for (Element bagroundImage : selectNodes) { Attribute srcImg = bagroundImage.attribute("src"); if (!srcImg.getValue().contains(domain)) srcImg.setValue(domain + "/" + srcImg.getValue()); }//from ww w . jav a2s.c om // Element bagroundImage = (Element) autoTileElement.selectSingleNode("img[1]"); }
From source file:hello.SampleSimpleApplication.java
License:Apache License
private void addBreadcrumbItem(Element bookmarkElement, Element h3El) { List<Element> selectChildNodes = bookmarkElement.selectNodes("*"); if (selectChildNodes.size() > 0) { Element lastElement = selectChildNodes.get(selectChildNodes.size() - 1); if (bookmarkElement.attribute("hasLink") == null) { addInnerAnchor(h3El, bookmarkElement); } else {/*from w w w . j ava 2s . c o m*/ h3El.addElement("span").addText(" > " + bookmarkElement.attributeValue("name")); } addBreadcrumbItem(lastElement, h3El); } else {//last in bookmark tree (null child) addInnerAnchor(h3El, bookmarkElement); } }
From source file:hello.SampleSimpleApplication.java
License:Apache License
private void addInnerAnchor(Element h3El, Element bookmarkElement) { String text = bookmarkElement.attributeValue("name"); String bookmarkId = bookmarkElement.attribute("href").getValue().substring(1); h3El.addElement("a").addAttribute("name", bookmarkId).addText(" > " + text); bookmarkElement.addAttribute("hasLink", "1"); }