use of com.revolsys.collection.map.NamedLinkedHashMapEx in project com.revolsys.open by revolsys.
the class XmlMapIterator method readMap.
@SuppressWarnings("unchecked")
private MapEx readMap() {
final String name = this.in.getLocalName();
final MapEx map = new NamedLinkedHashMapEx(name);
int textIndex = 0;
while (this.in.next() != XMLStreamConstants.END_ELEMENT) {
switch(this.in.getEventType()) {
case XMLStreamConstants.CDATA:
case XMLStreamConstants.CHARACTERS:
final String text = this.in.getText();
if (Property.hasValue(text)) {
map.put("xmlText" + ++textIndex, text);
}
break;
case XMLStreamConstants.SPACE:
break;
case XMLStreamConstants.START_ELEMENT:
final String tagName = this.in.getLocalName();
final Object value = readElement();
final Object oldValue = map.get(tagName);
if (oldValue == null) {
map.put(tagName, value);
} else {
List<Object> list;
if (oldValue instanceof List) {
list = (List<Object>) oldValue;
} else {
list = new ArrayList<>();
list.add(oldValue);
map.put(tagName, list);
}
list.add(value);
}
break;
default:
break;
}
}
return map;
}
use of com.revolsys.collection.map.NamedLinkedHashMapEx in project com.revolsys.open by revolsys.
the class XmlMapIterator method readElement.
@SuppressWarnings("unchecked")
private Object readElement() {
final String name = this.in.getLocalName();
final MapEx map = new NamedLinkedHashMapEx(name);
int textIndex = 0;
int elementIndex = 0;
while (this.in.next() != XMLStreamConstants.END_ELEMENT) {
switch(this.in.getEventType()) {
case XMLStreamConstants.CDATA:
case XMLStreamConstants.CHARACTERS:
final String text = this.in.getText();
if (Property.hasValue(text)) {
map.put("xmlText" + ++textIndex, text);
}
break;
case XMLStreamConstants.SPACE:
break;
case XMLStreamConstants.START_ELEMENT:
elementIndex++;
final String tagName = this.in.getLocalName();
final Object value = readElement();
final Object oldValue = map.get(tagName);
if (oldValue == null) {
map.put(tagName, value);
} else {
List<Object> list;
if (oldValue instanceof List) {
list = (List<Object>) oldValue;
} else {
list = new ArrayList<>();
list.add(oldValue);
map.put(tagName, list);
}
list.add(value);
}
break;
case XMLStreamConstants.COMMENT:
break;
default:
System.err.println(this.in.getEventType() + " " + this.in.getText());
break;
}
}
if (elementIndex == 0) {
if (textIndex > 0) {
final StringBuilder fullText = new StringBuilder();
for (final Object text : map.values()) {
fullText.append(text);
}
return fullText.toString();
}
}
return map;
}
use of com.revolsys.collection.map.NamedLinkedHashMapEx in project com.revolsys.open by revolsys.
the class PageInfoHttpMessageConverter method getMap.
private Map<String, Object> getMap(final String url, final PageInfo pageInfo) {
final MapEx pageMap = new NamedLinkedHashMapEx("resource");
pageMap.put("resourceUri", url);
pageMap.put("title", pageInfo.getTitle());
final String description = pageInfo.getDescription();
if (Property.hasValue(description)) {
pageMap.put("description", description);
}
for (final Entry<String, Object> attribute : pageInfo.getFields().entrySet()) {
final String key = attribute.getKey();
final Object value = attribute.getValue();
pageMap.put(key, value);
}
final List<Map<String, Object>> childPages = new ArrayList<>();
for (final Entry<String, PageInfo> childPage : pageInfo.getPages().entrySet()) {
final String childPath = childPage.getKey();
final PageInfo childPageInfo = childPage.getValue();
final String childUri = getUrl(url, childPath);
final Map<String, Object> childPageMap = getMap(childUri, childPageInfo);
childPages.add(childPageMap);
}
if (!childPages.isEmpty()) {
pageMap.put("resources", childPages);
}
return pageMap;
}