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

The following examples show how to use org.pentaho.di.core.xml.XMLHandler#getTagAttribute() . 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: 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 2
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 3
Source File: BaseStepMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Load step attributes.
 *
 * @throws KettleException the kettle exception
 */
protected void loadStepAttributes() throws KettleException {
  try ( InputStream inputStream = getClass().getResourceAsStream( STEP_ATTRIBUTES_FILE ) ) {
    if ( inputStream != null ) {
      Document document = XMLHandler.loadXMLFile( inputStream );
      Node attrsNode = XMLHandler.getSubNode( document, "attributes" );
      List<Node> nodes = XMLHandler.getNodes( attrsNode, "attribute" );
      attributes = new ArrayList<KettleAttributeInterface>();
      for ( Node node : nodes ) {
        String key = XMLHandler.getTagAttribute( node, "id" );
        String xmlCode = XMLHandler.getTagValue( node, "xmlcode" );
        String repCode = XMLHandler.getTagValue( node, "repcode" );
        String description = XMLHandler.getTagValue( node, "description" );
        String tooltip = XMLHandler.getTagValue( node, "tooltip" );
        int valueType = ValueMetaFactory.getIdForValueMeta( XMLHandler.getTagValue( node, "valuetype" ) );
        String parentId = XMLHandler.getTagValue( node, "parentid" );

        KettleAttribute attribute = new KettleAttribute( key, xmlCode, repCode, description, tooltip, valueType,
          findParent( attributes, parentId ) );
        attributes.add( attribute );
      }
    }
  } catch ( Exception e ) {
    throw new KettleException( "Unable to load file " + STEP_ATTRIBUTES_FILE, e );
  }
}
 
Example 4
Source File: BasePluginType.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
protected Map<String, String> readPluginLocale( Node pluginNode, String localizedTag, String translationTag ) {
  Map<String, String> map = new HashMap<>();

  Node locTipsNode = XMLHandler.getSubNode( pluginNode, localizedTag );
  int nrLocTips = XMLHandler.countNodes( locTipsNode, translationTag );
  for ( int j = 0; j < nrLocTips; j++ ) {
    Node locTipNode = XMLHandler.getSubNodeByNr( locTipsNode, translationTag, j );
    if ( locTipNode != null ) {
      String locale = XMLHandler.getTagAttribute( locTipNode, "locale" );
      String locTip = XMLHandler.getNodeValue( locTipNode );

      if ( !Utils.isEmpty( locale ) && !Utils.isEmpty( locTip ) ) {
        map.put( locale.toLowerCase(), locTip );
      }
    }
  }

  return map;
}
 
Example 5
Source File: BasePluginType.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
protected String getTagOrAttribute( Node pluginNode, String tag ) {
  String string = XMLHandler.getTagValue( pluginNode, tag );
  if ( string == null ) {
    string = XMLHandler.getTagAttribute( pluginNode, tag );
  }
  return string;
}
 
Example 6
Source File: MessagesSourceCrawler.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void addLabelOccurrences( String sourceFolder, FileObject fileObject, NodeList nodeList,
                                  String keyPrefix, String tag, String attribute, String defaultPackage,
                                  List<SourceCrawlerPackageException> packageExcpeptions ) throws Exception {
  if ( nodeList == null ) {
    return;
  }

  TransformerFactory transformerFactory = TransformerFactory.newInstance();
  Transformer transformer = transformerFactory.newTransformer();
  transformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, YES );
  transformer.setOutputProperty( OutputKeys.INDENT, YES );

  for ( int i = 0; i < nodeList.getLength(); i++ ) {
    Node node = nodeList.item( i );
    String labelString = null;

    if ( !Utils.isEmpty( attribute ) ) {
      labelString = XMLHandler.getTagAttribute( node, attribute );
    } else if ( !Utils.isEmpty( tag ) ) {
      labelString = XMLHandler.getTagValue( node, tag );
    }

    if ( labelString != null && labelString.startsWith( DOLLAR_SIGN ) ) {
      // just removed ${} around the key
      String key = labelString.substring( 2, labelString.length() - 1 ).trim();

      String messagesPackage = defaultPackage;
      for ( SourceCrawlerPackageException packageException : packageExcpeptions ) {
        if ( key.startsWith( packageException.getStartsWith() ) ) {
          messagesPackage = packageException.getPackageName();
        }
      }

      StringWriter bodyXML = new StringWriter();
      transformer.transform( new DOMSource( node ), new StreamResult( bodyXML ) );
      String xml = bodyXML.getBuffer().toString();

      KeyOccurrence keyOccurrence =
        new KeyOccurrence( fileObject, sourceFolder, messagesPackage, -1, -1, key, QUESTION_MARK, xml );
      addKeyOccurrence( keyOccurrence );
    }
  }
}
 
