Java Code Examples for org.pentaho.di.core.xml.XMLHandler#loadXMLFile()

The following examples show how to use org.pentaho.di.core.xml.XMLHandler#loadXMLFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DimensionTableDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void addAttributesFromFile(String filename) throws KettleException {
  InputStream inputStream = getClass().getResourceAsStream(filename);
  Document document = XMLHandler.loadXMLFile(inputStream);
  Node attributesNode = XMLHandler.getSubNode(document, "attributes");
  List<Node> attributeNodes = XMLHandler.getNodes(attributesNode, "attribute");
  for (Node node : attributeNodes) {
    String name = XMLHandler.getTagValue(node, "name");
    String description = XMLHandler.getTagValue(node, "description");
    String phName = XMLHandler.getTagValue(node, "physicalname");
    AttributeType attributeType= AttributeType.getAttributeType(XMLHandler.getTagValue(node, "attribute_type"));
    DataType dataType= ConceptUtil.getDataType(XMLHandler.getTagValue(node, "data_type"));
    int length = Const.toInt(XMLHandler.getTagValue(node, "length"), -1);
    int precision = Const.toInt(XMLHandler.getTagValue(node, "precision"), -1);
    // String sourceDb = XMLHandler.getTagValue(node, "source_db");
    // String sourceTable = XMLHandler.getTagValue(node, "source_table");
    // String sourceColumn = XMLHandler.getTagValue(node, "source_column");
    String remarks = XMLHandler.getTagValue(node, "remarks");
    addAttribute(name, description, phName, attributeType, dataType, length, precision, remarks);
  }

}
 
Example 2
Source File: TwoWayPasswordEncoderPluginType.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
protected void registerXmlPlugins() throws KettlePluginException {
  for ( PluginFolderInterface folder : pluginFolders ) {

    if ( folder.isPluginXmlFolder() ) {
      List<FileObject> pluginXmlFiles = findPluginXmlFiles( folder.getFolder() );
      for ( FileObject file : pluginXmlFiles ) {

        try {
          Document document = XMLHandler.loadXMLFile( file );
          Node pluginNode = XMLHandler.getSubNode( document, "plugin" );
          if ( pluginNode != null ) {
            registerPluginFromXmlResource( pluginNode, KettleVFS.getFilename( file.getParent() ), this
              .getClass(), false, file.getParent().getURL() );
          }
        } catch ( Exception e ) {
          // We want to report this plugin.xml error, perhaps an XML typo or something like that...
          //
          log.logError( "Error found while reading password encoder plugin.xml file: " + file.getName().toString(), e );
        }
      }
    }
  }
}
 
Example 3
Source File: ValueMetaPluginType.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
protected void registerXmlPlugins() throws KettlePluginException {
  for ( PluginFolderInterface folder : pluginFolders ) {

    if ( folder.isPluginXmlFolder() ) {
      List<FileObject> pluginXmlFiles = findPluginXmlFiles( folder.getFolder() );
      for ( FileObject file : pluginXmlFiles ) {

        try {
          Document document = XMLHandler.loadXMLFile( file );
          Node pluginNode = XMLHandler.getSubNode( document, "plugin" );
          if ( pluginNode != null ) {
            registerPluginFromXmlResource( pluginNode, KettleVFS.getFilename( file.getParent() ), this
              .getClass(), false, file.getParent().getURL() );
          }
        } catch ( Exception e ) {
          // We want to report this plugin.xml error, perhaps an XML typo or something like that...
          //
          log.logError( "Error found while reading step plugin.xml file: " + file.getName().toString(), e );
        }
      }
    }
  }
}
 
Example 4
Source File: RepositoryPluginType.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
protected void registerXmlPlugins() throws KettlePluginException {
  for ( PluginFolderInterface folder : pluginFolders ) {

    if ( folder.isPluginXmlFolder() ) {
      List<FileObject> pluginXmlFiles = findPluginXmlFiles( folder.getFolder() );
      for ( FileObject file : pluginXmlFiles ) {

        try {
          Document document = XMLHandler.loadXMLFile( file );
          Node pluginNode = XMLHandler.getSubNode( document, "plugin" );

          registerPluginFromXmlResource(
            pluginNode, KettleVFS.getFilename( file.getParent() ), this.getClass(), false, file
              .getParent().getURL() );
        } catch ( Exception e ) {
          // We want to report this plugin.xml error, perhaps an XML typo or something like that...
          //
          log.logError( "Error found while reading repository plugin.xml file: " + file.getName().toString(), e );
        }
      }
    }
  }
}
 
