Search in sources :

Example 1 with XMLInputSaxField

use of org.pentaho.di.trans.steps.xmlinputsax.XMLInputSaxField in project pentaho-kettle by pentaho.

the class XMLInputSaxDialog method get.

// 
private void get() {
    try {
        XMLInputSaxMeta meta = new XMLInputSaxMeta();
        getInfo(meta);
        // OK, let's try to walk through the complete tree
        List<XMLInputSaxField> fields = new ArrayList<XMLInputSaxField>();
        // Keep the list of positions
        String[] filePaths = meta.getFilePaths(transMeta);
        if (meta.getInputPosition().length == 0) {
            // error
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            mb.setMessage(BaseMessages.getString(PKG, "XMLInputSaxDialog.Dialog.NoElements.Message"));
            mb.setText(BaseMessages.getString(PKG, "XMLInputSaxDialog.Dialog.NoElements.Title"));
            mb.open();
            return;
        }
        for (int f = 0; f < filePaths.length; f++) {
            XMLInputSaxFieldRetriever fieldRetreiver = new XMLInputSaxFieldRetriever(log, filePaths[f], meta);
            fields = fieldRetreiver.getFields();
            // add the values to the grid...
            for (int i = 0; i < fields.size(); i++) {
                XMLInputSaxField iF = fields.get(i);
                TableItem item = new TableItem(wFields.table, SWT.NONE);
                item.setText(1, iF.getName());
                item.setText(2, iF.getTypeDesc());
                item.setText(11, iF.getFieldPositionsCode(meta.getInputPosition().length));
            }
            wFields.removeEmptyRows();
            wFields.setRowNums();
            wFields.optWidth(true);
        }
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "XMLInputSaxDialog.Dialog.ErrorParsingInputData.Title"), BaseMessages.getString(PKG, "XMLInputSaxDialog.Dialog.ErrorParsingInputData.Message"), e);
        System.out.println(e.getMessage());
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) XMLInputSaxFieldRetriever(org.pentaho.di.trans.steps.xmlinputsax.XMLInputSaxFieldRetriever) XMLInputSaxMeta(org.pentaho.di.trans.steps.xmlinputsax.XMLInputSaxMeta) XMLInputSaxField(org.pentaho.di.trans.steps.xmlinputsax.XMLInputSaxField) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 2 with XMLInputSaxField

use of org.pentaho.di.trans.steps.xmlinputsax.XMLInputSaxField in project pentaho-kettle by pentaho.

the class XMLInputSaxDialog method getData.

/**
 * Read the data from the XMLvInputMeta object and show it in this dialog.
 *
 * @param in
 *          The XMLvInputMeta object to obtain the data from.
 */
public void getData(XMLInputSaxMeta in) {
    if (in.getFileName() != null) {
        wFilenameList.removeAll();
        for (int i = 0; i < in.getFileName().length; i++) {
            wFilenameList.add(new String[] { in.getFileName()[i], in.getFileMask()[i] });
        }
        wFilenameList.removeEmptyRows();
        wFilenameList.setRowNums();
        wFilenameList.optWidth(true);
    }
    wInclFilename.setSelection(in.includeFilename());
    wInclRownum.setSelection(in.includeRowNumber());
    // wMultiple.setSelection(in.wildcard);
    if (in.getFilenameField() != null) {
        wInclFilenameField.setText(in.getFilenameField());
    }
    if (in.getRowNumberField() != null) {
        wInclRownumField.setText(in.getRowNumberField());
    }
    wLimit.setText("" + in.getRowLimit());
    logDebug("getting fields info...");
    for (int i = 0; i < in.getInputFields().length; i++) {
        XMLInputSaxField field = in.getInputFields()[i];
        if (field != null) {
            TableItem item = wFields.table.getItem(i);
            String name = field.getName();
            String type = field.getTypeDesc();
            String format = field.getFormat();
            String length = "" + field.getLength();
            String prec = "" + field.getPrecision();
            String curr = field.getCurrencySymbol();
            String group = field.getGroupSymbol();
            String decim = field.getDecimalSymbol();
            String trim = field.getTrimTypeDesc();
            String rep = field.isRepeated() ? "Y" : "N";
            if (name != null) {
                item.setText(1, name);
            }
            if (type != null) {
                item.setText(2, type);
            }
            if (format != null) {
                item.setText(3, format);
            }
            if (length != null && !"-1".equals(length)) {
                item.setText(4, length);
            }
            if (prec != null && !"-1".equals(prec)) {
                item.setText(5, prec);
            }
            if (curr != null) {
                item.setText(6, curr);
            }
            if (decim != null) {
                item.setText(7, decim);
            }
            if (group != null) {
                item.setText(8, group);
            }
            if (trim != null) {
                item.setText(9, trim);
            }
            if (rep != null) {
                item.setText(10, rep);
            }
            item.setText(11, field.getFieldPositionsCode());
        }
    }
    for (int i = 0; i < input.getDefinitionLength(); i++) {
        TableItem item = wAttributes.table.getItem(i);
        item.setText(1, input.getDefiningElement(i));
        item.setText(2, input.getDefiningAttribute(i));
    }
    for (int i = 0; i < input.getInputPosition().length; i++) {
        TableItem item = wPosition.table.getItem(i);
        if (input.getInputPosition()[i] != null) {
            item.setText(1, input.getInputPosition()[i].toString());
        }
    }
    wFields.removeEmptyRows();
    wFields.setRowNums();
    wFields.optWidth(true);
    wPosition.removeEmptyRows();
    wPosition.setRowNums();
    wPosition.optWidth(true);
    setMultiple();
    setIncludeFilename();
    setIncludeRownum();
    wStepname.selectAll();
    wStepname.setFocus();
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) XMLInputSaxField(org.pentaho.di.trans.steps.xmlinputsax.XMLInputSaxField)

