Example usage for org.apache.poi.ss.usermodel Cell getRichStringCellValue

List of usage examples for org.apache.poi.ss.usermodel Cell getRichStringCellValue

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Cell getRichStringCellValue.

Prototype

RichTextString getRichStringCellValue();

Source Link

Document

Get the value of the cell as a XSSFRichTextString

For numeric cells we throw an exception.

Usage

From source file:org.databene.formats.xls.XLSUtil.java

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
private static Object convertString(Cell cell, String emptyMarker, String nullMarker,
        Converter<?, ?> stringPreprocessor) {
    String content = cell.getRichStringCellValue().getString();
    if (content != null) {
        if (content.equals(emptyMarker) || content.equals("'"))
            content = "";
        if (content.equals(nullMarker))
            content = null;/*from w w w .  j  a v a2  s.  c om*/
    }
    return (stringPreprocessor != null ? ((Converter) stringPreprocessor).convert(content) : content);
}

From source file:org.datanucleus.store.excel.ExcelUtils.java

License:Open Source License

/**
 * Convenience method to check if a cell value matches the provided value and type.
 * @param cell The cell/*from  w w  w.  ja  v  a  2 s. c o m*/
 * @param fieldType The type to compare it with
 * @param fieldValue The value of the type to compare it with (can be null)
 * @return Whether the cell matches
 */
protected static boolean cellMatches(Cell cell, Class fieldType, Object fieldValue) {
    if (cell == null) {
        return false;
    }

    if (String.class.isAssignableFrom(fieldType)
            && cell.getRichStringCellValue().getString().equals(fieldValue)) {
        return true;
    } else if ((fieldType == int.class || fieldType == Integer.class)
            && ((Integer) fieldValue).intValue() == (int) cell.getNumericCellValue()) {
        return true;
    } else if ((fieldType == long.class || fieldType == Long.class)
            && ((Long) fieldValue).longValue() == (long) cell.getNumericCellValue()) {
        return true;
    } else if ((fieldType == short.class || fieldType == Short.class)
            && ((Short) fieldValue).shortValue() == (short) cell.getNumericCellValue()) {
        return true;
    } else if ((fieldType == float.class || fieldType == Float.class)
            && ((Float) fieldValue).floatValue() == (float) cell.getNumericCellValue()) {
        return true;
    } else if ((fieldType == double.class || fieldType == Double.class)
            && ((Double) fieldValue).doubleValue() == cell.getNumericCellValue()) {
        return true;
    } else if ((fieldType == boolean.class || fieldType == Boolean.class)
            && ((Boolean) fieldValue).booleanValue() == cell.getBooleanCellValue()) {
        return true;
    } else if ((fieldType == byte.class || fieldType == Byte.class)
            && ((Byte) fieldValue).byteValue() == (byte) cell.getNumericCellValue()) {
        return true;
    } else if ((fieldType == char.class || fieldType == Character.class)
            && ((Character) fieldValue).charValue() == cell.getRichStringCellValue().getString().charAt(0)) {
        return true;
    } else if ((Date.class.isAssignableFrom(fieldType)
            && ((Date) fieldValue).getTime() == cell.getDateCellValue().getTime())) {
        return true;
    }
    return false;
}

From source file:org.datanucleus.store.excel.fieldmanager.FetchFieldManager.java

License:Open Source License

public char fetchCharField(int fieldNumber) {
    Cell cell = sheet.getRow(rowNumber).getCell(getColumnMapping(fieldNumber).getColumn(0).getPosition());
    if (cell == null) {
        return 0;
    }/*w  w w . ja  v a  2s  .co m*/
    return cell.getRichStringCellValue().getString().charAt(0);
}

From source file:org.datanucleus.store.excel.fieldmanager.FetchFieldManager.java

License:Open Source License

public String fetchStringField(int fieldNumber) {
    Cell cell = sheet.getRow(rowNumber).getCell(getColumnMapping(fieldNumber).getColumn(0).getPosition());
    if (cell == null) {
        return null;
    }/*w w  w  .ja  v  a 2  s .  co  m*/
    return cell.getRichStringCellValue().getString();
}

From source file:org.datanucleus.store.excel.fieldmanager.FetchFieldManager.java

License:Open Source License