Example 5
Source File: JobEntryPluginType.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
protected void registerXmlPlugins() throws KettlePluginException {
  for ( PluginFolderInterface folder : pluginFolders ) {

    if ( folder.isPluginXmlFolder() ) {
      List<FileObject> pluginXmlFiles = findPluginXmlFiles( folder.getFolder() );
      for ( FileObject file : pluginXmlFiles ) {

        try {
          Document document = XMLHandler.loadXMLFile( file );
          Node pluginNode = XMLHandler.getSubNode( document, "plugin" );
          if ( pluginNode != null ) {
            registerPluginFromXmlResource( pluginNode, KettleVFS.getFilename( file.getParent() ), this
              .getClass(), false, file.getParent().getURL() );
          }
        } catch ( Exception e ) {
          // We want to report this plugin.xml error, perhaps an XML typo or something like that...
          //
          log.logError( "Error found while reading job entry plugin.xml file: " + file.getName().toString(), e );
        }
      }
    }
  }
}
 
Example 6
Source File: ScriptMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void parseXmlForAdditionalClasses() throws KettleException {
  try {
    Properties sysprops = System.getProperties();
    String strActPath = sysprops.getProperty( "user.dir" );
    Document dom = XMLHandler.loadXMLFile( strActPath + "/plugins/steps/ScriptValues_mod/plugin.xml" );
    Node stepnode = dom.getDocumentElement();
    Node libraries = XMLHandler.getSubNode( stepnode, "js_libraries" );
    int nbOfLibs = XMLHandler.countNodes( libraries, "js_lib" );
    additionalClasses = new ScriptAddClasses[nbOfLibs];
    for ( int i = 0; i < nbOfLibs; i++ ) {
      Node fnode = XMLHandler.getSubNodeByNr( libraries, "js_lib", i );
      String strJarName = XMLHandler.getTagAttribute( fnode, "name" );
      String strClassName = XMLHandler.getTagAttribute( fnode, "classname" );
      String strJSName = XMLHandler.getTagAttribute( fnode, "js_name" );

      Class<?> addClass =
        LoadAdditionalClass( strActPath + "/plugins/steps/ScriptValues_mod/" + strJarName, strClassName );
      Object addObject = addClass.newInstance();
      additionalClasses[i] = new ScriptAddClasses( addClass, addObject, strJSName );
    }
  } catch ( Exception e ) {
    throw new KettleException( BaseMessages.getString(
      PKG, "ScriptMeta.Exception.UnableToParseXMLforAdditionalClasses" ), e );
  }
}
 
Example 7
Source File: ScriptValuesMetaMod.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void parseXmlForAdditionalClasses() throws KettleException {
  try {
    Properties sysprops = System.getProperties();
    String strActPath = sysprops.getProperty( "user.dir" );
    Document dom = XMLHandler.loadXMLFile( strActPath + "/plugins/steps/ScriptValues_mod/plugin.xml" );
    Node stepnode = dom.getDocumentElement();
    Node libraries = XMLHandler.getSubNode( stepnode, "js_libraries" );
    int nbOfLibs = XMLHandler.countNodes( libraries, "js_lib" );
    additionalClasses = new ScriptValuesAddClasses[nbOfLibs];
    for ( int i = 0; i < nbOfLibs; i++ ) {
      Node fnode = XMLHandler.getSubNodeByNr( libraries, "js_lib", i );
      String strJarName = XMLHandler.getTagAttribute( fnode, "name" );
      String strClassName = XMLHandler.getTagAttribute( fnode, "classname" );
      String strJSName = XMLHandler.getTagAttribute( fnode, "js_name" );

      Class<?> addClass =
        LoadAdditionalClass( strActPath + "/plugins/steps/ScriptValues_mod/" + strJarName, strClassName );
      Object addObject = addClass.newInstance();
      additionalClasses[i] = new ScriptValuesAddClasses( addClass, addObject, strJSName );
    }
  } catch ( Exception e ) {
    throw new KettleException( BaseMessages.getString(
      PKG, "ScriptValuesMetaMod.Exception.UnableToParseXMLforAdditionalClasses" ), e );
  }
}
 
