List of usage examples for org.dom4j.tree DefaultElement getText
public String getText()
From source file:com.celexus.conniption.foreman.util.XMLHandler.java
License:Apache License
@SuppressWarnings("unchecked") private Map<OrderField, String> getMarketOrderPaths(Document doc) { Map<OrderField, String> toReturn = new HashMap<OrderField, String>(); for (OrderField f : OrderField.values()) { String path = f.getPath(); if (path != null) { List<DefaultElement> list = doc.selectNodes(path); for (Iterator<DefaultElement> iter = list.iterator(); iter.hasNext();) { DefaultElement attribute = iter.next(); String url = attribute.getText(); toReturn.put(f, url);//from w w w .j a v a 2s .c om } } } return toReturn; }
From source file:com.celexus.conniption.foreman.util.XMLHandler.java
License:Apache License
@SuppressWarnings("unchecked") private Map<OrderPreviewField, String> getMarketPreviewOrderPaths(Document doc) throws UtilityException { Map<OrderPreviewField, String> toReturn = new HashMap<OrderPreviewField, String>(); for (OrderPreviewField f : OrderPreviewField.values()) { String path = f.getPath(); if (f.equals(OrderPreviewField.ERROR)) { if (path != null) { List<DefaultElement> list = doc.selectNodes(path); for (Iterator<DefaultElement> iter = list.iterator(); iter.hasNext();) { DefaultElement attribute = iter.next(); String url = attribute.getText(); throw new UtilityException(url); }/*from w w w. ja v a 2 s.c o m*/ } } if (path != null) { List<DefaultElement> list = doc.selectNodes(path); for (Iterator<DefaultElement> iter = list.iterator(); iter.hasNext();) { DefaultElement attribute = iter.next(); String url = attribute.getText(); toReturn.put(f, url); } } } return toReturn; }
From source file:com.celexus.conniption.foreman.util.XMLHandler.java
License:Apache License
@SuppressWarnings("unchecked") private Map<AccountsField, String> getAccountPaths(Document doc) throws UtilityException { Map<AccountsField, String> toReturn = new HashMap<AccountsField, String>(); for (AccountsField f : AccountsField.values()) { String path = f.getPath(); if (f.equals(AccountsField.ERROR)) { if (path != null) { List<DefaultElement> list = doc.selectNodes(path); for (Iterator<DefaultElement> iter = list.iterator(); iter.hasNext();) { DefaultElement attribute = iter.next(); String url = attribute.getText(); throw new UtilityException(url); }//from w ww . j av a 2 s. c o m } } if (path != null) { List<DefaultElement> list = doc.selectNodes(path); for (Iterator<DefaultElement> iter = list.iterator(); iter.hasNext();) { DefaultElement attribute = iter.next(); String url = attribute.getText(); toReturn.put(f, url); } } } return toReturn; }
From source file:com.celexus.conniption.foreman.util.XMLHandler.java
License:Apache License
@SuppressWarnings("unchecked") private Map<MarketQuotesResponseField, String> getMarketQuotePaths(Document doc) throws UtilityException { Map<MarketQuotesResponseField, String> toReturn = new HashMap<MarketQuotesResponseField, String>(); for (MarketQuotesResponseField f : MarketQuotesResponseField.values()) { String[] paths = f.getPaths(); if (f.equals(MarketQuotesResponseField.ERROR)) { if (paths != null) { for (String path : paths) { List<DefaultElement> list = doc.selectNodes(path); for (Iterator<DefaultElement> iter = list.iterator(); iter.hasNext();) { DefaultElement attribute = iter.next(); String url = attribute.getText(); throw new UtilityException(url); }/*from w w w. j av a2 s. c o m*/ } } } if (paths != null) { for (String path : paths) { List<DefaultElement> list = doc.selectNodes(path); for (Iterator<DefaultElement> iter = list.iterator(); iter.hasNext();) { DefaultElement attribute = iter.next(); String url = attribute.getText(); toReturn.put(f, url); } } } } return toReturn; }
From source file:com.celexus.conniption.foreman.util.XMLHandler.java
License:Apache License
@SuppressWarnings("unchecked") public Map<MarketClockField, String> getMarketClockPaths(Document doc) throws UtilityException { Map<MarketClockField, String> toReturn = new HashMap<MarketClockField, String>(); for (MarketClockField f : MarketClockField.values()) { String path = f.getPath(); if (f.equals(MarketClockField.ERROR)) { if (path != null) { List<DefaultElement> list = doc.selectNodes(path); for (Iterator<DefaultElement> iter = list.iterator(); iter.hasNext();) { DefaultElement attribute = iter.next(); String url = attribute.getText(); throw new UtilityException(url); }//from w w w. ja v a 2s . c o m } } if (path != null) { List<DefaultElement> list = doc.selectNodes(path); for (Iterator<DefaultElement> iter = list.iterator(); iter.hasNext();) { DefaultElement attribute = iter.next(); String url = attribute.getText(); toReturn.put(f, url); } } } return toReturn; }
From source file:org.nuxeo.ecm.platform.scanimporter.service.ScannedFileMapperComponent.java
License:Open Source License
@Override public ScanFileBlobHolder parseMetaData(File xmlFile) throws Exception { Map<String, Serializable> data = new HashMap<String, Serializable>(); if (mappingDesc == null) { return null; }//ww w . j a v a 2 s. c o m String xmlData = FileUtils.readFile(xmlFile); Document xmlDoc = DocumentHelper.parseText(xmlData); for (ScanFileFieldMapping fieldMap : mappingDesc.getFieldMappings()) { XPath xpath = new Dom4jXPath(fieldMap.getSourceXPath()); List<?> nodes = xpath.selectNodes(xmlDoc); if (nodes.size() == 1) { DefaultElement elem = (DefaultElement) nodes.get(0); String value = null; if ("TEXT".equals(fieldMap.getSourceAttribute())) { value = elem.getText(); } else { value = elem.attribute(fieldMap.getSourceAttribute()).getValue(); } String target = fieldMap.getTargetXPath(); if ("string".equalsIgnoreCase(fieldMap.getTargetType())) { data.put(target, value); continue; } else if ("integer".equalsIgnoreCase(fieldMap.getTargetType())) { data.put(target, Integer.parseInt(value)); continue; } else if ("double".equalsIgnoreCase(fieldMap.getTargetType())) { data.put(target, Double.parseDouble(value)); continue; } else if ("date".equalsIgnoreCase(fieldMap.getTargetType())) { data.put(target, fieldMap.getDateFormat().parse(value)); continue; } else if ("boolean".equalsIgnoreCase(fieldMap.getTargetType())) { data.put(target, Boolean.parseBoolean(value)); continue; } log.error("Unknown target type, please look the scan importer configuration: " + fieldMap.getTargetType()); } log.error("Mulliple or no element(s) found for: " + fieldMap.sourceXPath + " for " + xmlFile.getAbsolutePath()); } List<Blob> blobs = new ArrayList<Blob>(); for (ScanFileBlobMapping blobMap : mappingDesc.getBlobMappings()) { XPath xpath = new Dom4jXPath(blobMap.getSourceXPath()); List<?> nodes = xpath.selectNodes(xmlDoc); for (Object node : nodes) { DefaultElement elem = (DefaultElement) node; String filePath = elem.attributeValue(blobMap.getSourcePathAttribute()); String fileName = elem.attributeValue(blobMap.getSourceFilenameAttribute()); // Mainly for tests if (filePath.startsWith("$TMP")) { filePath = filePath.replace("$TMP", Framework.getProperty("nuxeo.import.tmpdir")); } File file = new File(filePath); if (file.exists()) { Blob blob = new FileBlob(file); if (fileName != null) { blob.setFilename(fileName); } else { blob.setFilename(file.getName()); } String target = blobMap.getTargetXPath(); if (target == null) { blobs.add(blob); } else { data.put(target, (Serializable) blob); } } else { log.error("File " + file.getAbsolutePath() + " is referenced by " + xmlFile.getAbsolutePath() + " but was not found"); } } } String targetType = getTargetLeafType(); DocumentTypeMapper mapper = mappingDesc.getTargetLeafTypeMapper(); if (mapper != null) { targetType = mapper.getTargetDocumentType(xmlDoc, xmlFile); } ScanFileBlobHolder bh = new ScanFileBlobHolder(blobs, data, targetType); return bh; }
From source file:org.nuxeo.ecm.platform.template.XMLSerializer.java
License:Open Source License
public static List<TemplateInput> readFromXml(String xml) throws Exception { List<TemplateInput> result = new ArrayList<TemplateInput>(); Document xmlDoc = DocumentHelper.parseText(xml); List nodes = xmlDoc.getRootElement().elements(fieldTag); for (Object node : nodes) { DefaultElement elem = (DefaultElement) node; Attribute name = elem.attribute("name"); TemplateInput param = new TemplateInput(name.getValue()); InputType type = InputType.StringValue; if (elem.attribute("type") != null) { type = InputType.getByValue(elem.attribute("type").getValue()); param.setType(type);//from ww w . j a v a 2 s. c o m } String strValue = elem.attributeValue("value"); if (InputType.StringValue.equals(type)) { param.setStringValue(strValue); } else if (InputType.DateValue.equals(type)) { param.setDateValue(dateFormat.parse(strValue)); } else if (InputType.BooleanValue.equals(type)) { param.setBooleanValue(new Boolean(strValue)); } else { param.setSource(elem.attributeValue("source")); } if (elem.attribute("readonly") != null) { param.setReadOnly(Boolean.parseBoolean(elem.attributeValue("readonly"))); } if (elem.attribute("autoloop") != null) { param.setAutoLoop(Boolean.parseBoolean(elem.attributeValue("autoloop"))); } param.setDesciption(elem.getText()); result.add(param); } return result; }
From source file:org.nuxeo.template.XMLSerializer.java
License:Open Source License
public static List<TemplateInput> readFromXml(String xml) throws Exception { List<TemplateInput> result = new ArrayList<TemplateInput>(); Document xmlDoc = DocumentHelper.parseText(xml); @SuppressWarnings("rawtypes") List nodes = xmlDoc.getRootElement().elements(fieldTag); for (Object node : nodes) { DefaultElement elem = (DefaultElement) node; Attribute name = elem.attribute("name"); TemplateInput param = new TemplateInput(name.getValue()); InputType type = InputType.StringValue; if (elem.attribute("type") != null) { type = InputType.getByValue(elem.attribute("type").getValue()); param.setType(type);/*from w w w . j a v a 2 s . co m*/ } String strValue = elem.attributeValue("value"); if (InputType.StringValue.equals(type)) { param.setStringValue(strValue); } else if (InputType.DateValue.equals(type)) { param.setDateValue(dateFormat.parse(strValue)); } else if (InputType.BooleanValue.equals(type)) { param.setBooleanValue(new Boolean(strValue)); } else { param.setSource(elem.attributeValue("source")); } if (elem.attribute("readonly") != null) { param.setReadOnly(Boolean.parseBoolean(elem.attributeValue("readonly"))); } if (elem.attribute("autoloop") != null) { param.setAutoLoop(Boolean.parseBoolean(elem.attributeValue("autoloop"))); } param.setDesciption(elem.getText()); result.add(param); } return result; }
From source file:org.olat.ims.cp.objects.CPItem.java
License:Apache License
/** * @see org.olat.ims.cp.objects.CPNode#buildChildren() *///from w ww. j ava 2 s . c o m @Override public void buildChildren() { final Iterator<DefaultElement> children = this.elementIterator(); // iterate through children while (children.hasNext()) { final DefaultElement child = children.next(); if (child.getName().equals(CPCore.ITEM)) { final CPItem item = new CPItem(child, this); item.buildChildren(); item.setPosition(items.size()); item.setParentElement(this); items.add(item); } else if (child.getName().equals(CPCore.TITLE)) { title = child.getText(); } else if (child.getName().equals(CPCore.METADATA)) { // TODO: implement LOM METADATA metadata = new CPMetadata(child); metadata.setParentElement(this); } } this.clearContent(); validateElement(); }
From source file:org.olat.ims.cp.objects.CPOrganization.java
License:Apache License
/** * @see org.olat.ims.cp.objects.CPNode#buildChildren() *///from w ww. j a va 2s. c o m @Override public void buildChildren() { final Iterator<DefaultElement> children = this.elementIterator(); // iterate through children while (children.hasNext()) { final DefaultElement child = children.next(); if (child.getName().equals(CPCore.ITEM)) { final CPItem item = new CPItem(child, this); item.setParentElement(this); item.buildChildren(); item.setPosition(items.size()); items.add(item); } else if (child.getName().equals(CPCore.TITLE)) { title = child.getText(); } else if (child.getName().equals(CPCore.METADATA)) { metadata = new CPMetadata(child); metadata.setParentElement(this); } else { errors.add("Invalid IMS-Manifest ( unallowed element under <organization> )"); } } this.clearContent(); validateElement(); }