protected Object fetchObjectFieldInternal(int fieldNumber, AbstractMemberMetaData mmd, ClassLoaderResolver clr,
        RelationType relationType) {
    MemberColumnMapping mapping = getColumnMapping(fieldNumber);

    if (relationType == RelationType.NONE) {
        Column col = mapping.getColumn(0);
        if (mapping.getTypeConverter() != null) {
            TypeConverter conv = mapping.getTypeConverter();
            if (mapping.getNumberOfColumns() == 1) {
                Cell cell = sheet.getRow(rowNumber)
                        .getCell(getColumnMapping(fieldNumber).getColumn(0).getPosition());
                if (cell == null) {
                    return null;
                }/* ww  w  . j av  a  2 s  . co  m*/

                Object value = null;
                Class datastoreType = TypeConverterHelper.getDatastoreTypeForTypeConverter(conv, mmd.getType());
                if (datastoreType == String.class) {
                    value = conv.toMemberType(cell.getRichStringCellValue().getString());
                } else if (Number.class.isAssignableFrom(datastoreType)) {
                    value = conv.toMemberType(cell.getNumericCellValue());
                } else if (Boolean.class.isAssignableFrom(datastoreType)) {
                    value = conv.toMemberType(cell.getBooleanCellValue());
                } else if (Date.class.isAssignableFrom(datastoreType)) {
                    value = conv.toMemberType(cell.getDateCellValue());
                } else {
                    NucleusLogger.DATASTORE_PERSIST.warn("TypeConverter for member " + mmd.getFullFieldName()
                            + " converts to " + datastoreType.getName() + " - not yet supported");
                }

                if (op != null) {
                    return SCOUtils.wrapSCOField(op, fieldNumber, value, true);
                }
                return value;
            }

            // Member stored in multiple columns and convertable using TypeConverter
            boolean isNull = true;
            Object valuesArr = null;
            Class[] colTypes = ((MultiColumnConverter) conv).getDatastoreColumnTypes();
            if (colTypes[0] == int.class) {
                valuesArr = new int[mapping.getNumberOfColumns()];
            } else if (colTypes[0] == long.class) {
                valuesArr = new long[mapping.getNumberOfColumns()];
            } else if (colTypes[0] == double.class) {
                valuesArr = new double[mapping.getNumberOfColumns()];
            } else if (colTypes[0] == float.class) {
                valuesArr = new double[mapping.getNumberOfColumns()];
            } else if (colTypes[0] == String.class) {
                valuesArr = new String[mapping.getNumberOfColumns()];
            }
            // TODO Support other types
            else {
                valuesArr = new Object[mapping.getNumberOfColumns()];
            }

            for (int i = 0; i < mapping.getNumberOfColumns(); i++) {
                Cell cell = sheet.getRow(rowNumber).getCell(mapping.getColumn(i).getPosition());
                if (cell == null) {
                    Array.set(valuesArr, i, null);
                } else {
                    isNull = false;
                    if (colTypes[i] == int.class) {
                        Object cellValue = getValueFromCellOfType(cell, Integer.class,
                                mapping.getColumn(i).getJdbcType());
                        Array.set(valuesArr, i, ((Integer) cellValue).intValue());
                    } else if (colTypes[i] == long.class) {
                        Object cellValue = getValueFromCellOfType(cell, Long.class,
                                mapping.getColumn(i).getJdbcType());
                        Array.set(valuesArr, i, ((Long) cellValue).longValue());
                    } else {
                        Object cellValue = getValueFromCellOfType(cell, colTypes[i],
                                mapping.getColumn(i).getJdbcType());
                        Array.set(valuesArr, i, cellValue);
                    }
                }
            }

            if (isNull) {
                return null;
            }

            Object memberValue = conv.toMemberType(valuesArr);
            if (op != null && memberValue != null) {
                memberValue = SCOUtils.wrapSCOField(op, fieldNumber, memberValue, true);
            }
            return memberValue;
        }

        Cell cell = sheet.getRow(rowNumber).getCell(mapping.getColumn(0).getPosition());
        if (cell == null) {
            return null;
        }

        Object value = getValueFromCellOfType(cell, mmd.getType(), col.getJdbcType());

        // Wrap the field if it is SCO
        if (op != null) {
            return SCOUtils.wrapSCOField(op, fieldNumber, value, true);
        }
        return value;
    } else if (RelationType.isRelationSingleValued(relationType)) {
        // Persistable object stored as String reference of the identity
        Cell cell = sheet.getRow(rowNumber).getCell(mapping.getColumn(0).getPosition());
        if (cell == null) {
            return null;
        }

        String idStr = cell.getRichStringCellValue().getString();
        if (idStr == null) {
            return null;
        }

        if (idStr.startsWith("[") && idStr.endsWith("]")) {
            idStr = idStr.substring(1, idStr.length() - 1);
            Object obj = null;
            AbstractClassMetaData memberCmd = ec.getMetaDataManager().getMetaDataForClass(mmd.getType(), clr);
            try {
                if (memberCmd.usesSingleFieldIdentityClass() && idStr.indexOf(':') > 0) {
                    // Uses persistent identity
                    obj = IdentityUtils.getObjectFromPersistableIdentity(idStr, memberCmd, ec);
                } else {
                    // Uses legacy identity
                    obj = IdentityUtils.getObjectFromIdString(idStr, memberCmd, ec, true);
                }
            } catch (NucleusObjectNotFoundException nfe) {
                NucleusLogger.GENERAL.warn("Object=" + op + " field=" + mmd.getFullFieldName() + " has id="
                        + idStr + " but could not instantiate object with that identity");
                return null;
            }
            return obj;
        }

        return null;
    } else if (RelationType.isRelationMultiValued(relationType)) {
        // Collection/Map/Array
        Cell cell = sheet.getRow(rowNumber).getCell(mapping.getColumn(0).getPosition());
        if (cell == null) {
            return null;
        }

        String cellStr = cell.getRichStringCellValue().getString();
        if (cellStr == null) {
            return null;
        }

        if (cellStr.startsWith("[") && cellStr.endsWith("]")) {
            cellStr = cellStr.substring(1, cellStr.length() - 1);
            String[] components = MetaDataUtils.getInstance().getValuesForCommaSeparatedAttribute(cellStr);
            if (Collection.class.isAssignableFrom(mmd.getType())) {
                Collection<Object> coll;
                try {
                    Class instanceType = SCOUtils.getContainerInstanceType(mmd.getType(),
                            mmd.getOrderMetaData() != null);
                    coll = (Collection<Object>) instanceType.newInstance();
                } catch (Exception e) {
                    throw new NucleusDataStoreException(e.getMessage(), e);
                }

                boolean changeDetected = false;
                if (components != null) {
                    AbstractClassMetaData elementCmd = mmd.getCollection()
                            .getElementClassMetaData(ec.getClassLoaderResolver(), ec.getMetaDataManager());
                    for (int i = 0; i < components.length; i++) {
                        // TODO handle Collection<interface>
                        Object element = null;
                        try {
                            if (elementCmd.usesSingleFieldIdentityClass() && components[i].indexOf(':') > 0) {
                                // Uses persistent identity
                                element = IdentityUtils.getObjectFromPersistableIdentity(components[i],
                                        elementCmd, ec);
                            } else {
                                // Uses legacy identity
                                element = IdentityUtils.getObjectFromIdString(components[i], elementCmd, ec,
                                        true);
                            }
                            coll.add(element);
                        } catch (NucleusObjectNotFoundException nfe) {
                            // Object no longer exists. Deleted by user? so ignore
                            changeDetected = true;
                        }
                    }
                }
                if (op != null) {
                    coll = (Collection) SCOUtils.wrapSCOField(op, fieldNumber, coll, true);
                    if (changeDetected) {
                        op.makeDirty(mmd.getAbsoluteFieldNumber());
                    }
                }
                return coll;
            } else if (Map.class.isAssignableFrom(mmd.getType())) {
                AbstractClassMetaData keyCmd = mmd.getMap().getKeyClassMetaData(clr, ec.getMetaDataManager());
                AbstractClassMetaData valCmd = mmd.getMap().getValueClassMetaData(clr, ec.getMetaDataManager());

                Map map;
                try {
                    Class instanceType = SCOUtils.getContainerInstanceType(mmd.getType(), false);
                    map = (Map) instanceType.newInstance();
                } catch (Exception e) {
                    throw new NucleusDataStoreException(e.getMessage(), e);
                }

                boolean changeDetected = false;
                if (components != null) {
                    for (int i = 0; i < components.length; i++) {
                        String keyCmpt = components[i];
                        i++;
                        String valCmpt = components[i];

                        // Strip square brackets from entry bounds
                        String keyStr = keyCmpt.substring(1, keyCmpt.length() - 1);
                        String valStr = valCmpt.substring(1, valCmpt.length() - 1);

                        boolean keySet = true;
                        boolean valSet = true;
                        Object key = null;
                        if (keyCmd != null) {
                            try {
                                // TODO handle Map<interface, ?>
                                if (keyCmd.usesSingleFieldIdentityClass() && keyStr.indexOf(':') > 0) {
                                    // Uses persistent identity
                                    key = IdentityUtils.getObjectFromPersistableIdentity(keyStr, keyCmd, ec);
                                } else {
                                    // Uses legacy identity
                                    key = IdentityUtils.getObjectFromIdString(keyStr, keyCmd, ec, true);
                                }
                            } catch (NucleusObjectNotFoundException nfe) {
                                // Object no longer exists. Deleted by user? so ignore
                                changeDetected = true;
                                keySet = false;
                            }
                        } else {
                            String keyTypeName = mmd.getMap().getKeyType();
                            Class keyType = ec.getClassLoaderResolver().classForName(keyTypeName);
                            if (Enum.class.isAssignableFrom(keyType)) {
                                key = Enum.valueOf(keyType, keyStr);
                            } else if (keyType == String.class) {
                                key = keyStr;
                            } else {
                                // TODO Support other map key types
                                throw new NucleusException(
                                        "Don't currently support retrieval of Maps with keys of type "
                                                + keyTypeName + " (field=" + mmd.getFullFieldName() + ")");
                            }
                        }

                        Object val = null;
                        if (valCmd != null) {
                            try {
                                // TODO handle Collection<?, interface>
                                if (valCmd.usesSingleFieldIdentityClass() && valStr.indexOf(':') > 0) {
                                    // Uses persistent identity
                                    val = IdentityUtils.getObjectFromPersistableIdentity(valStr, valCmd, ec);
                                } else {
                                    // Uses legacy identity
                                    val = IdentityUtils.getObjectFromIdString(valStr, valCmd, ec, true);
                                }
                            } catch (NucleusObjectNotFoundException nfe) {
                                // Object no longer exists. Deleted by user? so ignore
                                changeDetected = true;
                                valSet = false;
                            }
                        } else {
                            String valTypeName = mmd.getMap().getValueType();
                            Class valType = ec.getClassLoaderResolver().classForName(valTypeName);
                            if (Enum.class.isAssignableFrom(valType)) {
                                val = Enum.valueOf(valType, valStr);
                            } else if (valType == String.class) {
                                val = valStr;
                            } else {
                                // TODO Support other map value types
                                throw new NucleusException(
                                        "Don't currently support retrieval of Maps with values of type "
                                                + valTypeName + " (field=" + mmd.getFullFieldName() + ")");
                            }
                        }

                        if (keySet && valSet) {
                            map.put(key, val);
                        }
                    }
                }
                if (op != null) {
                    map = (Map) SCOUtils.wrapSCOField(op, fieldNumber, map, true);
                    if (changeDetected) {
                        op.makeDirty(mmd.getAbsoluteFieldNumber());
                    }
                }
                return map;
            } else if (mmd.getType().isArray()) {
                Object array = null;
                boolean changeDetected = false;
                int pos = 0;
                if (components != null) {
                    AbstractClassMetaData elementCmd = mmd.getCollection()
                            .getElementClassMetaData(ec.getClassLoaderResolver(), ec.getMetaDataManager());
                    array = Array.newInstance(mmd.getType().getComponentType(), components.length);
                    for (int i = 0; i < components.length; i++) {
                        // TODO handle interface[]
                        Object element = null;
                        try {
                            if (elementCmd.usesSingleFieldIdentityClass() && components[i].indexOf(':') > 0) {
                                // Uses persistent identity
                                element = IdentityUtils.getObjectFromPersistableIdentity(components[i],
                                        elementCmd, ec);
                            } else {
                                // Uses legacy identity
                                element = IdentityUtils.getObjectFromIdString(components[i], elementCmd, ec,
                                        true);
                            }
                            Array.set(array, pos++, element);
                        } catch (NucleusObjectNotFoundException nfe) {
                            // Object no longer exists. Deleted by user? so ignore
                            changeDetected = true;
                        }
                    }
                } else {
                    array = Array.newInstance(mmd.getType().getComponentType(), 0);
                }

                if (changeDetected) {
                    if (pos < Array.getLength(array)) {
                        // Some elements not found, so resize the array
                        Object arrayOld = array;
                        array = Array.newInstance(mmd.getType().getComponentType(), pos);
                        for (int j = 0; j < pos; j++) {
                            Array.set(array, j, Array.get(arrayOld, j));
                        }
                    }
                    if (op != null) {
                        array = SCOUtils.wrapSCOField(op, fieldNumber, array, true);
                        if (changeDetected) {
                            op.makeDirty(mmd.getAbsoluteFieldNumber());
                        }
                    }
                }
                return array;
            }
        }
    }
    throw new NucleusException("Dont currently support retrieval of type " + mmd.getTypeName());
}