Example 8
Source File: LoggingPluginType.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
protected void registerXmlPlugins() throws KettlePluginException {
  for ( PluginFolderInterface folder : pluginFolders ) {

    if ( folder.isPluginXmlFolder() ) {
      List<FileObject> pluginXmlFiles = findPluginXmlFiles( folder.getFolder() );
      for ( FileObject file : pluginXmlFiles ) {

        try {
          Document document = XMLHandler.loadXMLFile( file );
          Node pluginNode = XMLHandler.getSubNode( document, "plugin" );
          if ( pluginNode != null ) {
            registerPluginFromXmlResource( pluginNode, KettleVFS.getFilename( file.getParent() ), this
              .getClass(), false, file.getParent().getURL() );
          }
        } catch ( Exception e ) {
          // We want to report this plugin.xml error, perhaps an XML typo or something like that...
          //
          log.logError( "Error found while reading logging plugin.xml file: " + file.getName().toString(), e );
        }
      }
    }
  }
}
 
Example 9
Source File: LogTablePluginType.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
protected void registerXmlPlugins() throws KettlePluginException {
  for ( PluginFolderInterface folder : pluginFolders ) {

    if ( folder.isPluginXmlFolder() ) {
      List<FileObject> pluginXmlFiles = findPluginXmlFiles( folder.getFolder() );
      for ( FileObject file : pluginXmlFiles ) {

        try {
          Document document = XMLHandler.loadXMLFile( file );
          Node pluginNode = XMLHandler.getSubNode( document, "plugin" );
          if ( pluginNode != null ) {
            registerPluginFromXmlResource( pluginNode, KettleVFS.getFilename( file.getParent() ), this
              .getClass(), false, file.getParent().getURL() );
          }
        } catch ( Exception e ) {
          // We want to report this plugin.xml error, perhaps an XML typo or something like that...
          //
          log.logError( "Error found while reading logging plugin.xml file: " + file.getName().toString(), e );
        }
      }
    }
  }
}
 
Example 10
Source File: PartitionerPluginType.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
protected void registerXmlPlugins() throws KettlePluginException {
  for ( PluginFolderInterface folder : pluginFolders ) {

    if ( folder.isPluginXmlFolder() ) {
      List<FileObject> pluginXmlFiles = findPluginXmlFiles( folder.getFolder() );
      for ( FileObject file : pluginXmlFiles ) {

        try {
          Document document = XMLHandler.loadXMLFile( file );
          Node pluginNode = XMLHandler.getSubNode( document, "partitioner-plugin" );
          if ( pluginNode != null ) {
            registerPluginFromXmlResource( pluginNode, KettleVFS.getFilename( file.getParent() ), this
              .getClass(), false, file.getParent().getURL() );
          }
        } catch ( Exception e ) {
          // We want to report this plugin.xml error, perhaps an XML typo or something like that...
          //
          log.logError(
            "Error found while reading partitioning plugin.xml file: " + file.getName().toString(), e );
        }
      }
    }
  }
}
 
Example 11
Source File: CartePluginType.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
protected void registerXmlPlugins() throws KettlePluginException {
  for ( PluginFolderInterface folder : pluginFolders ) {

    if ( folder.isPluginXmlFolder() ) {
      List<FileObject> pluginXmlFiles = findPluginXmlFiles( folder.getFolder() );
      for ( FileObject file : pluginXmlFiles ) {

        try {
          Document document = XMLHandler.loadXMLFile( file );
          Node pluginNode = XMLHandler.getSubNode( document, "plugin" );
          if ( pluginNode != null ) {
            registerPluginFromXmlResource( pluginNode, KettleVFS.getFilename( file.getParent() ), this
              .getClass(), false, file.getParent().getURL() );
          }
        } catch ( Exception e ) {
          // We want to report this plugin.xml error, perhaps an XML typo or
          // something like that...
          //
          log.logError( "Error found while reading step plugin.xml file: " + file.getName().toString(), e );
        }
      }
    }
  }
}
 
Example 12
Source File: StepPluginType.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
protected void registerXmlPlugins() throws KettlePluginException {
  for ( PluginFolderInterface folder : pluginFolders ) {

    if ( folder.isPluginXmlFolder() ) {
      List<FileObject> pluginXmlFiles = findPluginXmlFiles( folder.getFolder() );
      for ( FileObject file : pluginXmlFiles ) {

        try {
          Document document = XMLHandler.loadXMLFile( file );
          Node pluginNode = XMLHandler.getSubNode( document, "plugin" );
          if ( pluginNode != null ) {
            registerPluginFromXmlResource( pluginNode, KettleVFS.getFilename( file.getParent() ), this
              .getClass(), false, file.getParent().getURL() );
          }
        } catch ( Exception e ) {
          // We want to report this plugin.xml error, perhaps an XML typo or something like that...
          //
          log.logError( "Error found while reading step plugin.xml file: " + file.getName().toString(), e );
        }
      }
    }
  }
}
 
