use of org.pentaho.di.core.row.ValueMeta in project pentaho-kettle by pentaho.
the class XMLJoinMeta method getFields.
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
ValueMetaInterface v = new ValueMeta(this.getValueXMLfield(), ValueMetaInterface.TYPE_STRING);
v.setOrigin(name);
TransMeta transMeta = (TransMeta) space;
try {
// source fields.
for (String fieldName : transMeta.getStepFields(transMeta.findStep(getSourceXMLstep()), null, null).getFieldNames()) {
row.removeValueMeta(fieldName);
}
} catch (KettleValueException e) {
// Pass
}
row.addValueMeta(v);
}
use of org.pentaho.di.core.row.ValueMeta in project pentaho-kettle by pentaho.
the class XMLInputMeta method getFields.
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
for (int i = 0; i < inputFields.length; i++) {
XMLInputField field = inputFields[i];
int type = field.getType();
if (type == ValueMeta.TYPE_NONE) {
type = ValueMeta.TYPE_STRING;
}
try {
ValueMetaInterface v = ValueMetaFactory.createValueMeta(field.getName(), type);
v.setLength(field.getLength(), field.getPrecision());
v.setConversionMask(field.getFormat());
v.setDecimalSymbol(field.getDecimalSymbol());
v.setGroupingSymbol(field.getGroupSymbol());
v.setTrimType(field.getTrimType());
v.setCurrencySymbol(field.getCurrencySymbol());
v.setOrigin(name);
r.addValueMeta(v);
} catch (Exception e) {
throw new KettleStepException(e);
}
}
if (includeFilename) {
ValueMetaInterface v = new ValueMeta(filenameField, ValueMeta.TYPE_STRING);
v.setLength(100);
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeRowNumber) {
ValueMetaInterface v = new ValueMeta(rowNumberField, ValueMeta.TYPE_INTEGER);
v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH);
v.setOrigin(name);
r.addValueMeta(v);
}
}
use of org.pentaho.di.core.row.ValueMeta in project pentaho-kettle by pentaho.
the class XMLInputDialog method getValues.
/**
* Get all the values defined in a Node
*
* @param node
* The node to examine
* @param row
* The
*/
private void getValues(Node node, RowMetaInterface row, List<XMLInputFieldPosition> path, int level) throws KettleException {
String baseName = "";
for (int p = 0; p < path.size(); p++) {
XMLInputFieldPosition pos = path.get(p);
String elementName = pos.getName() + pos.getElementNr();
if (!elementName.startsWith("#")) {
baseName += StringUtil.initCap(new ValueMetaAndData("p", elementName).toString());
}
}
// Add the root element
if (level == 0) {
if (XMLHandler.getNodeValue(node) != null) {
XMLInputFieldPosition attrPos = new XMLInputFieldPosition(node.getNodeName(), XMLInputFieldPosition.XML_ROOT);
path.add(attrPos);
String root = StringUtil.initCap(new ValueMetaAndData("a", node.getNodeName()).toString());
String fieldName = baseName + root;
if (row.searchValueMeta(fieldName) == null) {
// Not there yet: add it!
// Add the fieldname...
ValueMeta field = new ValueMeta(fieldName, ValueMeta.TYPE_STRING);
// Add the path to this attribute to the origin of the
// field...
String encoded = XMLInputFieldPosition.encodePath(path);
field.setOrigin(encoded);
row.addValueMeta(field);
}
// Now remove the root from the path again, it's not needed
// realy...
path.remove(path.size() - 1);
}
}
// First check out the attributes...
String[] attributes = XMLHandler.getNodeAttributes(node);
if (attributes != null) {
for (int i = 0; i < attributes.length; i++) {
XMLInputFieldPosition attrPos = new XMLInputFieldPosition(attributes[i], XMLInputFieldPosition.XML_ATTRIBUTE);
path.add(attrPos);
String attribute = StringUtil.initCap(new ValueMetaAndData("a", attributes[i]).toString());
String fieldName = baseName + attribute;
// See if this fieldname already exists in Row...
if (row.searchValueMeta(fieldName) == null) {
// Add the fieldname...
ValueMeta field = new ValueMeta(fieldName, ValueMeta.TYPE_STRING);
// Add the path to this attribute to the origin of the
// field...
String encoded = XMLInputFieldPosition.encodePath(path);
field.setOrigin(encoded);
row.addValueMeta(field);
}
path.remove(path.size() - 1);
}
}
// Then get the elements
String[] elements = XMLHandler.getNodeElements(node);
if (elements != null) {
for (int e = 0; e < elements.length; e++) {
// Count the number of occurrences of this element...
int occurrences = XMLHandler.countNodes(node, elements[e]);
for (int o = 0; o < occurrences; o++) {
Node itemNode = XMLHandler.getSubNodeByNr(node, elements[e], o, false);
XMLInputFieldPosition xmlPos = new XMLInputFieldPosition(elements[e], XMLInputFieldPosition.XML_ELEMENT, o + 1);
path.add(xmlPos);
getValues(itemNode, row, path, level + 1);
// remove the last one again
path.remove(path.size() - 1);
}
}
} else {
if (path.size() > 0) {
int idxLast = path.size() - 1;
XMLInputFieldPosition last = path.get(idxLast);
path.remove(idxLast);
if (path.size() > 0) {
String encoded = XMLInputFieldPosition.encodePath(path);
if (row.searchValueMeta(baseName) == null) {
ValueMeta value = new ValueMeta(baseName, ValueMeta.TYPE_STRING);
value.setOrigin(encoded);
row.addValueMeta(value);
}
}
path.add(last);
}
}
}
use of org.pentaho.di.core.row.ValueMeta in project pentaho-kettle by pentaho.
the class AddXMLMeta method getFields.
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
ValueMetaInterface v = new ValueMeta(this.getValueName(), ValueMetaInterface.TYPE_STRING);
v.setOrigin(name);
row.addValueMeta(v);
}
use of org.pentaho.di.core.row.ValueMeta in project pentaho-kettle by pentaho.
the class GetXMLDataMeta method getFields.
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
int i;
for (i = 0; i < inputFields.length; i++) {
GetXMLDataField field = inputFields[i];
int type = field.getType();
if (type == ValueMeta.TYPE_NONE) {
type = ValueMeta.TYPE_STRING;
}
try {
ValueMetaInterface v = ValueMetaFactory.createValueMeta(space.environmentSubstitute(field.getName()), type);
v.setLength(field.getLength());
v.setPrecision(field.getPrecision());
v.setOrigin(name);
v.setConversionMask(field.getFormat());
v.setDecimalSymbol(field.getDecimalSymbol());
v.setGroupingSymbol(field.getGroupSymbol());
v.setCurrencySymbol(field.getCurrencySymbol());
r.addValueMeta(v);
} catch (Exception e) {
throw new KettleStepException(e);
}
}
if (includeFilename) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(filenameField), ValueMeta.TYPE_STRING);
v.setLength(250);
v.setPrecision(-1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeRowNumber) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(rowNumberField), ValueMeta.TYPE_INTEGER);
v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getShortFileNameField() != null && getShortFileNameField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getShortFileNameField()), ValueMeta.TYPE_STRING);
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getExtensionField() != null && getExtensionField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getExtensionField()), ValueMeta.TYPE_STRING);
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getPathField() != null && getPathField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getPathField()), ValueMeta.TYPE_STRING);
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getSizeField() != null && getSizeField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getSizeField()), ValueMeta.TYPE_INTEGER);
v.setOrigin(name);
v.setLength(9);
r.addValueMeta(v);
}
if (isHiddenField() != null && isHiddenField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(isHiddenField()), ValueMeta.TYPE_BOOLEAN);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getLastModificationDateField() != null && getLastModificationDateField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getLastModificationDateField()), ValueMeta.TYPE_DATE);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getUriField() != null && getUriField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getUriField()), ValueMeta.TYPE_STRING);
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getRootUriField() != null && getRootUriField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getRootUriField()), ValueMeta.TYPE_STRING);
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
}
Aggregations