From source file:org.datanucleus.store.excel.fieldmanager.FetchFieldManager.java

License:Open Source License

protected Object getValueFromCellOfType(Cell cell, Class requiredType, JdbcType jdbcType) {
    if (Date.class.isAssignableFrom(requiredType)) {
        Date date = cell.getDateCellValue();
        if (date == null) {
            return null;
        }/*from   w  w w  . ja va 2s  .  c om*/

        Object value = date;
        if (requiredType == java.sql.Date.class) {
            value = new java.sql.Date(date.getTime());
        } else if (requiredType == java.sql.Time.class) {
            value = new java.sql.Time(date.getTime());
        } else if (requiredType == java.sql.Timestamp.class) {
            value = new java.sql.Timestamp(date.getTime());
        }
        return value;
    } else if (Calendar.class.isAssignableFrom(requiredType)) {
        Date date = cell.getDateCellValue();
        if (date == null) {
            return null;
        }

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal;
    } else if (Boolean.class.isAssignableFrom(requiredType)) {
        boolean boolValue = cell.getBooleanCellValue();
        return Boolean.valueOf(boolValue);
    } else if (Character.class.isAssignableFrom(requiredType)) {
        String strValue = cell.getRichStringCellValue().getString();
        return Character.valueOf(strValue.charAt(0));
    } else if (Number.class.isAssignableFrom(requiredType)) {
        double val = cell.getNumericCellValue();
        if (Double.class.isAssignableFrom(requiredType)) {
            return Double.valueOf(val);
        } else if (Float.class.isAssignableFrom(requiredType)) {
            return Float.valueOf((float) val);
        } else if (Integer.class.isAssignableFrom(requiredType)) {
            return Integer.valueOf((int) val);
        } else if (Long.class.isAssignableFrom(requiredType)) {
            return Long.valueOf((long) val);
        } else if (Short.class.isAssignableFrom(requiredType)) {
            return Short.valueOf((short) val);
        } else if (Byte.class.isAssignableFrom(requiredType)) {
            return Byte.valueOf((byte) val);
        } else if (BigDecimal.class.isAssignableFrom(requiredType)) {
            return new BigDecimal(val);
        } else if (BigInteger.class.isAssignableFrom(requiredType)) {
            return new BigInteger("" + val);
        }
    } else if (Enum.class.isAssignableFrom(requiredType)) {
        if (MetaDataUtils.isJdbcTypeNumeric(jdbcType)) {
            double value = cell.getNumericCellValue();
            return requiredType.getEnumConstants()[(int) value];
        }

        String value = cell.getRichStringCellValue().getString();
        if (value != null && value.length() > 0) {
            return Enum.valueOf(requiredType, value);
        }

        return null;
    } else if (requiredType == byte[].class) {
        String value = cell.getStringCellValue();
        if (value != null) {
            return Base64.decode(value);
        }
    }

    // Fallback to String/Long TypeConverters
    if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
        TypeConverter longConv = ec.getNucleusContext().getTypeManager().getTypeConverterForType(requiredType,
                Long.class);
        return longConv.toMemberType((long) cell.getNumericCellValue());
    } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
        TypeConverter strConv = ec.getNucleusContext().getTypeManager().getTypeConverterForType(requiredType,
                String.class);
        String cellValue = (cell.getRichStringCellValue() != null ? cell.getRichStringCellValue().getString()
                : null);
        if (cellValue != null && cellValue.length() > 0) {
            return strConv.toMemberType(cell.getRichStringCellValue().getString());
        }
    }

    // Not supported as String so just set to null
    NucleusLogger.PERSISTENCE.warn("Field could not be set in the object since it is not persistable to Excel");
    return null;
}