Example 7
Source File: BasePluginType.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
protected PluginInterface registerPluginFromXmlResource( Node pluginNode, String path,
  Class<? extends PluginTypeInterface> pluginType, boolean nativePlugin, URL pluginFolder ) throws KettlePluginException {
  try {

    String idAttr = XMLHandler.getTagAttribute( pluginNode, "id" );
    String description = getTagOrAttribute( pluginNode, "description" );
    String iconfile = getTagOrAttribute( pluginNode, "iconfile" );
    String tooltip = getTagOrAttribute( pluginNode, "tooltip" );
    String category = getTagOrAttribute( pluginNode, "category" );
    String classname = getTagOrAttribute( pluginNode, "classname" );
    String errorHelpfile = getTagOrAttribute( pluginNode, "errorhelpfile" );
    String documentationUrl = getTagOrAttribute( pluginNode, "documentation_url" );
    String casesUrl = getTagOrAttribute( pluginNode, "cases_url" );
    String forumUrl = getTagOrAttribute( pluginNode, "forum_url" );
    String suggestion = getTagOrAttribute( pluginNode, "suggestion" );

    Node libsnode = XMLHandler.getSubNode( pluginNode, "libraries" );
    int nrlibs = XMLHandler.countNodes( libsnode, "library" );

    List<String> jarFiles = new ArrayList<>();
    if ( path != null ) {
      for ( int j = 0; j < nrlibs; j++ ) {
        Node libnode = XMLHandler.getSubNodeByNr( libsnode, "library", j );
        String jarfile = XMLHandler.getTagAttribute( libnode, "name" );
        jarFiles.add( new File( path + Const.FILE_SEPARATOR + jarfile ).getAbsolutePath() );
      }
    }

    // Localized categories, descriptions and tool tips
    //
    Map<String, String> localizedCategories = readPluginLocale( pluginNode, "localized_category", "category" );
    category = getAlternativeTranslation( category, localizedCategories );

    Map<String, String> localDescriptions =
      readPluginLocale( pluginNode, "localized_description", "description" );
    description = getAlternativeTranslation( description, localDescriptions );
    description += addDeprecation( category );

    suggestion = getAlternativeTranslation( suggestion, localDescriptions );

    Map<String, String> localizedTooltips = readPluginLocale( pluginNode, "localized_tooltip", "tooltip" );
    tooltip = getAlternativeTranslation( tooltip, localizedTooltips );

    String iconFilename = ( path == null ) ? iconfile : path + Const.FILE_SEPARATOR + iconfile;
    String errorHelpFileFull = errorHelpfile;
    if ( !Utils.isEmpty( errorHelpfile ) ) {
      errorHelpFileFull = ( path == null ) ? errorHelpfile : path + Const.FILE_SEPARATOR + errorHelpfile;
    }

    Map<Class<?>, String> classMap = new HashMap<>();

    PluginMainClassType mainClassTypesAnnotation = pluginType.getAnnotation( PluginMainClassType.class );
    classMap.put( mainClassTypesAnnotation.value(), classname );

    // process annotated extra types
    PluginExtraClassTypes classTypesAnnotation = pluginType.getAnnotation( PluginExtraClassTypes.class );
    if ( classTypesAnnotation != null ) {
      for ( int i = 0; i < classTypesAnnotation.classTypes().length; i++ ) {
        Class<?> classType = classTypesAnnotation.classTypes()[i];
        String className = getTagOrAttribute( pluginNode, classTypesAnnotation.xmlNodeNames()[i] );

        classMap.put( classType, className );
      }
    }

    // process extra types added at runtime
    Map<Class<?>, String> objectMap = getAdditionalRuntimeObjectTypes();
    for ( Map.Entry<Class<?>, String> entry : objectMap.entrySet() ) {
      String clzName = getTagOrAttribute( pluginNode, entry.getValue() );
      classMap.put( entry.getKey(), clzName );
    }

    PluginInterface pluginInterface =
      new Plugin(
        idAttr.split( "," ), pluginType, mainClassTypesAnnotation.value(), category, description, tooltip,
        iconFilename, false, nativePlugin, classMap, jarFiles, errorHelpFileFull, pluginFolder,
        documentationUrl, casesUrl, forumUrl, suggestion );
    registry.registerPlugin( pluginType, pluginInterface );

    return pluginInterface;
  } catch ( Exception e ) {
    throw new KettlePluginException( BaseMessages.getString(
      PKG, "BasePluginType.RuntimeError.UnableToReadPluginXML.PLUGIN0001" ), e );
  }
}