Example usage for org.apache.wicket.markup.parser XmlTag getLength

List of usage examples for org.apache.wicket.markup.parser XmlTag getLength

Introduction

In this page you can find the example usage for org.apache.wicket.markup.parser XmlTag getLength.

Prototype

public int getLength() 

Source Link

Document

Gets the length of the tag in characters.

Usage

From source file:org.wicketstuff.poi.excel.GeneralPurposeExporter.java

License:Apache License

public void exportCell(XmlTag tag, XmlPullParser parser, Cell cell, Component gridComponent)
        throws ParseException {
    XmlTag firstMostNestedTag = tag;
    // find the most inner tag value
    while ((tag = parser.nextTag()).getName().equals("td") == false) {
        if (tag.isOpen() || tag.isOpenClose()) {
            firstMostNestedTag = tag;//w  w  w  .  j av  a  2  s . c o m
        } else {
            break;
        }
    }
    CharSequence possibleComponentReference = firstMostNestedTag
            .getAttribute(TableParser.OutputPathBehavior.PATH_ATTRIBUTE);
    if (possibleComponentReference != null) {
        Component firstMostNestedComponent = gridComponent.getPage().get(possibleComponentReference.toString());
        // exclude auto links
        if (firstMostNestedComponent.getClass().getName().contains("ResourceReferenceAutolink")) {
            cell.setCellValue("");
            return;
        }
        // handle links
        if (firstMostNestedComponent instanceof Link) {
            Link<?> link = (Link<?>) firstMostNestedComponent;
            firstMostNestedComponent = getLinkInnerComponent(link);
            if (firstMostNestedComponent == null) {
                cell.setCellValue("");
                return;
            }
        }
        Object modelValue = firstMostNestedComponent.getDefaultModelObject();
        if (modelValue != null) {
            if (modelValue instanceof Number) {
                handleNumber(cell, (Number) modelValue);
            } else if (modelValue instanceof CharSequence) {
                cell.setCellValue(modelValue.toString());
            } else if (modelValue instanceof CharSequence) {
                cell.setCellValue(modelValue.toString());
            } else if (modelValue instanceof Boolean) {
                cell.setCellValue((Boolean) modelValue);
            } else if (modelValue instanceof Calendar) {
                handleCalendar(cell, (Calendar) modelValue);
            } else if (modelValue instanceof Date) {
                handleDate(cell, (Date) modelValue);
            } else {
                cell.setCellValue(modelValue.toString());
            }
        }
    } else {
        // simply set the first most nested tag value
        String value = parser
                .getInput(firstMostNestedTag.getPos() + firstMostNestedTag.getLength(), tag.getPos())
                .toString();
        cell.setCellValue(value);
    }
}