From source file:org.datanucleus.store.excel.query.ExcelCandidateList.java

License:Open Source License

protected Object retrieveObjectForIndex(int index) {
    if (index < 0 || index >= getSize()) {
        throw new NoSuchElementException();
    }//from   w  ww.  ja  v  a  2s .  c om

    Iterator<AbstractClassMetaData> cmdIter = cmds.iterator();
    Iterator<Integer> numIter = numberInstancesPerClass.iterator();
    int first = 0;
    int last = -1;
    while (cmdIter.hasNext()) {
        final AbstractClassMetaData cmd = cmdIter.next();
        int number = numIter.next();
        last = first + number;

        if (index >= first && index < last) {
            // Object is of this candidate type, so find the object
            Table table = ec.getStoreManager().getStoreDataForClass(cmd.getFullClassName()).getTable();
            String sheetName = table.getName();
            Workbook workbook = (Workbook) mconn.getConnection();
            final Sheet worksheet = workbook.getSheet(sheetName);
            if (worksheet != null) {
                int idColIndex = -1;
                if (cmd.getIdentityType() == IdentityType.APPLICATION) {
                    int[] pkFieldNums = cmd.getPKMemberPositions(); // TODO Check all pk cols?
                    AbstractMemberMetaData pkMmd = cmd
                            .getMetaDataForManagedMemberAtAbsolutePosition(pkFieldNums[0]);
                    idColIndex = table.getMemberColumnMappingForMember(pkMmd).getColumn(0).getPosition();
                } else if (cmd.getIdentityType() == IdentityType.DATASTORE) {
                    idColIndex = table.getDatastoreIdColumn().getPosition();
                } else {
                    idColIndex = 0; // No id column with nondurable, so just take the first
                }

                int current = first;
                for (int i = worksheet.getFirstRowNum(); i <= worksheet.getLastRowNum(); i++) {
                    final Row row = worksheet.getRow(i);
                    if (row.getCell(idColIndex) != null) // Omit inactive rows
                    {
                        if (current == index) {
                            // This row equates to the required index
                            final int rowNumber = i;
                            if (cmd.getIdentityType() == IdentityType.APPLICATION) {
                                final FetchFieldManager fm = new FetchFieldManager(ec, cmd, worksheet,
                                        rowNumber, table);
                                Object id = IdentityUtils.getApplicationIdentityForResultSetRow(ec, cmd, null,
                                        false, fm);

                                return ec.findObject(id, new FieldValues() {
                                    // ObjectProvider calls the fetchFields method
                                    public void fetchFields(ObjectProvider op) {
                                        op.replaceFields(cmd.getAllMemberPositions(), fm);
                                    }

                                    public void fetchNonLoadedFields(ObjectProvider sm) {
                                        sm.replaceNonLoadedFields(cmd.getAllMemberPositions(), fm);
                                    }

                                    public FetchPlan getFetchPlanForLoading() {
                                        return null;
                                    }
                                }, null, ignoreCache, false);
                            } else if (cmd.getIdentityType() == IdentityType.DATASTORE) {
                                final FetchFieldManager fm = new FetchFieldManager(ec, cmd, worksheet,
                                        rowNumber, table);
                                Object id = null;
                                Cell idCell = row.getCell(idColIndex);
                                int type = idCell.getCellType();
                                if (type == Cell.CELL_TYPE_STRING) {
                                    String key = idCell.getRichStringCellValue().getString();
                                    id = ec.getNucleusContext().getIdentityManager()
                                            .getDatastoreId(cmd.getFullClassName(), key);
                                } else if (type == Cell.CELL_TYPE_NUMERIC) {
                                    long key = (long) idCell.getNumericCellValue();
                                    id = ec.getNucleusContext().getIdentityManager()
                                            .getDatastoreId(cmd.getFullClassName(), key);
                                }
                                return ec.findObject(id, new FieldValues() {
                                    // ObjectProvider calls the fetchFields method
                                    public void fetchFields(ObjectProvider op) {
                                        op.replaceFields(cmd.getAllMemberPositions(), fm);
                                    }

                                    public void fetchNonLoadedFields(ObjectProvider op) {
                                        op.replaceNonLoadedFields(cmd.getAllMemberPositions(), fm);
                                    }

                                    public FetchPlan getFetchPlanForLoading() {
                                        return null;
                                    }
                                }, null, ignoreCache, false);
                            } else {
                                // Nondurable identity
                                final FetchFieldManager fm = new FetchFieldManager(ec, cmd, worksheet,
                                        rowNumber, table);
                                Object id = new SCOID(cmd.getFullClassName());
                                return ec.findObject(id, new FieldValues() {
                                    // ObjectProvider calls the fetchFields method
                                    public void fetchFields(ObjectProvider op) {
                                        op.replaceFields(cmd.getAllMemberPositions(), fm);
                                    }

                                    public void fetchNonLoadedFields(ObjectProvider sm) {
                                        sm.replaceNonLoadedFields(cmd.getAllMemberPositions(), fm);
                                    }

                                    public FetchPlan getFetchPlanForLoading() {
                                        return null;
                                    }
                                }, null, ignoreCache, false);
                            }
                        }

                        current++;
                    }
                }
            }
        } else {
            first += number;
        }
    }

    return null;
}