Example 13
Source File: MySQLBulkLoaderTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testFieldFormatType() throws KettleXMLException {
  MySQLBulkLoaderMeta lm = new MySQLBulkLoaderMeta();
  Document document = XMLHandler.loadXMLFile( this.getClass().getResourceAsStream( "step.xml" ) );
  IMetaStore metastore = null;
  Node stepNode = (Node) document.getDocumentElement();
  lm.loadXML( stepNode, Collections.EMPTY_LIST, metastore );
  int[] codes = lm.getFieldFormatType();
  assertEquals( 3, codes[0] );
  assertEquals( 4, codes[1] );
}
 
Example 14
Source File: SecurityService.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read the specified security file and get back the content as XML
 * 
 * @return the requested security reference information
 * @throws Exception
 *           in case something goes awry
 */
public Node getContentFromFile() throws Exception {
  try {
    Document doc = XMLHandler.loadXMLFile( filename );
    return XMLHandler.getSubNode( doc, "content" ); //$NON-NLS-1$
  } catch ( KettleXMLException e ) {
    throw new Exception(
        Messages.getString( "SecurityService.ERROR_0007_UNABLE_TO_GET_SECURITY_CONTENT", filename ), e ); //$NON-NLS-1$ 
  }
}
 
Example 15
Source File: KettleFileRepository.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public Node loadNodeFromXML( ObjectId id, String tag ) throws KettleException {
  try {
    // The object ID is the base name of the file in the Base directory folder
    //
    String filename = calcDirectoryName( null ) + id.getId();
    FileObject fileObject = KettleVFS.getFileObject( filename );
    Document document = XMLHandler.loadXMLFile( fileObject );
    Node node = XMLHandler.getSubNode( document, tag );

    return node;
  } catch ( Exception e ) {
    throw new KettleException( "Unable to load XML object from object with ID ["
      + id + "] and tag [" + tag + "]", e );
  }
}
 
Example 16
Source File: TextFileOutputIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the default setting of createparentfolder to true by creating a new TextFileOutputMeta using a sample XML
 * step (from a real transformation) and verifying that createparentfolder is true
 *
 * @throws Exception
 */
@Test
public void testTextFileOutput3() throws Exception {
  KettleEnvironment.init();

  // Create a new transformation from the same XML file
  //
  ByteArrayInputStream xmlStream = new ByteArrayInputStream( getXML1().getBytes( "UTF-8" ) );
  Document doc = XMLHandler.loadXMLFile( xmlStream, null, false, false );
  Node stepnode = XMLHandler.getSubNode( doc, "step" );
  TextFileOutputMeta textFileOutputMeta = new TextFileOutputMeta();
  textFileOutputMeta.loadXML( stepnode, null, (IMetaStore) null );
  assertTrue( textFileOutputMeta.isCreateParentFolder() );
}
 
Example 17
Source File: XMLInput.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private boolean openNextFile() {
  try {
    if ( data.filenr >= data.files.size() ) { // finished processing!
      if ( log.isDetailed() ) {
        logDetailed( BaseMessages.getString( PKG, "XMLInput.Log.FinishedProcessing" ) );
      }
      return false;
    }

    // Is this the last file?
    data.last_file = ( data.filenr == data.files.size() - 1 );
    data.file = data.files.get( data.filenr );

    logBasic( BaseMessages.getString( PKG, "XMLInput.Log.OpeningFile", data.file.toString() ) );

    // Move file pointer ahead!
    data.filenr++;

    String baseURI = this.environmentSubstitute( meta.getFileBaseURI() );
    if ( Utils.isEmpty( baseURI ) ) {
      baseURI = data.file.getParent().getName().getURI();
    }

    // Open the XML document
    data.document =
      XMLHandler.loadXMLFile( data.file, baseURI, meta.isIgnoreEntities(), meta.isNamespaceAware() );

    // Add this to the result file names...
    ResultFile resultFile =
      new ResultFile( ResultFile.FILE_TYPE_GENERAL, data.file, getTransMeta().getName(), getStepname() );
    resultFile.setComment( "File was read by an XML input step" );
    addResultFile( resultFile );

    if ( log.isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "XMLInput.Log.FileOpened", data.file.toString() ) );
    }

    // Position in the file...
    data.section = data.document;

    for ( int i = 0; i < meta.getInputPosition().length - 1; i++ ) {
      data.section = XMLHandler.getSubNode( data.section, meta.getInputPosition()[i] );
    }
    // Last element gets repeated: what's the name?
    data.itemElement = meta.getInputPosition()[meta.getInputPosition().length - 1];

    data.itemCount = XMLHandler.countNodes( data.section, data.itemElement );
    data.itemPosition = meta.getNrRowsToSkip();
  } catch ( Exception e ) {
    logError( BaseMessages.getString( PKG, "XMLInput.Log.UnableToOpenFile", "" + data.filenr, data.file
      .toString(), e.toString() ) );
    stopAll();
    setErrors( 1 );
    return false;
  }
  return true;
}
 
