use of org.pentaho.di.core.exception.KettleXMLException in project pentaho-kettle by pentaho.
the class MessagesSourceCrawler method crawl.
public void crawl() throws Exception {
for (final String sourceDirectory : sourceDirectories) {
FileObject folder = KettleVFS.getFileObject(sourceDirectory);
FileObject[] javaFiles = folder.findFiles(new FileSelector() {
@Override
public boolean traverseDescendents(FileSelectInfo info) throws Exception {
return true;
}
@Override
public boolean includeFile(FileSelectInfo info) throws Exception {
return info.getFile().getName().getExtension().equals("java");
}
});
for (FileObject javaFile : javaFiles) {
/**
* We don't want the Messages.java files, there is nothing in there for us.
*/
boolean skip = false;
for (String filename : filesToAvoid) {
if (javaFile.getName().getBaseName().equals(filename)) {
skip = true;
}
}
if (skip) {
// don't process this file.
continue;
}
// For each of these files we look for keys...
//
lookForOccurrencesInFile(sourceDirectory, javaFile);
}
}
//
for (SourceCrawlerXMLFolder xmlFolder : xmlFolders) {
String[] xmlDirs = { xmlFolder.getFolder() };
String[] xmlMasks = { xmlFolder.getWildcard() };
String[] xmlReq = { "N" };
// search sub-folders too
boolean[] xmlSubdirs = { true };
FileInputList xulFileInputList = FileInputList.createFileList(new Variables(), xmlDirs, xmlMasks, xmlReq, xmlSubdirs);
for (FileObject fileObject : xulFileInputList.getFiles()) {
try {
Document doc = XMLHandler.loadXMLFile(fileObject);
//
for (SourceCrawlerXMLElement xmlElement : xmlFolder.getElements()) {
addLabelOccurrences(xmlFolder.getDefaultSourceFolder(), fileObject, doc.getElementsByTagName(xmlElement.getSearchElement()), xmlFolder.getKeyPrefix(), xmlElement.getKeyTag(), xmlElement.getKeyAttribute(), xmlFolder.getDefaultPackage(), xmlFolder.getPackageExceptions());
}
} catch (KettleXMLException e) {
log.logError("Unable to open XUL / XML document: " + fileObject);
}
}
}
}
use of org.pentaho.di.core.exception.KettleXMLException in project pentaho-kettle by pentaho.
the class XMLJoin method processRow.
@Override
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
meta = (XMLJoinMeta) smi;
data = (XMLJoinData) sdi;
XPath xpath = XPathFactory.newInstance().newXPath();
// if first row we do some initializing and process the first row of the target XML Step
if (first) {
first = false;
int target_field_id = -1;
XMLJoinMeta meta = (XMLJoinMeta) smi;
// Get the two input row sets
data.TargetRowSet = findInputRowSet(meta.getTargetXMLstep());
data.SourceRowSet = findInputRowSet(meta.getSourceXMLstep());
// get the first line from the target row set
Object[] rTarget = getRowFrom(data.TargetRowSet);
if (rTarget == null) {
// nothing to do
logBasic(BaseMessages.getString(PKG, "XMLJoin.NoRowsFoundInTarget"));
setOutputDone();
return false;
}
// get target xml
String[] target_field_names = data.TargetRowSet.getRowMeta().getFieldNames();
for (int i = 0; i < target_field_names.length; i++) {
if (meta.getTargetXMLfield().equals(target_field_names[i])) {
target_field_id = i;
}
}
// Throw exception if target field has not been found
if (target_field_id == -1) {
throw new KettleException(BaseMessages.getString(PKG, "XMLJoin.Exception.FieldNotFound", meta.getTargetXMLfield()));
}
data.outputRowMeta = data.TargetRowSet.getRowMeta().clone();
meta.getFields(data.outputRowMeta, getStepname(), new RowMetaInterface[] { data.TargetRowSet.getRowMeta() }, null, getTransMeta(), repository, metaStore);
data.outputRowData = rTarget.clone();
// get the target xml structure and create a DOM
String strTarget = (String) rTarget[target_field_id];
// parse the XML as a W3C Document
InputSource inputSource = new InputSource(new StringReader(strTarget));
data.XPathStatement = meta.getTargetXPath();
try {
DocumentBuilder builder = XMLParserFactoryProducer.createSecureDocBuilderFactory().newDocumentBuilder();
data.targetDOM = builder.parse(inputSource);
if (!meta.isComplexJoin()) {
data.targetNode = (Node) xpath.evaluate(data.XPathStatement, data.targetDOM, XPathConstants.NODE);
if (data.targetNode == null) {
throw new KettleXMLException("XPath statement returned no result [" + data.XPathStatement + "]");
}
}
} catch (Exception e) {
throw new KettleXMLException(e);
}
}
// This also waits for a row to be finished.
Object[] rJoinSource = getRowFrom(data.SourceRowSet);
if (rJoinSource == null) {
// no more input to be expected... create the output row
try {
if (meta.isOmitNullValues()) {
removeEmptyNodes(data.targetDOM.getChildNodes());
}
// create string from xml tree
StringWriter sw = new StringWriter();
StreamResult resultXML = new StreamResult(sw);
DOMSource source = new DOMSource(data.targetDOM);
getTransformer().transform(source, resultXML);
int outputIndex = data.outputRowMeta.size() - 1;
// send the row to the next steps...
putRow(data.outputRowMeta, RowDataUtil.addValueData(data.outputRowData, outputIndex, sw.toString()));
// finishing up
setOutputDone();
return false;
} catch (Exception e) {
throw new KettleException(e);
}
} else {
if (data.iSourceXMLField == -1) {
// assume failure
// get the column of the join xml set
// get target xml
String[] source_field_names = data.SourceRowSet.getRowMeta().getFieldNames();
for (int i = 0; i < source_field_names.length; i++) {
if (meta.getSourceXMLfield().equals(source_field_names[i])) {
data.iSourceXMLField = i;
}
}
// Throw exception if source xml field has not been found
if (data.iSourceXMLField == -1) {
throw new KettleException(BaseMessages.getString(PKG, "XMLJoin.Exception.FieldNotFound", meta.getSourceXMLfield()));
}
}
if (meta.isComplexJoin() && data.iCompareFieldID == -1) {
// get the column of the compare value
String[] source_field_names = data.SourceRowSet.getRowMeta().getFieldNames();
for (int i = 0; i < source_field_names.length; i++) {
if (meta.getJoinCompareField().equals(source_field_names[i])) {
data.iCompareFieldID = i;
}
}
// Throw exception if source xml field has not been found
if (data.iCompareFieldID == -1) {
throw new KettleException(BaseMessages.getString(PKG, "XMLJoin.Exception.FieldNotFound", meta.getJoinCompareField()));
}
}
// get XML tags to join
String strJoinXML = (String) rJoinSource[data.iSourceXMLField];
try {
DocumentBuilder builder = XMLParserFactoryProducer.createSecureDocBuilderFactory().newDocumentBuilder();
Document joinDocument = builder.parse(new InputSource(new StringReader(strJoinXML)));
Node node = data.targetDOM.importNode(joinDocument.getDocumentElement(), true);
if (meta.isComplexJoin()) {
String strCompareValue = rJoinSource[data.iCompareFieldID].toString();
String strXPathStatement = data.XPathStatement.replace("?", strCompareValue);
data.targetNode = (Node) xpath.evaluate(strXPathStatement, data.targetDOM, XPathConstants.NODE);
if (data.targetNode == null) {
throw new KettleXMLException("XPath statement returned no result [" + strXPathStatement + "]");
}
}
data.targetNode.appendChild(node);
} catch (Exception e) {
throw new KettleException(e);
}
}
return true;
}
use of org.pentaho.di.core.exception.KettleXMLException in project pentaho-kettle by pentaho.
the class XMLJoinMeta method readData.
private void readData(Node stepnode) throws KettleXMLException {
try {
valueXMLfield = XMLHandler.getTagValue(stepnode, "valueXMLfield");
targetXMLstep = XMLHandler.getTagValue(stepnode, "targetXMLstep");
targetXMLfield = XMLHandler.getTagValue(stepnode, "targetXMLfield");
sourceXMLstep = XMLHandler.getTagValue(stepnode, "sourceXMLstep");
sourceXMLfield = XMLHandler.getTagValue(stepnode, "sourceXMLfield");
targetXPath = XMLHandler.getTagValue(stepnode, "targetXPath");
joinCompareField = XMLHandler.getTagValue(stepnode, "joinCompareField");
encoding = XMLHandler.getTagValue(stepnode, "encoding");
complexJoin = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "complexJoin"));
omitXMLHeader = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "omitXMLHeader"));
omitNullValues = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "omitNullValues"));
} catch (Exception e) {
throw new KettleXMLException("Unable to load step info from XML", e);
}
}
use of org.pentaho.di.core.exception.KettleXMLException in project pentaho-kettle by pentaho.
the class XsdValidatorMeta method readData.
private void readData(Node stepnode) throws KettleXMLException {
try {
xsdFilename = XMLHandler.getTagValue(stepnode, "xdsfilename");
xmlStream = XMLHandler.getTagValue(stepnode, "xmlstream");
resultFieldname = XMLHandler.getTagValue(stepnode, "resultfieldname");
xsdDefinedField = XMLHandler.getTagValue(stepnode, "xsddefinedfield");
xsdSource = XMLHandler.getTagValue(stepnode, "xsdsource");
addValidationMessage = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "addvalidationmsg"));
validationMessageField = XMLHandler.getTagValue(stepnode, "validationmsgfield");
ifXmlValid = XMLHandler.getTagValue(stepnode, "ifxmlvalid");
ifXmlInvalid = XMLHandler.getTagValue(stepnode, "ifxmlunvalid");
outputStringField = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "outputstringfield"));
xmlSourceFile = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "xmlsourcefile"));
} catch (Exception e) {
throw new KettleXMLException(BaseMessages.getString(PKG, "XsdValidatorMeta.Exception.UnableToLoadStepInfoFromXML"), e);
}
}
use of org.pentaho.di.core.exception.KettleXMLException in project pentaho-kettle by pentaho.
the class XsltMeta method readData.
private void readData(Node stepnode) throws KettleXMLException {
try {
xslFilename = XMLHandler.getTagValue(stepnode, "xslfilename");
fieldName = XMLHandler.getTagValue(stepnode, "fieldname");
resultFieldname = XMLHandler.getTagValue(stepnode, "resultfieldname");
xslFileField = XMLHandler.getTagValue(stepnode, "xslfilefield");
xslFileFieldUse = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "xslfilefielduse"));
String isAFile = XMLHandler.getTagValue(stepnode, "xslfieldisafile");
if (xslFileFieldUse && Utils.isEmpty(isAFile)) {
xslFieldIsAFile = true;
} else {
xslFieldIsAFile = "Y".equalsIgnoreCase(isAFile);
}
xslFactory = XMLHandler.getTagValue(stepnode, "xslfactory");
Node parametersNode = XMLHandler.getSubNode(stepnode, "parameters");
int nrparams = XMLHandler.countNodes(parametersNode, "parameter");
Node parametersOutputProps = XMLHandler.getSubNode(stepnode, "outputproperties");
int nroutputprops = XMLHandler.countNodes(parametersOutputProps, "outputproperty");
allocate(nrparams, nroutputprops);
for (int i = 0; i < nrparams; i++) {
Node anode = XMLHandler.getSubNodeByNr(parametersNode, "parameter", i);
parameterField[i] = XMLHandler.getTagValue(anode, "field");
parameterName[i] = XMLHandler.getTagValue(anode, "name");
}
for (int i = 0; i < nroutputprops; i++) {
Node anode = XMLHandler.getSubNodeByNr(parametersOutputProps, "outputproperty", i);
outputPropertyName[i] = XMLHandler.getTagValue(anode, "name");
outputPropertyValue[i] = XMLHandler.getTagValue(anode, "value");
}
} catch (Exception e) {
throw new KettleXMLException(BaseMessages.getString(PKG, "XsltMeta.Exception.UnableToLoadStepInfoFromXML"), e);
}
}
Aggregations