From source file:org.dbflute.helper.io.xls.DfTableXlsReader.java

License:Apache License

protected void setupColumns(DfDataTable table, Row nameRow, Row valueRow) {
    for (int i = 0;; ++i) {
        final Cell nameCell = nameRow.getCell(i);
        if (nameCell == null) {
            break;
        }/*from   w  w w .  j av a 2  s. co  m*/
        final RichTextString richStringCellValue = nameCell.getRichStringCellValue();
        if (richStringCellValue == null) {
            break;
        }
        final String columnName = richStringCellValue.getString().trim();
        if (columnName.length() == 0) {
            break;
        }
        Cell valueCell = null;
        if (valueRow != null) {
            valueCell = valueRow.getCell(i);
        }
        if (valueCell != null) {
            table.addColumn(columnName, getColumnType(valueCell));
        } else {
            table.addColumn(columnName);
        }
    }
}

From source file:org.dbflute.helper.io.xls.DfTableXlsReader.java

License:Apache License

protected Object processRichStringCellValue(DfDataTable table, int columnIndex, Row row, Cell cell) {
    String str = cell.getRichStringCellValue().getString();
    str = rtrimCellValueIfNeeds(table, cell, str); // basically for compatible
    str = treatEmptyAsNullBasically(str); // empty means null basically
    str = treatNullAsEmptyIfTarget(table, columnIndex, str); // but empty if target
    str = treatCrLfAsLf(str); // remove CR
    if (isCellBase64Formatted(cell)) {
        return decodeAsBase64(str);
    }//w w  w  .  ja  va  2s.  c o  m
    // normal cell here
    return resolveLargeDataIfNeeds(table, columnIndex, row, str);
}