Example 18
Source File: XMLInputDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void get() {
  boolean finished = false;

  int elementsFound = 0;

  try {
    XMLInputMeta meta = new XMLInputMeta();
    getInfo( meta );

    // check if the path is given
    if ( !checkInputPositionsFilled( meta ) ) {
      return;
    }

    EnterNumberDialog dialog =
      new EnterNumberDialog(
        shell, 1000, "Number of elements to scan", "Enter the number of elements to scan (0=all)" );
    int maxElements = dialog.open();

    // OK, let's try to walk through the complete tree
    RowMetaInterface row = new RowMeta(); // no fields found...

    // Keep the list of positions
    List<XMLInputFieldPosition> path = new ArrayList<XMLInputFieldPosition>(); // ArrayList of XMLInputFieldPosition

    FileInputList inputList = meta.getFiles( transMeta );

    for ( int f = 0; f < inputList.getFiles().size() && !finished; f++ ) {
      // Open the file...
      Node rootNode =
        XMLHandler.loadXMLFile( inputList.getFile( f ), transMeta
          .environmentSubstitute( meta.getFileBaseURI() ), meta.isIgnoreEntities(), meta.isNamespaceAware() );

      // Position to the repeating item
      for ( int p = 0; rootNode != null && p < meta.getInputPosition().length - 1; p++ ) {
        rootNode = XMLHandler.getSubNode( rootNode, meta.getInputPosition()[p] );
      }

      if ( rootNode == null ) {
        // Specified node not found: return!
        return;
      }

      if ( meta.getInputPosition().length > 1 ) {
        // Count the number of rootnodes
        String itemElement = meta.getInputPosition()[meta.getInputPosition().length - 1];
        int nrItems = XMLHandler.countNodes( rootNode, itemElement );
        for ( int i = 0; i < nrItems && !finished; i++ ) {
          Node itemNode = XMLHandler.getSubNodeByNr( rootNode, itemElement, i, false );
          if ( i >= meta.getNrRowsToSkip() ) {
            getValues( itemNode, row, path, 0 );

            elementsFound++;
            if ( elementsFound >= maxElements && maxElements > 0 ) {
              finished = true;
            }
          }
        }
      } else {
        // Only search the root node
        //
        getValues( rootNode, row, path, 0 );

        elementsFound++;
        if ( elementsFound >= maxElements && maxElements > 0 ) {
          finished = true;
        }
      }
    }

    // System.out.println("Values found: "+row);

    // add the values to the grid...
    for ( int i = 0; i < row.size(); i++ ) {
      ValueMetaInterface v = row.getValueMeta( i );
      TableItem item = new TableItem( wFields.table, SWT.NONE );
      item.setText( 1, v.getName() );
      item.setText( 2, v.getTypeDesc() );
      item.setText( 11, v.getOrigin() );
    }

    wFields.removeEmptyRows();
    wFields.setRowNums();
    wFields.optWidth( true );
  } catch ( KettleException e ) {
    new ErrorDialog(
      shell, BaseMessages.getString( PKG, "XMLInputDialog.ErrorParsingData.DialogTitle" ), BaseMessages
        .getString( PKG, "XMLInputDialog.ErrorParsingData.DialogMessage" ), e );
  }
}
 
Example 19
Source File: JsonInputMetaTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private Node loadStep( String step ) throws KettleXMLException {
  Document document = XMLHandler.loadXMLFile( this.getClass().getResourceAsStream( step ) );
  Node stepNode = (Node) document.getDocumentElement();
  return stepNode;
}
 
Example 20
Source File: RegisterPackageServlet.java    From pentaho-kettle with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieve config xml, <code>xmlTag</code> from combined path of  <code>archiveUrl</code> and <code>fileName</code>.
 * @param archiveUrl root file path.
 * @param fileName xml configuration file at root of <code>archiveUrl</code>.
 * @param xmlTag xml root tag.
 * @return configuration node.
 * @throws KettleXMLException
 */
protected Node getConfigNode( String archiveUrl, String fileName, String xmlTag ) throws KettleXMLException {
  String configUrl = concat( archiveUrl, fileName );
  Document configDoc = XMLHandler.loadXMLFile( configUrl );
  return XMLHandler.getSubNode( configDoc, xmlTag );
}