org.pentaho.libformula.editor.function.FunctionDescription Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kettle-engine Show documentation
Show all versions of kettle-engine Show documentation
Container pom for Pentaho Data Integration modules
The newest version!
/*! ******************************************************************************
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2017 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/**
*
*/
package org.pentaho.libformula.editor.function;
import java.util.ArrayList;
import java.util.List;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.util.Utils;
import org.pentaho.di.core.xml.XMLHandler;
import org.w3c.dom.Node;
/**
* @author matt
*
*
*
*
*
* Text
* &
* Concatenate two strings.
* Text Left & Text Right
* Text
* None
* Concatenates two text (string) values. Due to the way conversion works, numbers are converted to
* strings. Note that this is equivalent to CONCATENATE(Left,Right).
* (Note: CONCATENATE is not yet available in libformula version 0.1.18.2)
*
* "Hi " & "there" "Hi there"
* 1 Simple concatenation.
* "H" & "" "H"
* 1 Concatenating an empty string produces no change.
* -5&"b" -5b
* 1 Unary - has higher precedence than &
* 3&2-1 31
* 1 Binary - has higher precedence than &
*
*
*
*/
public class FunctionDescription {
public static final String XML_TAG = "function";
private String category;
private String name;
private String description;
private String syntax;
private String returns;
private String constraints;
private String semantics;
private List functionExamples;
/**
* @param category
* @param name
* @param description
* @param syntax
* @param returns
* @param constraints
* @param semantics
* @param functionExamples
*/
public FunctionDescription( String category, String name, String description, String syntax, String returns,
String constraints, String semantics, List functionExamples ) {
this.category = category;
this.name = name;
this.description = description;
this.syntax = syntax;
this.returns = returns;
this.constraints = constraints;
this.semantics = semantics;
this.functionExamples = functionExamples;
}
public FunctionDescription( Node node ) {
this.category = XMLHandler.getTagValue( node, "category" );
this.name = XMLHandler.getTagValue( node, "name" );
this.description = XMLHandler.getTagValue( node, "description" );
this.syntax = XMLHandler.getTagValue( node, "syntax" );
this.returns = XMLHandler.getTagValue( node, "returns" );
this.constraints = XMLHandler.getTagValue( node, "constraints" );
this.semantics = XMLHandler.getTagValue( node, "semantics" );
this.functionExamples = new ArrayList();
Node examplesNode = XMLHandler.getSubNode( node, "examples" );
int nrExamples = XMLHandler.countNodes( examplesNode, FunctionExample.XML_TAG );
for ( int i = 0; i < nrExamples; i++ ) {
Node exampleNode = XMLHandler.getSubNodeByNr( examplesNode, FunctionExample.XML_TAG, i );
this.functionExamples.add( new FunctionExample( exampleNode ) );
}
}
/**
* @return the category
*/
public String getCategory() {
return category;
}
/**
* @param category
* the category to set
*/
public void setCategory( String category ) {
this.category = category;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName( String name ) {
this.name = name;
}
/**
* @return the description
*/
public String getDescription() {
return description;
}
/**
* @param description
* the description to set
*/
public void setDescription( String description ) {
this.description = description;
}
/**
* @return the syntax
*/
public String getSyntax() {
return syntax;
}
/**
* @param syntax
* the syntax to set
*/
public void setSyntax( String syntax ) {
this.syntax = syntax;
}
/**
* @return the returns
*/
public String getReturns() {
return returns;
}
/**
* @param returns
* the returns to set
*/
public void setReturns( String returns ) {
this.returns = returns;
}
/**
* @return the constraints
*/
public String getConstraints() {
return constraints;
}
/**
* @param constraints
* the constraints to set
*/
public void setConstraints( String constraints ) {
this.constraints = constraints;
}
/**
* @return the semantics
*/
public String getSemantics() {
return semantics;
}
/**
* @param semantics
* the semantics to set
*/
public void setSemantics( String semantics ) {
this.semantics = semantics;
}
/**
* @return the functionExamples
*/
public List getFunctionExamples() {
return functionExamples;
}
/**
* @param functionExamples
* the functionExamples to set
*/
public void setFunctionExamples( List functionExamples ) {
this.functionExamples = functionExamples;
}
/**
* Create a text version of a report on this function
*
* @return
*/
public String getHtmlReport() {
StringBuilder report = new StringBuilder( 200 );
// The function name on top
//
report.append( "" ).append( name ).append( "
" ).append( Const.CR );
// Then the description
//
report.append( "Description: " ).append( description ).append( "
" ).append( Const.CR );
// Syntax
//
if ( !Utils.isEmpty( syntax ) ) {
report.append( "Syntax: " ).append( syntax ).append( "
" ).append( Const.CR );
}
// Returns
//
if ( !Utils.isEmpty( returns ) ) {
report.append( "Returns: " ).append( returns ).append( "
" ).append( Const.CR );
}
// Constraints
//
if ( !Utils.isEmpty( constraints ) ) {
report.append( "Constraints: " ).append( constraints ).append( "
" ).append( Const.CR );
}
// Semantics
//
if ( !Utils.isEmpty( semantics ) ) {
report.append( "Semantics: " ).append( semantics ).append( "
" ).append( Const.CR );
}
// Examples
//
if ( functionExamples.size() > 0 ) {
report.append( Const.CR );
report.append( "
Examples: " ).append( Const.CR );
report.append( "
" );
report.append( "" );
report.append( "Expression " );
report.append( "Result " );
report.append( "Comment " );
report.append( " " );
for ( FunctionExample example : functionExamples ) {
// "Hi " & "there" "Hi there" 1
// Simple concatenation.
report.append( "" );
report.append( "" ).append( example.getExpression() ).append( " " );
report.append( "" ).append( example.getResult() ).append( " " );
if ( !Utils.isEmpty( example.getComment() ) ) {
report.append( "" ).append( example.getComment() ).append( " " );
}
report.append( " " );
report.append( Const.CR );
}
report.append( "
" );
}
return report.toString();
}
}