Search in sources :

Example 1 with ITextFileInputField

use of org.apache.hop.core.gui.ITextFileInputField in project hop by apache.

the class TextFileInputDialog method getFields.

private Vector<ITextFileInputField> getFields(TextFileInputMeta info, List<String> rows) {
    Vector<ITextFileInputField> fields = new Vector<>();
    int maxsize = 0;
    for (String row : rows) {
        int len = row.length();
        if (len > maxsize) {
            maxsize = len;
        }
    }
    int prevEnd = 0;
    int dummynr = 1;
    for (int i = 0; i < info.getInputFields().length; i++) {
        TextFileInputField f = info.getInputFields()[i];
        // See if positions are skipped, if this is the case, add dummy fields...
        if (f.getPosition() != prevEnd) {
            // gap
            TextFileInputField field = new TextFileInputField("Dummy" + dummynr, prevEnd, f.getPosition() - prevEnd);
            // don't include in result by default.
            field.setIgnored(true);
            fields.add(field);
            dummynr++;
        }
        TextFileInputField field = new TextFileInputField(f.getName(), f.getPosition(), f.getLength());
        field.setType(f.getType());
        field.setIgnored(false);
        field.setFormat(f.getFormat());
        field.setPrecision(f.getPrecision());
        field.setTrimType(f.getTrimType());
        field.setDecimalSymbol(f.getDecimalSymbol());
        field.setGroupSymbol(f.getGroupSymbol());
        field.setCurrencySymbol(f.getCurrencySymbol());
        field.setRepeated(f.isRepeated());
        field.setNullString(f.getNullString());
        fields.add(field);
        prevEnd = field.getPosition() + field.getLength();
    }
    if (info.getInputFields().length == 0) {
        TextFileInputField field = new TextFileInputField("Field1", 0, maxsize);
        fields.add(field);
    } else {
        // Take the last field and see if it reached until the maximum...
        TextFileInputField f = info.getInputFields()[info.getInputFields().length - 1];
        int pos = f.getPosition();
        int len = f.getLength();
        if (pos + len < maxsize) {
            // If not, add an extra trailing field!
            TextFileInputField field = new TextFileInputField("Dummy" + dummynr, pos + len, maxsize - pos - len);
            // don't include in result by default.
            field.setIgnored(true);
            fields.add(field);
        }
    }
    Collections.sort(fields);
    return fields;
}
Also used : ITextFileInputField(org.apache.hop.core.gui.ITextFileInputField) TextFileInputField(org.apache.hop.core.file.TextFileInputField) ITextFileInputField(org.apache.hop.core.gui.ITextFileInputField) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString)

Example 2 with ITextFileInputField

use of org.apache.hop.core.gui.ITextFileInputField in project hop by apache.

the class TextFileInputDialog method getFields.

private Vector<ITextFileInputField> getFields(TextFileInputMeta info, List<String> rows) {
    Vector<ITextFileInputField> fields = new Vector<>();
    int maxsize = 0;
    for (String row : rows) {
        int len = row.length();
        if (len > maxsize) {
            maxsize = len;
        }
    }
    int prevEnd = 0;
    int dummynr = 1;
    for (int i = 0; i < info.inputFields.length; i++) {
        BaseFileField f = info.inputFields[i];
        // See if positions are skipped, if this is the case, add dummy fields...
        if (f.getPosition() != prevEnd) {
            // gap
            BaseFileField field = new BaseFileField("Dummy" + dummynr, prevEnd, f.getPosition() - prevEnd);
            // don't include in result by default.
            field.setIgnored(true);
            fields.add(field);
            dummynr++;
        }
        BaseFileField field = new BaseFileField(f.getName(), f.getPosition(), f.getLength());
        field.setType(f.getType());
        field.setIgnored(false);
        field.setFormat(f.getFormat());
        field.setPrecision(f.getPrecision());
        field.setTrimType(f.getTrimType());
        field.setDecimalSymbol(f.getDecimalSymbol());
        field.setGroupSymbol(f.getGroupSymbol());
        field.setCurrencySymbol(f.getCurrencySymbol());
        field.setRepeated(f.isRepeated());
        field.setNullString(f.getNullString());
        fields.add(field);
        prevEnd = field.getPosition() + field.getLength();
    }
    if (info.inputFields.length == 0) {
        BaseFileField field = new BaseFileField("Field1", 0, maxsize);
        fields.add(field);
    } else {
        // Take the last field and see if it reached until the maximum...
        BaseFileField f = info.inputFields[info.inputFields.length - 1];
        int pos = f.getPosition();
        int len = f.getLength();
        if (pos + len < maxsize) {
            // If not, add an extra trailing field!
            BaseFileField field = new BaseFileField("Dummy" + dummynr, pos + len, maxsize - pos - len);
            // don't include in result by default.
            field.setIgnored(true);
            fields.add(field);
        }
    }
    Collections.sort(fields);
    return fields;
}
Also used : ITextFileInputField(org.apache.hop.core.gui.ITextFileInputField) BaseFileField(org.apache.hop.pipeline.transforms.file.BaseFileField) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString)

Aggregations

ITextFileInputField (org.apache.hop.core.gui.ITextFileInputField)2 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)2 TextFileInputField (org.apache.hop.core.file.TextFileInputField)1 BaseFileField (org.apache.hop.pipeline.transforms.file.BaseFileField)1