Example 3 with XMLInputSaxField

use of org.pentaho.di.trans.steps.xmlinputsax.XMLInputSaxField in project pentaho-kettle by pentaho.

the class XMLInputSaxDialog method getInfo.

// get metadata from ui to in
private void getInfo(XMLInputSaxMeta in) throws KettleException {
    // return value
    stepname = wStepname.getText();
    // copy info to TextFileInputMeta class (input)
    in.setRowLimit(Const.toLong(wLimit.getText(), 0L));
    in.setFilenameField(wInclFilenameField.getText());
    in.setRowNumberField(wInclRownumField.getText());
    in.setIncludeFilename(wInclFilename.getSelection());
    in.setIncludeRowNumber(wInclRownum.getSelection());
    int nrFiles = wFilenameList.getItemCount();
    int nrAttributes = wAttributes.nrNonEmpty();
    int nrFields = wFields.nrNonEmpty();
    int nrPositions = wPosition.nrNonEmpty();
    in.allocate(nrFiles, nrFields, nrPositions);
    in.setFileName(wFilenameList.getItems(0));
    in.setFileMask(wFilenameList.getItems(1));
    in.clearDefinition();
    for (int i = 0; i < nrAttributes; i++) {
        TableItem item = wAttributes.getNonEmpty(i);
        in.setDefiningAttribute(item.getText(1), item.getText(2));
    }
    for (int i = 0; i < nrFields; i++) {
        XMLInputSaxField field = new XMLInputSaxField();
        TableItem item = wFields.getNonEmpty(i);
        field.setName(item.getText(1));
        field.setType(Value.getType(item.getText(2)));
        field.setFormat(item.getText(3));
        field.setLength(Const.toInt(item.getText(4), -1));
        field.setPrecision(Const.toInt(item.getText(5), -1));
        field.setCurrencySymbol(item.getText(6));
        field.setDecimalSymbol(item.getText(7));
        field.setGroupSymbol(item.getText(8));
        field.setTrimType(XMLInputSaxField.getTrimType(item.getText(9)));
        field.setRepeated("Y".equalsIgnoreCase(item.getText(10)));
        field.setFieldPosition(item.getText(11));
        // CHECKSTYLE:Indentation:OFF
        in.getInputFields()[i] = field;
    }
    for (int i = 0; i < nrPositions; i++) {
        TableItem item = wPosition.getNonEmpty(i);
        String encode = item.getText(1);
        // CHECKSTYLE:Indentation:OFF
        in.getInputPosition()[i] = new XMLInputSaxFieldPosition(encode);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) XMLInputSaxField(org.pentaho.di.trans.steps.xmlinputsax.XMLInputSaxField) XMLInputSaxFieldPosition(org.pentaho.di.trans.steps.xmlinputsax.XMLInputSaxFieldPosition)

Aggregations

TableItem (org.eclipse.swt.widgets.TableItem)3 XMLInputSaxField (org.pentaho.di.trans.steps.xmlinputsax.XMLInputSaxField)3 ArrayList (java.util.ArrayList)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 KettleException (org.pentaho.di.core.exception.KettleException)1 XMLInputSaxFieldPosition (org.pentaho.di.trans.steps.xmlinputsax.XMLInputSaxFieldPosition)1 XMLInputSaxFieldRetriever (org.pentaho.di.trans.steps.xmlinputsax.XMLInputSaxFieldRetriever)1 XMLInputSaxMeta (org.pentaho.di.trans.steps.xmlinputsax.XMLInputSaxMeta)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1