List of usage examples for org.dom4j Element attributes
List<Attribute> attributes();
From source file:com.glaf.core.xml.XmlReader.java
License:Apache License
public SysDataTable getSysDataTable(java.io.InputStream inputStream) { SysDataTable dataTable = new SysDataTable(); SAXReader xmlReader = new SAXReader(); try {// w w w . j ava2s . co m Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); Element element = root.element("entity"); if (element != null) { dataTable.setServiceKey(element.attributeValue("name")); dataTable.setTablename(element.attributeValue("table")); dataTable.setTitle(element.attributeValue("title")); Element idElement = element.element("id"); if (idElement != null) { SysDataField idField = new SysDataField(); List<?> attrs = idElement.attributes(); if (attrs != null && !attrs.isEmpty()) { Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); Iterator<?> iter = attrs.iterator(); while (iter.hasNext()) { Attribute attr = (Attribute) iter.next(); dataMap.put(attr.getName(), attr.getStringValue()); } Tools.populate(idField, dataMap); } idField.setPrimaryKey("Y"); idField.setName(idElement.attributeValue("name")); idField.setColumnName(idElement.attributeValue("column")); idField.setTitle(idElement.attributeValue("title")); idField.setDataType(idElement.attributeValue("type")); dataTable.addField(idField); } List<?> props = element.elements("property"); if (props != null && props.size() > 0) { Iterator<?> iterator = props.iterator(); while (iterator.hasNext()) { Element elem = (Element) iterator.next(); SysDataField field = new SysDataField(); List<?> attrs = elem.attributes(); if (attrs != null && !attrs.isEmpty()) { Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); Iterator<?> iter = attrs.iterator(); while (iter.hasNext()) { Attribute attr = (Attribute) iter.next(); dataMap.put(attr.getName(), attr.getStringValue()); } Tools.populate(field, dataMap); } field.setName(elem.attributeValue("name")); field.setColumnName(elem.attributeValue("column")); field.setTitle(elem.attributeValue("title")); field.setDataType(elem.attributeValue("type")); dataTable.addField(field); } } } } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } return dataTable; }
From source file:com.glaf.core.xml.XmlReader.java
License:Apache License
protected void read(Element elem, ColumnDefinition field) { List<?> attrs = elem.attributes(); if (attrs != null && !attrs.isEmpty()) { Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); Iterator<?> iter = attrs.iterator(); while (iter.hasNext()) { Attribute attr = (Attribute) iter.next(); dataMap.put(attr.getName(), attr.getStringValue()); }/* w ww .j a v a 2s . c o m*/ Tools.populate(field, dataMap); } field.setName(elem.attributeValue("name")); field.setMask(elem.attributeValue("mask")); field.setTitle(elem.attributeValue("title")); field.setEnglishTitle(elem.attributeValue("englishTitle")); field.setType(elem.attributeValue("type")); field.setDataCode(elem.attributeValue("dataCode")); field.setRenderType(elem.attributeValue("renderType")); field.setColumnName(elem.attributeValue("column")); field.setDataType(FieldType.getFieldType(field.getType())); String length = elem.attributeValue("length"); if (StringUtils.isNumeric(length)) { field.setLength(Integer.valueOf(length)); } String maxLength = elem.attributeValue("maxLength"); if (StringUtils.isNumeric(maxLength)) { field.setMaxLength(Integer.valueOf(maxLength)); } String minLength = elem.attributeValue("minLength"); if (StringUtils.isNumeric(minLength)) { field.setMinLength(Integer.valueOf(minLength)); } String displayType = elem.attributeValue("displayType"); if (StringUtils.isNumeric(displayType)) { field.setDisplayType(Integer.valueOf(displayType)); } String sortNo = elem.attributeValue("sortNo"); if (StringUtils.isNumeric(sortNo)) { field.setSortNo(Integer.valueOf(sortNo)); } if (StringUtils.equals(elem.attributeValue("updatable"), "false")) { field.setUpdatable(false); } if (StringUtils.equals(elem.attributeValue("nullable"), "false")) { field.setNullable(false); } if (StringUtils.equals(elem.attributeValue("editable"), "true")) { field.setEditable(true); } if (StringUtils.equals(elem.attributeValue("searchable"), "true")) { field.setSearchable(true); } }
From source file:com.glaf.core.xml.XmlReader.java
License:Apache License
public TableDefinition read(java.io.InputStream inputStream) { TableDefinition tableDefinition = new TableDefinition(); SAXReader xmlReader = new SAXReader(); try {//from ww w. j a v a2s .co m Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); Element element = root.element("entity"); if (element != null) { List<?> attrs = element.attributes(); if (attrs != null && !attrs.isEmpty()) { Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); Iterator<?> iter = attrs.iterator(); while (iter.hasNext()) { Attribute attr = (Attribute) iter.next(); dataMap.put(attr.getName(), attr.getStringValue()); } Tools.populate(tableDefinition, dataMap); } tableDefinition.setEntityName(element.attributeValue("name")); tableDefinition.setPackageName(element.attributeValue("package")); tableDefinition.setTableName(element.attributeValue("table")); tableDefinition.setTitle(element.attributeValue("title")); tableDefinition.setEnglishTitle(element.attributeValue("englishTitle")); if (StringUtils.equals("true", element.attributeValue("jbpmSupport"))) { tableDefinition.setJbpmSupport(true); } if (StringUtils.equals("true", element.attributeValue("treeSupport"))) { tableDefinition.setTreeSupport(true); } tableDefinition.setAggregationKeys(element.attributeValue("aggregationKeys")); tableDefinition.setModuleName(element.attributeValue("moduleName")); String primaryKey = element.attributeValue("primaryKey"); List<?> rows = element.elements("property"); if (rows != null && rows.size() > 0) { Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element elem = (Element) iterator.next(); ColumnDefinition field = new ColumnDefinition(); this.read(elem, field); if (primaryKey != null && StringUtils.equals(primaryKey, field.getColumnName())) { tableDefinition.setIdColumn(field); } else { tableDefinition.addColumn(field); } } } Element idElem = element.element("id"); if (idElem != null) { ColumnDefinition idField = new ColumnDefinition(); this.read(idElem, idField); tableDefinition.setIdColumn(idField); } } } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } return tableDefinition; }
From source file:com.glaf.dts.util.XmlReader.java
License:Apache License
public DataTransfer read(java.io.InputStream inputStream) { DataTransfer tableModel = new DataTransfer(); SAXReader xmlReader = new SAXReader(); try {// ww w . java 2s .c o m Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); Element element = root.element("entity"); if (element != null) { List<?> attrs = element.attributes(); if (attrs != null && !attrs.isEmpty()) { Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); Iterator<?> iter = attrs.iterator(); while (iter.hasNext()) { Attribute attr = (Attribute) iter.next(); dataMap.put(attr.getName(), attr.getStringValue()); tableModel.addProperty(attr.getName(), attr.getStringValue()); } Tools.populate(tableModel, dataMap); } tableModel.setEntityName(element.attributeValue("name")); tableModel.setPrimaryKey(element.attributeValue("primaryKey")); tableModel.setTableName(element.attributeValue("table")); tableModel.setTitle(element.attributeValue("title")); tableModel.setStopWord(element.attributeValue("stopWord")); tableModel.setPackageName(element.attributeValue("package")); tableModel.setEnglishTitle(element.attributeValue("englishTitle")); tableModel.setFilePrefix(element.attributeValue("filePrefix")); tableModel.setParseType(element.attributeValue("parseType")); tableModel.setParseClass(element.attributeValue("parseClass")); tableModel.setAggregationKeys(element.attributeValue("aggregationKeys")); tableModel.setSplit(element.attributeValue("split")); if (StringUtils.equals(element.attributeValue("insertOnly"), "true")) { tableModel.setInsertOnly("true"); } String startRow = element.attributeValue("startRow"); if (StringUtils.isNotEmpty(startRow) && StringUtils.isNumeric(startRow)) { tableModel.setStartRow(Integer.parseInt(startRow)); } String stopSkipRow = element.attributeValue("stopSkipRow"); if (StringUtils.isNotEmpty(stopSkipRow) && StringUtils.isNumeric(stopSkipRow)) { tableModel.setStopSkipRow(Integer.parseInt(stopSkipRow)); } String batchSize = element.attributeValue("batchSize"); if (StringUtils.isNotEmpty(batchSize) && StringUtils.isNumeric(batchSize)) { tableModel.setBatchSize(Integer.parseInt(batchSize)); } List<?> excludes = element.elements("excludes"); if (excludes != null && excludes.size() > 0) { Iterator<?> iterator = excludes.iterator(); while (iterator.hasNext()) { Element elem = (Element) iterator.next(); tableModel.addExclude(elem.getStringValue()); } } List<?> rows = element.elements("property"); if (rows != null && rows.size() > 0) { Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element elem = (Element) iterator.next(); ColumnDefinition field = new ColumnDefinition(); this.readField(elem, field); tableModel.addColumn(field); if (StringUtils.equalsIgnoreCase(tableModel.getPrimaryKey(), field.getColumnName())) { tableModel.setIdColumn(field); } } } } } catch (Exception ex) { throw new RuntimeException(ex); } return tableModel; }
From source file:com.glaf.dts.util.XmlReader.java
License:Apache License
protected void readField(Element elem, ColumnDefinition field) { List<?> attrs = elem.attributes(); if (attrs != null && !attrs.isEmpty()) { Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); Iterator<?> iter = attrs.iterator(); while (iter.hasNext()) { Attribute attr = (Attribute) iter.next(); dataMap.put(attr.getName(), attr.getStringValue()); field.addProperty(attr.getName(), attr.getStringValue()); }//from www .j av a 2 s . c o m Tools.populate(field, dataMap); } field.setName(elem.attributeValue("name")); field.setType(elem.attributeValue("type")); field.setColumnName(elem.attributeValue("column")); field.setTitle(elem.attributeValue("title")); field.setValueExpression(elem.attributeValue("valueExpression")); /** * */ if ("true".equals(elem.attributeValue("required"))) { field.setRequired(true); } String length = elem.attributeValue("length"); if (StringUtils.isNotEmpty(length) && StringUtils.isNumeric(length)) { field.setLength(Integer.parseInt(length)); } String nullable = elem.attributeValue("nullable"); if (StringUtils.isNotEmpty(nullable)) { if (StringUtils.equalsIgnoreCase(nullable, "true")) { field.setNullable(true); field.setNullableField("true"); } else { field.setNullable(false); field.setNullableField("false"); } } String position = elem.attributeValue("position"); if (StringUtils.isNotEmpty(position) && StringUtils.isNumeric(position)) { field.setPosition(Integer.parseInt(position)); } String precision = elem.attributeValue("precision"); if (StringUtils.isNotEmpty(precision) && StringUtils.isNumeric(precision)) { field.setPrecision(Integer.parseInt(precision)); } }
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 a va 2 s . c om 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.util.ttx.TtxToTmx.java
License:Apache License
/** * Creates new elements for TU and TUV with lowercase names by * constructing new elements and inserting them in place of the * old ones.// w ww . ja v a2s . c o m */ private Element lowercaseElements(Element p_tu) { Element tu = m_factory.createElement("tu"); tu.setAttributes(p_tu.attributes()); List tuvs = p_tu.selectNodes("//Tuv"); for (int i = 0, max = tuvs.size(); i < max; i++) { Element tuv = (Element) tuvs.get(i); // Detach the TUV or else TUVs will accumulate on // subsequent TUs (sic!). tuv.detach(); Element newTuv = m_factory.createElement("tuv"); newTuv.setAttributes(tuv.attributes()); newTuv.setContent(tuv.content()); tu.add(newTuv); } return tu; }
From source file:com.globalsight.everest.tm.util.ttx.TtxToTmx.java
License:Apache License
/** * Removes all non-standard UT attributes like `Type="start" * RightEdge="angle" DisplayText="font"' (= all of them, ut has no * attributes in TMX).//from w w w.j a v a 2 s . c om */ private void fixUtElements(Element p_tu) { ArrayList elems = new ArrayList(); findUtElements(elems, p_tu); for (int i = 0, max = elems.size(); i < max; i++) { Element elem = (Element) elems.get(i); elem.attributes().clear(); } }
From source file:com.globalsight.ling.docproc.worldserver.WsSkeletonDispose.java
License:Apache License
@Override public String dealSkeleton(String skeleton, String localizedBy) { boolean localizedByUser = false; boolean localizedByMT = false; boolean localizedByLocalTM = false; if (localizedBy != null && localizedBy.equals(PageTemplate.byUser)) { localizedByUser = true;/* ww w .j ava2 s .co m*/ } else if (localizedBy != null && localizedBy.equals(PageTemplate.byMT)) { localizedByMT = true; } else if (localizedBy != null && localizedBy.equals(PageTemplate.byLocalTM)) { localizedByLocalTM = true; } int begin = skeleton.indexOf("<" + IWS_SEGMENT_DATA); int end = skeleton.indexOf("</" + IWS_SEGMENT_DATA) + ("</" + IWS_SEGMENT_DATA + ">").length(); String iwsStr = skeleton.substring(begin, end); iwsStr = "<segmentdata " + "xmlns:iws=\"http://www.idiominc.com/ws/asset\">" + iwsStr + "</segmentdata>"; Document dom = getDom(iwsStr); Element root = dom.getRootElement(); List iwsStatusList = root.selectNodes("//iws:status"); for (int x = 0; x < iwsStatusList.size(); x++) { Element status = (Element) iwsStatusList.get(x); if (localizedByUser || localizedByLocalTM || localizedByMT) { /* * if (status.attribute("match-quality") != null) * status.remove(status.attribute("match-quality")); * * if (status.attribute("source_content") != null) * status.remove(status.attribute("source_content")); * * if (status.attribute("target_content") != null) * status.remove(status.attribute("target_content")); */ List<Attribute> attrList = new ArrayList(); attrList.addAll(status.attributes()); for (int i = 0; i < attrList.size(); i++) { String name = attrList.get(i).getName(); if (!name.equals(IWS_TRANSLATION_STATUS) && !name.equals(IWS_TRANSLATION_TYPE) && !name.equals(IWS_SOURCE_CONTENT)) { status.remove(attrList.get(i)); } } } if (status.attribute(IWS_TRANSLATION_STATUS) != null) { if (localizedByUser) { status.attribute(IWS_TRANSLATION_STATUS).setValue("finished"); } else if (localizedByLocalTM) { status.attribute(IWS_TRANSLATION_STATUS).setValue("pending"); } } else { if (localizedByUser) { status.addAttribute(IWS_TRANSLATION_STATUS, "finished"); } else if (localizedByLocalTM) { status.addAttribute(IWS_TRANSLATION_STATUS, "pending"); } } if (status.attribute(IWS_TRANSLATION_TYPE) != null) { if (localizedByMT) { status.attribute(IWS_TRANSLATION_TYPE).setValue("machine_translation_mt"); } else if (localizedByUser || localizedByLocalTM) { status.attribute(IWS_TRANSLATION_TYPE).setValue("manual_translation"); } } else { if (localizedBy != null) { if (localizedByMT) { status.addAttribute(IWS_TRANSLATION_TYPE, "machine_translation_mt"); } else if (localizedByUser || localizedByLocalTM) { status.addAttribute(IWS_TRANSLATION_TYPE, "manual_translation"); } } } } iwsStr = dom.selectSingleNode("//iws:segment-metadata").asXML(); String str = "xmlns:iws=\"http://www.idiominc.com/ws/asset\""; iwsStr = iwsStr.replace(str, ""); skeleton = skeleton.substring(0, begin) + iwsStr + skeleton.substring(end); return skeleton; }
From source file:com.haulmont.bali.util.Dom4j.java
License:Apache License
@SuppressWarnings("unchecked") public static List<Attribute> attributes(Element element) { return element.attributes(); }