Search in sources :

Example 1 with NamedLinkedHashMapEx

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;
}
Also used : NamedLinkedHashMapEx(com.revolsys.collection.map.NamedLinkedHashMapEx) NamedLinkedHashMapEx(com.revolsys.collection.map.NamedLinkedHashMapEx) MapEx(com.revolsys.collection.map.MapEx) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with NamedLinkedHashMapEx

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;
}
Also used : NamedLinkedHashMapEx(com.revolsys.collection.map.NamedLinkedHashMapEx) NamedLinkedHashMapEx(com.revolsys.collection.map.NamedLinkedHashMapEx) MapEx(com.revolsys.collection.map.MapEx) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with NamedLinkedHashMapEx

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;
}
Also used : NamedLinkedHashMapEx(com.revolsys.collection.map.NamedLinkedHashMapEx) PageInfo(com.revolsys.ui.model.PageInfo) NamedLinkedHashMapEx(com.revolsys.collection.map.NamedLinkedHashMapEx) MapEx(com.revolsys.collection.map.MapEx) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MapEx (com.revolsys.collection.map.MapEx)3 NamedLinkedHashMapEx (com.revolsys.collection.map.NamedLinkedHashMapEx)3 ArrayList (java.util.ArrayList)3 List (java.util.List)2 PageInfo (com.revolsys.ui.model.PageInfo)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1