Java Code Examples for org.pentaho.di.core.xml.XMLHandler#loadXMLString()
The following examples show how to use
org.pentaho.di.core.xml.XMLHandler#loadXMLString() .
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: KettleBeamUtil.java From kettle-beam with Apache License 2.0 | 6 votes |
public static void loadStepMetadataFromXml( String stepname, StepMetaInterface stepMetaInterface, String stepMetaInterfaceXml, IMetaStore metaStore ) throws KettleException { synchronized ( object ) { Document stepDocument = XMLHandler.loadXMLString( stepMetaInterfaceXml ); if ( stepDocument == null ) { throw new KettleException( "Unable to load step XML document from : " + stepMetaInterfaceXml ); } Node stepNode = XMLHandler.getSubNode( stepDocument, StepMeta.XML_TAG ); if ( stepNode == null ) { throw new KettleException( "Unable to find XML tag " + StepMeta.XML_TAG + " from : " + stepMetaInterfaceXml ); } try { stepMetaInterface.loadXML( stepNode, new ArrayList<>(), metaStore ); } catch ( Exception e ) { throw new KettleException( "There was an error loading step metadata information (loadXML) for step '" + stepname + "'", e ); } finally { XMLHandlerCache.getInstance().clear(); } } }
Example 2
Source File: RepositoryImporter.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Override public boolean jobElementRead( String xml, RepositoryImportFeedbackInterface feedback ) { try { Document doc = XMLHandler.loadXMLString( getOrCreateDb(), xml ); Node jobNode = XMLHandler.getSubNode( doc, RepositoryExportSaxParser.STRING_JOB ); if ( !importJob( jobNode, feedback ) ) { return false; } jobNumber++; } catch ( Exception e ) { // Some unexpected error occurred during job import // This is usually a problem with a missing plugin or something // like that... // showError( BaseMessages.getString( PKG, "RepositoryImporter.UnexpectedErrorDuringJobImport.Title" ), BaseMessages .getString( PKG, "RepositoryImporter.UnexpectedErrorDuringJobImport.Message" ), e ); if ( !feedback.askContinueOnErrorQuestion( BaseMessages.getString( PKG, "RepositoryImporter.DoYouWantToContinue.Title" ), BaseMessages.getString( PKG, "RepositoryImporter.DoYouWantToContinue.Message" ) ) ) { return false; } } return true; }
Example 3
Source File: Wsdl.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private Definition readWsdl( WSDLReader wsdlReader, String uri, String username, String password ) throws WSDLException, KettleException, AuthenticationException { try { HTTPProtocol http = new HTTPProtocol(); Document doc = XMLHandler.loadXMLString( http.get( wsdlURI.toString(), username, password ), true, false ); if ( doc != null ) { return ( wsdlReader.readWSDL( doc.getBaseURI(), doc ) ); } else { throw new KettleException( "Unable to get document." ); } } catch ( MalformedURLException mue ) { throw new KettleException( mue ); } catch ( AuthenticationException ae ) { // re-throw this. If not IOException seems to catch it throw ae; } catch ( IOException ioe ) { throw new KettleException( ioe ); } }
Example 4
Source File: ConceptPropertyAggregationList.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
public static List<AggregationSettings> fromXML( String value ) throws Exception { try { Document doc = XMLHandler.loadXMLString( value ); List<AggregationSettings> aggSettings = new ArrayList<AggregationSettings>(); Node node = XMLHandler.getSubNode( doc, "aggregationlist" ); //$NON-NLS-1$ int nrAggs = XMLHandler.countNodes( node, "aggregation" ); //$NON-NLS-1$ for ( int i = 0; i < nrAggs; i++ ) { Node aggNode = XMLHandler.getSubNodeByNr( node, "aggregation", i ); //$NON-NLS-1$ String type = XMLHandler.getNodeValue( aggNode ); //$NON-NLS-1$ if ( type != null ) { AggregationSettings setting = AggregationSettings.getType( type ); if ( setting != null ) { aggSettings.add( setting ); } } } if ( aggSettings.size() != 0 ) { return aggSettings; } else { return null; } } catch ( Exception e ) { throw new Exception( Messages.getString( "ConceptPropertyAggregationList.ERROR_0001_CANT_CREATE_AGGLIST_OBJECT" ), e ); //$NON-NLS-1$ } }
Example 5
Source File: RowMetaTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void testRowMetaInitializingFromXmlNode() throws Exception { String testXmlNode; try ( InputStream in = RowMetaTest.class.getResourceAsStream( "rowMetaNode.xml" ) ) { testXmlNode = IOUtils.toString( in ); } Document xmlDoc = XMLHandler.loadXMLString( testXmlNode ); System.setProperty( Const.KETTLE_XML_EMPTY_TAG_YIELDS_EMPTY_VALUE, "N" ); RowMeta rowMeta = spy( new RowMeta( xmlDoc.getFirstChild() ) ); assertEquals( 2, rowMeta.getValueMetaList().size() ); ValueMetaInterface valueMeta = rowMeta.getValueMeta( 0 ); assertTrue( valueMeta instanceof ValueMetaDate ); assertEquals( "testDate", valueMeta.getName() ); assertNull( valueMeta.getConversionMask() ); valueMeta = rowMeta.getValueMeta( 1 ); assertTrue( valueMeta instanceof ValueMetaTimestamp ); assertEquals( "testTimestamp", valueMeta.getName() ); assertEquals( "yyyy/MM/dd HH:mm:ss.000000000", valueMeta.getConversionMask() ); }
Example 6
Source File: CarteIT.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testAddTransServlet() { HttpTester request = new HttpTester(); HttpTester response = new HttpTester(); request.setMethod( "GET" ); request.setHeader( "Host", "tester" ); request.setURI( RegisterTransServlet.CONTEXT_PATH + "?xml=Y" ); request.setVersion( "HTTP/1.0" ); try { TransExecutionConfiguration transExecConfig = new TransExecutionConfiguration(); Trans trans = CarteIT.generateTestTransformation(); TransConfiguration transConfig = new TransConfiguration( trans.getTransMeta(), transExecConfig ); request.setContent( transConfig.getXML() ); response.parse( tester.getResponses( request.generate() ) ); Document document = XMLHandler.loadXMLString( response.getContent() ); NodeList nodes = document.getElementsByTagName( "result" ); Assert.assertEquals( 1, nodes.getLength() ); Assert.assertEquals( WebResult.STRING_OK, nodes.item( 0 ).getTextContent() ); SlaveServerStatus status = getStatus(); SlaveServerTransStatus transStatus = status.findTransStatus( trans.getName(), null ); // find the first one Assert.assertNotNull( transStatus ); Assert.assertFalse( transStatus.isPaused() ); Assert.assertFalse( transStatus.isRunning() ); } catch ( Exception ex ) { ex.printStackTrace(); Assert.fail( ex.getMessage() ); } }
Example 7
Source File: MQTTConsumerMetaTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public static MQTTConsumerMeta fromXml( String metaXml ) { Document doc; try { doc = XMLHandler.loadXMLString( "<step>" + metaXml + "</step>" ); Node stepNode = XMLHandler.getSubNode( doc, "step" ); MQTTConsumerMeta mqttConsumerMeta = new MQTTConsumerMeta(); mqttConsumerMeta.loadXML( stepNode, emptyList(), (IMetaStore) null ); return mqttConsumerMeta; } catch ( KettleXMLException e ) { throw new RuntimeException( e ); } }
Example 8
Source File: SlaveServer.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public long getNextSlaveSequenceValue( String slaveSequenceName, long incrementValue ) throws KettleException { try { String xml = execService( NextSequenceValueServlet.CONTEXT_PATH + "/" + "?" + NextSequenceValueServlet.PARAM_NAME + "=" + URLEncoder.encode( slaveSequenceName, "UTF-8" ) + "&" + NextSequenceValueServlet.PARAM_INCREMENT + "=" + Long.toString( incrementValue ) ); Document doc = XMLHandler.loadXMLString( xml ); Node seqNode = XMLHandler.getSubNode( doc, NextSequenceValueServlet.XML_TAG ); String nextValueString = XMLHandler.getTagValue( seqNode, NextSequenceValueServlet.XML_TAG_VALUE ); String errorString = XMLHandler.getTagValue( seqNode, NextSequenceValueServlet.XML_TAG_ERROR ); if ( !Utils.isEmpty( errorString ) ) { throw new KettleException( errorString ); } if ( Utils.isEmpty( nextValueString ) ) { throw new KettleException( "No value retrieved from slave sequence '" + slaveSequenceName + "' on slave " + toString() ); } long nextValue = Const.toLong( nextValueString, Long.MIN_VALUE ); if ( nextValue == Long.MIN_VALUE ) { throw new KettleException( "Incorrect value '" + nextValueString + "' retrieved from slave sequence '" + slaveSequenceName + "' on slave " + toString() ); } return nextValue; } catch ( Exception e ) { throw new KettleException( "There was a problem retrieving a next sequence value from slave sequence '" + slaveSequenceName + "' on slave " + toString(), e ); } }
Example 9
Source File: CarteIT.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testStartTransServlet() { // add our test transformation testAddTransServlet(); HttpTester request = new HttpTester(); HttpTester response = new HttpTester(); request.setMethod( "GET" ); request.setHeader( "Host", "tester" ); request.setURI( StartTransServlet.CONTEXT_PATH + "?xml=Y&name=CarteUnitTest" ); request.setVersion( "HTTP/1.0" ); try { response.parse( tester.getResponses( request.generate() ) ); Document document = XMLHandler.loadXMLString( response.getContent() ); NodeList nodes = document.getElementsByTagName( "result" ); Assert.assertEquals( 1, nodes.getLength() ); Assert.assertEquals( WebResult.STRING_OK, nodes.item( 0 ).getTextContent() ); SlaveServerStatus status = getStatus(); SlaveServerTransStatus transStatus = status.findTransStatus( "CarteUnitTest", null ); Assert.assertNotNull( transStatus ); Assert.assertFalse( transStatus.isPaused() ); Assert.assertTrue( transStatus.isRunning() ); } catch ( Exception ex ) { ex.printStackTrace(); Assert.fail( ex.getMessage() ); } }
Example 10
Source File: ScriptValuesHelp.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private static void xparseXmlFile( String strFileName ) throws KettleXMLException { try { InputStream is = ScriptValuesHelp.class.getResourceAsStream( strFileName ); int c; StringBuilder buffer = new StringBuilder(); while ( ( c = is.read() ) != -1 ) { buffer.append( (char) c ); } is.close(); dom = XMLHandler.loadXMLString( buffer.toString() ); } catch ( Exception e ) { throw new KettleXMLException( "Unable to read script values help file from file [" + strFileName + "]", e ); } }
Example 11
Source File: StepMeta.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public static StepMeta fromXml( String metaXml ) { Document doc; try { doc = XMLHandler.loadXMLString( metaXml ); Node stepNode = XMLHandler.getSubNode( doc, "step" ); return new StepMeta( stepNode, Collections.emptyList(), (IMetaStore) null ); } catch ( KettleXMLException | KettlePluginLoaderException e ) { throw new RuntimeException( e ); } }
Example 12
Source File: StepStatus.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public StepStatus fromXML( String xml ) throws KettleException { Document document = XMLHandler.loadXMLString( xml ); return new StepStatus( XMLHandler.getSubNode( document, XML_TAG ) ); }
Example 13
Source File: RowLevelSecurity.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 4 votes |
public static RowLevelSecurity fromXML( String value ) throws Exception { Document doc = XMLHandler.loadXMLString( value ); return new RowLevelSecurity( XMLHandler.getSubNode( doc, ELEM_ROW_LEVEL_SECURITY ) ); //$NON-NLS-1$ }
Example 14
Source File: SlaveServerTransStatus.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public static SlaveServerTransStatus fromXML( String xml ) throws KettleException { Document document = XMLHandler.loadXMLString( xml ); SlaveServerTransStatus status = new SlaveServerTransStatus( XMLHandler.getSubNode( document, XML_TAG ) ); return status; }
Example 15
Source File: SlaveServerJobStatus.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public static SlaveServerJobStatus fromXML( String xml ) throws KettleException { Document document = XMLHandler.loadXMLString( xml ); SlaveServerJobStatus status = new SlaveServerJobStatus( XMLHandler.getSubNode( document, XML_TAG ) ); return status; }
Example 16
Source File: SlaveServerConfigTest.java From pentaho-kettle with Apache License 2.0 | 4 votes |
private Node getConfigNode( String configString ) throws KettleXMLException { Document document = XMLHandler.loadXMLString( configString ); Node configNode = XMLHandler.getSubNode( document, SlaveServerConfig.XML_TAG ); return configNode; }
Example 17
Source File: HBaseValueMetaInterfaceImplTest.java From pentaho-hadoop-shims with Apache License 2.0 | 4 votes |
private Document loadDocumentFromString( StringBuilder result ) throws KettleXMLException, ParserConfigurationException { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); Document document = XMLHandler.loadXMLString( docBuilderFactory.newDocumentBuilder(), result.toString() ); return document; }
Example 18
Source File: TableOutputMetaTest.java From pentaho-kettle with Apache License 2.0 | 4 votes |
private Node getTestNode() throws KettleXMLException { String xml = " <step>\n" + " <name>Table output</name>\n" + " <type>TableOutput</type>\n" + " <description/>\n" + " <distribute>Y</distribute>\n" + " <custom_distribution/>\n" + " <copies>1</copies>\n" + " <partitioning>\n" + " <method>none</method>\n" + " <schema_name/>\n" + " </partitioning>\n" + " <connection>local postgres</connection>\n" + " <schema>public</schema>\n" + " <table>sales_csv</table>\n" + " <commit>1000</commit>\n" + " <truncate>Y</truncate>\n" + " <ignore_errors>N</ignore_errors>\n" + " <use_batch>Y</use_batch>\n" + " <specify_fields>Y</specify_fields>\n" + " <partitioning_enabled>N</partitioning_enabled>\n" + " <partitioning_field/>\n" + " <partitioning_daily>N</partitioning_daily>\n" + " <partitioning_monthly>Y</partitioning_monthly>\n" + " <tablename_in_field>N</tablename_in_field>\n" + " <tablename_field/>\n" + " <tablename_in_table>Y</tablename_in_table>\n" + " <return_keys>N</return_keys>\n" + " <return_field/>\n" + " <fields>\n" + " <field>\n" + " <column_name>ORDERNUMBER</column_name>\n" + " <stream_name>ORDERNUMBER</stream_name>\n" + " </field>\n" + " <field>\n" + " <column_name>QUANTITYORDERED</column_name>\n" + " <stream_name>QUANTITYORDERED</stream_name>\n" + " </field>\n" + " <field>\n" + " <column_name>PRICEEACH</column_name>\n" + " <stream_name>PRICEEACH</stream_name>\n" + " </field>\n" + " </fields>\n" + " <cluster_schema/>\n" + " <remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>\n" + " <xloc>368</xloc>\n" + " <yloc>64</yloc>\n" + " <draw>Y</draw>\n" + " </GUI>\n" + " </step>\n"; return XMLHandler.loadXMLString( xml, "step" ); }
Example 19
Source File: ColumnFilterTest.java From pentaho-hadoop-shims with Apache License 2.0 | 4 votes |
@Test public void testGetFilter() throws Exception { ColumnFilter cf = getCF(); Node node = XMLHandler.loadXMLString( XML_NODE, "filter" ); assertTrue( equalsCF( cf, getFilter( node ) ) ); }
Example 20
Source File: SpoonSlave.java From pentaho-kettle with Apache License 2.0 | 4 votes |
protected void sniff() { TreeItem[] ti = wTree.getSelection(); if ( ti.length == 1 ) { TreeItem treeItem = ti[0]; String[] path = ConstUI.getTreeStrings( treeItem ); // Make sure we're positioned on a step if ( path.length <= 2 ) { return; } String name = path[1]; String step = path[2]; String copy = treeItem.getText( 1 ); EnterNumberDialog numberDialog = new EnterNumberDialog( shell, PropsUI.getInstance().getDefaultPreviewSize(), BaseMessages.getString( PKG, "SpoonSlave.SniffSizeQuestion.Title" ), BaseMessages.getString( PKG, "SpoonSlave.SniffSizeQuestion.Message" ) ); int lines = numberDialog.open(); if ( lines <= 0 ) { return; } EnterSelectionDialog selectionDialog = new EnterSelectionDialog( shell, new String[] { SniffStepServlet.TYPE_INPUT, SniffStepServlet.TYPE_OUTPUT, }, BaseMessages.getString( PKG, "SpoonSlave.SniffTypeQuestion.Title" ), BaseMessages.getString( PKG, "SpoonSlave.SniffTypeQuestion.Message" ) ); String type = selectionDialog.open( 1 ); if ( type == null ) { return; } try { String xml = slaveServer.sniffStep( name, step, copy, lines, type ); Document doc = XMLHandler.loadXMLString( xml ); Node node = XMLHandler.getSubNode( doc, SniffStepServlet.XML_TAG ); Node metaNode = XMLHandler.getSubNode( node, RowMeta.XML_META_TAG ); RowMetaInterface rowMeta = new RowMeta( metaNode ); int nrRows = Const.toInt( XMLHandler.getTagValue( node, "nr_rows" ), 0 ); List<Object[]> rowBuffer = new ArrayList<Object[]>(); for ( int i = 0; i < nrRows; i++ ) { Node dataNode = XMLHandler.getSubNodeByNr( node, RowMeta.XML_DATA_TAG, i ); Object[] row = rowMeta.getRow( dataNode ); rowBuffer.add( row ); } PreviewRowsDialog prd = new PreviewRowsDialog( shell, new Variables(), SWT.NONE, step, rowMeta, rowBuffer ); prd.open(); } catch ( Exception e ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "SpoonSlave.ErrorSniffingStep.Title" ), BaseMessages.getString( PKG, "SpoonSlave.ErrorSniffingStep.Message" ), e ); } } }