From source file:org.dbflute.logic.manage.freegen.table.xls.DfXlsTableLoader.java

License:Apache License

protected boolean processColumnValue(final String requestName, final Map<String, String> columnMap,
        final Row row, final Map<String, Object> beanMap, final String key, final String value,
        List<DfFreeGenLazyReflector> reflectorList, Map<String, Map<String, String>> mappingMap) {
    if (convertByMethod(requestName, beanMap, key, value, reflectorList)) {
        return false;
    }/*from   www  .  j  a v  a2 s .  c o  m*/
    // normal setting (cell number)
    boolean exists = false;
    final Integer cellNumber;
    try {
        cellNumber = Integer.valueOf(value) - 1;
    } catch (NumberFormatException e) {
        String msg = "The property value should be Integer in FreeGen " + requestName + ":";
        msg = msg + " key=" + key + " value=" + value;
        throw new DfIllegalPropertySettingException(msg);
    }
    final Cell cell = row.getCell(cellNumber);
    if (cell == null) {
        return false;
    }
    final RichTextString cellValue = cell.getRichStringCellValue();
    if (cellValue == null) {
        return false;
    }
    exists = true;
    String resultValue = cellValue.getString();
    final Map<String, String> mapping = mappingMap.get(key);
    if (mapping != null) {
        final String mappingValue = mapping.get(resultValue);
        if (mappingValue != null) {
            resultValue = mappingValue;
        }
    }
    beanMap.put(key, resultValue);
    return exists;
}