List of usage examples for org.apache.commons.vfs FileObject getName
public FileName getName();
From source file:org.pentaho.di.resource.ResourceUtil.java
/** * Serializes the referenced resource export interface (Job, Transformation, Mapping, Step, Job Entry, etc) to a ZIP * file.// ww w . j av a 2 s. c om * * @param zipFilename * The ZIP file to put the content in * @param resourceExportInterface * the interface to serialize * @param space * the space to use for variable replacement * @param repository * the repository to load objects from (or null if not used) * @param injectXML * The XML to inject into the resulting ZIP archive (optional, can be null) * @param injectFilename * The name of the file for the XML to inject in the ZIP archive (optional, can be null) * @return The full VFS filename reference to the serialized export interface XML file in the ZIP archive. * @throws KettleException * in case anything goes wrong during serialization */ public static final TopLevelResource serializeResourceExportInterface(String zipFilename, ResourceExportInterface resourceExportInterface, VariableSpace space, Repository repository, IMetaStore metaStore, String injectXML, String injectFilename) throws KettleException { ZipOutputStream out = null; try { Map<String, ResourceDefinition> definitions = new HashMap<String, ResourceDefinition>(); // In case we want to add an extra pay-load to the exported ZIP file... // if (injectXML != null) { ResourceDefinition resourceDefinition = new ResourceDefinition(injectFilename, injectXML); definitions.put(injectFilename, resourceDefinition); } ResourceNamingInterface namingInterface = new SequenceResourceNaming(); String topLevelResource = resourceExportInterface.exportResources(space, definitions, namingInterface, repository, metaStore); if (topLevelResource != null && !definitions.isEmpty()) { // Create the ZIP file... // FileObject fileObject = KettleVFS.getFileObject(zipFilename, space); // Store the XML in the definitions in a ZIP file... // out = new ZipOutputStream(KettleVFS.getOutputStream(fileObject, false)); for (String filename : definitions.keySet()) { ResourceDefinition resourceDefinition = definitions.get(filename); ZipEntry zipEntry = new ZipEntry(resourceDefinition.getFilename()); String comment = BaseMessages.getString(PKG, "ResourceUtil.SerializeResourceExportInterface.ZipEntryComment.OriginatingFile", filename, Const.NVL(resourceDefinition.getOrigin(), "-")); zipEntry.setComment(comment); out.putNextEntry(zipEntry); out.write(resourceDefinition.getContent().getBytes()); out.closeEntry(); } String zipURL = fileObject.getName().toString(); return new TopLevelResource(topLevelResource, zipURL, "zip:" + zipURL + "!" + topLevelResource); } else { throw new KettleException( BaseMessages.getString(PKG, "ResourceUtil.Exception.NoResourcesFoundToExport")); } } catch (Exception e) { throw new KettleException(BaseMessages.getString(PKG, "ResourceUtil.Exception.ErrorSerializingExportInterface", resourceExportInterface.toString()), e); } finally { if (out != null) { try { out.close(); } catch (IOException e) { throw new KettleException(BaseMessages.getString(PKG, "ResourceUtil.Exception.ErrorClosingZipStream", zipFilename)); } } } }
From source file:org.pentaho.di.resource.SimpleResourceNaming.java
public String nameResource(FileObject fileObject, VariableSpace space, boolean includeFileName) throws FileSystemException { if (includeFileName) { return handleDataFile(fileObject.getName().getBaseName(), fileObject.getParent().getURL().toString(), ""); } else {// w w w . j a v a 2 s .c om return handleDataFile("", fileObject.getURL().toString(), ""); } }
From source file:org.pentaho.di.scoring.WekaScoringDialog.java
/** * Open the dialog//from w ww . j a va 2s . c o m * * @return the step name */ public String open() { // Make sure that all Weka packages have been loaded! weka.core.WekaPackageManager.loadPackages(false); Shell parent = getParent(); Display display = parent.getDisplay(); shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX); props.setLook(shell); setShellImage(shell, m_currentMeta); // used to listen to a text field (m_wStepname) ModifyListener lsMod = new ModifyListener() { public void modifyText(ModifyEvent e) { m_currentMeta.setChanged(); } }; changed = m_currentMeta.hasChanged(); FormLayout formLayout = new FormLayout(); formLayout.marginWidth = Const.FORM_MARGIN; formLayout.marginHeight = Const.FORM_MARGIN; shell.setLayout(formLayout); shell.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Shell.Title")); //$NON-NLS-1$ int middle = props.getMiddlePct(); int margin = Const.MARGIN; // Stepname line m_wlStepname = new Label(shell, SWT.RIGHT); m_wlStepname.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.StepName.Label")); //$NON-NLS-1$ props.setLook(m_wlStepname); m_fdlStepname = new FormData(); m_fdlStepname.left = new FormAttachment(0, 0); m_fdlStepname.right = new FormAttachment(middle, -margin); m_fdlStepname.top = new FormAttachment(0, margin); m_wlStepname.setLayoutData(m_fdlStepname); m_wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); m_wStepname.setText(stepname); props.setLook(m_wStepname); m_wStepname.addModifyListener(lsMod); // format the text field m_fdStepname = new FormData(); m_fdStepname.left = new FormAttachment(middle, 0); m_fdStepname.top = new FormAttachment(0, margin); m_fdStepname.right = new FormAttachment(100, 0); m_wStepname.setLayoutData(m_fdStepname); m_wTabFolder = new CTabFolder(shell, SWT.BORDER); props.setLook(m_wTabFolder, Props.WIDGET_STYLE_TAB); m_wTabFolder.setSimple(false); // Start of the file tab m_wFileTab = new CTabItem(m_wTabFolder, SWT.NONE); m_wFileTab.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileTab.TabTitle")); //$NON-NLS-1$ Composite wFileComp = new Composite(m_wTabFolder, SWT.NONE); props.setLook(wFileComp); FormLayout fileLayout = new FormLayout(); fileLayout.marginWidth = 3; fileLayout.marginHeight = 3; wFileComp.setLayout(fileLayout); // Filename line m_wlFilename = new Label(wFileComp, SWT.RIGHT); m_wlFilename.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Filename.Label")); //$NON-NLS-1$ props.setLook(m_wlFilename); m_fdlFilename = new FormData(); m_fdlFilename.left = new FormAttachment(0, 0); m_fdlFilename.top = new FormAttachment(0, margin); m_fdlFilename.right = new FormAttachment(middle, -margin); m_wlFilename.setLayoutData(m_fdlFilename); // file browse button m_wbFilename = new Button(wFileComp, SWT.PUSH | SWT.CENTER); props.setLook(m_wbFilename); m_wbFilename.setText(BaseMessages.getString(WekaScoringMeta.PKG, "System.Button.Browse")); //$NON-NLS-1$ m_fdbFilename = new FormData(); m_fdbFilename.right = new FormAttachment(100, 0); m_fdbFilename.top = new FormAttachment(0, 0); m_wbFilename.setLayoutData(m_fdbFilename); // combined text field and env variable widget m_wFilename = new TextVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(m_wFilename); m_wFilename.addModifyListener(lsMod); m_fdFilename = new FormData(); m_fdFilename.left = new FormAttachment(middle, 0); m_fdFilename.top = new FormAttachment(0, margin); m_fdFilename.right = new FormAttachment(m_wbFilename, -margin); m_wFilename.setLayoutData(m_fdFilename); // store model in meta data Label saveModelMetaLab = new Label(wFileComp, SWT.RIGHT); props.setLook(saveModelMetaLab); saveModelMetaLab .setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.SaveModelToMeta.Label")); //$NON-NLS-1$ FormData fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(m_wFilename, margin); fd.right = new FormAttachment(middle, -margin); saveModelMetaLab.setLayoutData(fd); m_storeModelInStepMetaData = new Button(wFileComp, SWT.CHECK); props.setLook(m_storeModelInStepMetaData); fd = new FormData(); fd.left = new FormAttachment(middle, 0); fd.top = new FormAttachment(m_wFilename, margin); fd.right = new FormAttachment(100, 0); m_storeModelInStepMetaData.setLayoutData(fd); m_wUpdateModelLab = new Label(wFileComp, SWT.RIGHT); m_wUpdateModelLab .setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.UpdateModel.Label")); //$NON-NLS-1$ props.setLook(m_wUpdateModelLab); m_fdlUpdateModel = new FormData(); m_fdlUpdateModel.left = new FormAttachment(0, 0); m_fdlUpdateModel.top = new FormAttachment(m_storeModelInStepMetaData, margin); m_fdlUpdateModel.right = new FormAttachment(middle, -margin); m_wUpdateModelLab.setLayoutData(m_fdlUpdateModel); m_wUpdateModel = new Button(wFileComp, SWT.CHECK); props.setLook(m_wUpdateModel); m_fdUpdateModel = new FormData(); m_fdUpdateModel.left = new FormAttachment(middle, 0); m_fdUpdateModel.top = new FormAttachment(m_storeModelInStepMetaData, margin); m_fdUpdateModel.right = new FormAttachment(100, 0); m_wUpdateModel.setLayoutData(m_fdUpdateModel); m_wUpdateModel.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { m_currentMeta.setChanged(); m_wbSaveFilename.setEnabled(m_wUpdateModel.getSelection()); m_wSaveFilename.setEnabled(m_wUpdateModel.getSelection()); } }); // ---------------------------- // Save filename line m_wlSaveFilename = new Label(wFileComp, SWT.RIGHT); m_wlSaveFilename .setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.SaveFilename.Label")); //$NON-NLS-1$ props.setLook(m_wlSaveFilename); m_fdlSaveFilename = new FormData(); m_fdlSaveFilename.left = new FormAttachment(0, 0); m_fdlSaveFilename.top = new FormAttachment(m_wUpdateModel, margin); m_fdlSaveFilename.right = new FormAttachment(middle, -margin); m_wlSaveFilename.setLayoutData(m_fdlSaveFilename); // Save file browse button m_wbSaveFilename = new Button(wFileComp, SWT.PUSH | SWT.CENTER); props.setLook(m_wbSaveFilename); m_wbSaveFilename.setText(BaseMessages.getString(WekaScoringMeta.PKG, "System.Button.Browse")); //$NON-NLS-1$ m_fdbSaveFilename = new FormData(); m_fdbSaveFilename.right = new FormAttachment(100, 0); m_fdbSaveFilename.top = new FormAttachment(m_wUpdateModel, 0); m_wbSaveFilename.setLayoutData(m_fdbSaveFilename); m_wbSaveFilename.setEnabled(false); // combined text field and env variable widget m_wSaveFilename = new TextVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(m_wSaveFilename); m_wSaveFilename.addModifyListener(lsMod); m_fdSaveFilename = new FormData(); m_fdSaveFilename.left = new FormAttachment(middle, 0); m_fdSaveFilename.top = new FormAttachment(m_wUpdateModel, margin); m_fdSaveFilename.right = new FormAttachment(m_wbSaveFilename, -margin); m_wSaveFilename.setLayoutData(m_fdSaveFilename); m_wSaveFilename.setEnabled(false); m_fdFileComp = new FormData(); m_fdFileComp.left = new FormAttachment(0, 0); m_fdFileComp.top = new FormAttachment(0, 0); m_fdFileComp.right = new FormAttachment(100, 0); m_fdFileComp.bottom = new FormAttachment(100, 0); wFileComp.setLayoutData(m_fdFileComp); wFileComp.layout(); m_wFileTab.setControl(wFileComp); m_wAcceptFileNameFromFieldCheckLab = new Label(wFileComp, SWT.RIGHT); m_wAcceptFileNameFromFieldCheckLab.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.AcceptFileNamesFromFieldCheck.Label")); //$NON-NLS-1$ props.setLook(m_wAcceptFileNameFromFieldCheckLab); FormData fdAcceptCheckLab = new FormData(); fdAcceptCheckLab.left = new FormAttachment(0, 0); fdAcceptCheckLab.top = new FormAttachment(m_wSaveFilename, margin); fdAcceptCheckLab.right = new FormAttachment(middle, -margin); m_wAcceptFileNameFromFieldCheckLab.setLayoutData(fdAcceptCheckLab); m_wAcceptFileNameFromFieldCheckBox = new Button(wFileComp, SWT.CHECK); props.setLook(m_wAcceptFileNameFromFieldCheckBox); FormData fdAcceptCheckBox = new FormData(); fdAcceptCheckBox.left = new FormAttachment(middle, 0); fdAcceptCheckBox.top = new FormAttachment(m_wSaveFilename, margin); fdAcceptCheckBox.right = new FormAttachment(100, 0); m_wAcceptFileNameFromFieldCheckBox.setLayoutData(fdAcceptCheckBox); m_wAcceptFileNameFromFieldCheckBox.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { m_currentMeta.setChanged(); if (m_wAcceptFileNameFromFieldCheckBox.getSelection()) { m_wUpdateModel.setSelection(false); m_wUpdateModel.setEnabled(false); m_wSaveFilename.setText(""); //$NON-NLS-1$ m_wlFilename.setText( BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Default.Label")); //$NON-NLS-1$ if (!Const.isEmpty(m_wFilename.getText())) { // load - loadModel() will take care of storing it in // either the main or default model in the current meta loadModel(); } else { // try and shift the main model (if non-null) over into the // default model in current meta m_currentMeta.setDefaultModel(m_currentMeta.getModel()); m_currentMeta.setModel(null); } } else { if (!Const.isEmpty(m_wFilename.getText())) { // load - loadModel() will take care of storing it in // either the main or default model in the current meta loadModel(); } else { // try and shift the default model (if non-null) over into the // main model in current meta m_currentMeta.setModel(m_currentMeta.getDefaultModel()); m_currentMeta.setDefaultModel(null); } m_wCacheModelsCheckBox.setSelection(false); m_wlFilename.setText( BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Filename.Label")); //$NON-NLS-1$ } m_wCacheModelsCheckBox.setEnabled(m_wAcceptFileNameFromFieldCheckBox.getSelection()); m_wAcceptFileNameFromFieldText.setEnabled(m_wAcceptFileNameFromFieldCheckBox.getSelection()); m_wbSaveFilename.setEnabled( !m_wAcceptFileNameFromFieldCheckBox.getSelection() && m_wUpdateModel.getSelection()); m_wSaveFilename.setEnabled( !m_wAcceptFileNameFromFieldCheckBox.getSelection() && m_wUpdateModel.getSelection()); } }); // m_wAcceptFileNameFromFieldTextLab = new Label(wFileComp, SWT.RIGHT); m_wAcceptFileNameFromFieldTextLab.setText( BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.AcceptFileNamesFromField.Label")); //$NON-NLS-1$ props.setLook(m_wAcceptFileNameFromFieldTextLab); FormData fdAcceptLab = new FormData(); fdAcceptLab.left = new FormAttachment(0, 0); fdAcceptLab.top = new FormAttachment(m_wAcceptFileNameFromFieldCheckBox, margin); fdAcceptLab.right = new FormAttachment(middle, -margin); m_wAcceptFileNameFromFieldTextLab.setLayoutData(fdAcceptLab); m_wAcceptFileNameFromFieldText = new TextVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(m_wAcceptFileNameFromFieldText); m_wAcceptFileNameFromFieldText.addModifyListener(lsMod); FormData fdAcceptText = new FormData(); fdAcceptText.left = new FormAttachment(middle, 0); fdAcceptText.top = new FormAttachment(m_wAcceptFileNameFromFieldCheckBox, margin); fdAcceptText.right = new FormAttachment(100, 0); m_wAcceptFileNameFromFieldText.setLayoutData(fdAcceptText); m_wAcceptFileNameFromFieldText.setEnabled(false); m_wCacheModelsLab = new Label(wFileComp, SWT.RIGHT); m_wCacheModelsLab .setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.CacheModels.Label")); //$NON-NLS-1$ props.setLook(m_wCacheModelsLab); FormData fdCacheLab = new FormData(); fdCacheLab.left = new FormAttachment(0, 0); fdCacheLab.top = new FormAttachment(m_wAcceptFileNameFromFieldText, margin); fdCacheLab.right = new FormAttachment(middle, -margin); m_wCacheModelsLab.setLayoutData(fdCacheLab); // m_wCacheModelsCheckBox = new Button(wFileComp, SWT.CHECK); props.setLook(m_wCacheModelsCheckBox); FormData fdCacheCheckBox = new FormData(); fdCacheCheckBox.left = new FormAttachment(middle, 0); fdCacheCheckBox.top = new FormAttachment(m_wAcceptFileNameFromFieldText, margin); fdCacheCheckBox.right = new FormAttachment(100, 0); m_wCacheModelsCheckBox.setLayoutData(fdCacheCheckBox); m_wCacheModelsCheckBox.setEnabled(false); m_wOutputProbsLab = new Label(wFileComp, SWT.RIGHT); m_wOutputProbsLab .setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.OutputProbs.Label")); //$NON-NLS-1$ props.setLook(m_wOutputProbsLab); m_fdlOutputProbs = new FormData(); m_fdlOutputProbs.left = new FormAttachment(0, 0); m_fdlOutputProbs.top = new FormAttachment(m_wCacheModelsCheckBox, margin); m_fdlOutputProbs.right = new FormAttachment(middle, -margin); m_wOutputProbsLab.setLayoutData(m_fdlOutputProbs); m_wOutputProbs = new Button(wFileComp, SWT.CHECK); props.setLook(m_wOutputProbs); m_fdOutputProbs = new FormData(); m_fdOutputProbs.left = new FormAttachment(middle, 0); m_fdOutputProbs.top = new FormAttachment(m_wCacheModelsCheckBox, margin); m_fdOutputProbs.right = new FormAttachment(100, 0); m_wOutputProbs.setLayoutData(m_fdOutputProbs); // batch scoring size line Label batchLab = new Label(wFileComp, SWT.RIGHT); batchLab.setText("Batch scoring batch size"); //$NON-NLS-1$ props.setLook(batchLab); FormData fdd = new FormData(); fdd.left = new FormAttachment(0, 0); fdd.top = new FormAttachment(m_wOutputProbs, margin); fdd.right = new FormAttachment(middle, -margin); batchLab.setLayoutData(fdd); m_batchScoringBatchSizeText = new TextVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(m_batchScoringBatchSizeText); m_batchScoringBatchSizeText.addModifyListener(lsMod); fdd = new FormData(); fdd.left = new FormAttachment(middle, 0); fdd.top = new FormAttachment(m_wOutputProbs, margin); fdd.right = new FormAttachment(100, 0); m_batchScoringBatchSizeText.setLayoutData(fdd); m_batchScoringBatchSizeText.setEnabled(false); // Fields mapping tab m_wFieldsTab = new CTabItem(m_wTabFolder, SWT.NONE); m_wFieldsTab.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FieldsTab.TabTitle")); //$NON-NLS-1$ FormLayout fieldsLayout = new FormLayout(); fieldsLayout.marginWidth = 3; fieldsLayout.marginHeight = 3; Composite wFieldsComp = new Composite(m_wTabFolder, SWT.NONE); props.setLook(wFieldsComp); wFieldsComp.setLayout(fieldsLayout); // body of tab to be a scrolling text area // to display the mapping m_wMappingText = new Text(wFieldsComp, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); m_wMappingText.setEditable(false); FontData fontd = new FontData("Courier New", 12, SWT.NORMAL); //$NON-NLS-1$ m_wMappingText.setFont(new Font(getParent().getDisplay(), fontd)); props.setLook(m_wMappingText); // format the fields mapping text area m_fdMappingText = new FormData(); m_fdMappingText.left = new FormAttachment(0, 0); m_fdMappingText.top = new FormAttachment(0, margin); m_fdMappingText.right = new FormAttachment(100, 0); m_fdMappingText.bottom = new FormAttachment(100, 0); m_wMappingText.setLayoutData(m_fdMappingText); m_fdFieldsComp = new FormData(); m_fdFieldsComp.left = new FormAttachment(0, 0); m_fdFieldsComp.top = new FormAttachment(0, 0); m_fdFieldsComp.right = new FormAttachment(100, 0); m_fdFieldsComp.bottom = new FormAttachment(100, 0); wFieldsComp.setLayoutData(m_fdFieldsComp); wFieldsComp.layout(); m_wFieldsTab.setControl(wFieldsComp); // Model display tab m_wModelTab = new CTabItem(m_wTabFolder, SWT.NONE); m_wModelTab.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.ModelTab.TabTitle")); //$NON-NLS-1$ FormLayout modelLayout = new FormLayout(); modelLayout.marginWidth = 3; modelLayout.marginHeight = 3; Composite wModelComp = new Composite(m_wTabFolder, SWT.NONE); props.setLook(wModelComp); wModelComp.setLayout(modelLayout); // body of tab to be a scrolling text area // to display the pre-learned model m_wModelText = new Text(wModelComp, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); m_wModelText.setEditable(false); fontd = new FontData("Courier New", 12, SWT.NORMAL); //$NON-NLS-1$ m_wModelText.setFont(new Font(getParent().getDisplay(), fontd)); props.setLook(m_wModelText); // format the model text area m_fdModelText = new FormData(); m_fdModelText.left = new FormAttachment(0, 0); m_fdModelText.top = new FormAttachment(0, margin); m_fdModelText.right = new FormAttachment(100, 0); m_fdModelText.bottom = new FormAttachment(100, 0); m_wModelText.setLayoutData(m_fdModelText); m_fdModelComp = new FormData(); m_fdModelComp.left = new FormAttachment(0, 0); m_fdModelComp.top = new FormAttachment(0, 0); m_fdModelComp.right = new FormAttachment(100, 0); m_fdModelComp.bottom = new FormAttachment(100, 0); wModelComp.setLayoutData(m_fdModelComp); wModelComp.layout(); m_wModelTab.setControl(wModelComp); m_fdTabFolder = new FormData(); m_fdTabFolder.left = new FormAttachment(0, 0); m_fdTabFolder.top = new FormAttachment(m_wStepname, margin); m_fdTabFolder.right = new FormAttachment(100, 0); m_fdTabFolder.bottom = new FormAttachment(100, -50); m_wTabFolder.setLayoutData(m_fdTabFolder); // Buttons inherited from BaseStepDialog wOK = new Button(shell, SWT.PUSH); wOK.setText(BaseMessages.getString(WekaScoringMeta.PKG, "System.Button.OK")); //$NON-NLS-1$ wCancel = new Button(shell, SWT.PUSH); wCancel.setText(BaseMessages.getString(WekaScoringMeta.PKG, "System.Button.Cancel")); //$NON-NLS-1$ setButtonPositions(new Button[] { wOK, wCancel }, margin, m_wTabFolder); // Add listeners lsCancel = new Listener() { public void handleEvent(Event e) { cancel(); } }; lsOK = new Listener() { public void handleEvent(Event e) { ok(); } }; wCancel.addListener(SWT.Selection, lsCancel); wOK.addListener(SWT.Selection, lsOK); lsDef = new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { ok(); } }; m_wStepname.addSelectionListener(lsDef); // Detect X or ALT-F4 or something that kills this window... shell.addShellListener(new ShellAdapter() { @Override public void shellClosed(ShellEvent e) { cancel(); } }); // Whenever something changes, set the tooltip to the expanded version: m_wFilename.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { m_wFilename.setToolTipText(transMeta.environmentSubstitute(m_wFilename.getText())); } }); m_wSaveFilename.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { m_wSaveFilename.setToolTipText(transMeta.environmentSubstitute(m_wSaveFilename.getText())); } }); // listen to the file name text box and try to load a model // if the user presses enter m_wFilename.addSelectionListener(new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { if (!loadModel()) { log.logError( BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Log.FileLoadingError")); //$NON-NLS-1$ } } }); m_wbFilename.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String[] extensions = null; String[] filterNames = null; if (XStream.isPresent()) { extensions = new String[4]; filterNames = new String[4]; extensions[0] = "*.model"; //$NON-NLS-1$ filterNames[0] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFileBinary"); //$NON-NLS-1$ extensions[1] = "*.xstreammodel"; //$NON-NLS-1$ filterNames[1] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFileXML"); //$NON-NLS-1$ extensions[2] = "*.xml"; //$NON-NLS-1$ filterNames[2] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFilePMML"); //$NON-NLS-1$ extensions[3] = "*"; //$NON-NLS-1$ filterNames[3] = BaseMessages.getString(WekaScoringMeta.PKG, "System.FileType.AllFiles"); //$NON-NLS-1$ } else { extensions = new String[3]; filterNames = new String[3]; extensions[0] = "*.model"; //$NON-NLS-1$ filterNames[0] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFileBinary"); //$NON-NLS-1$ extensions[1] = "*.xml"; //$NON-NLS-1$ filterNames[1] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFilePMML"); //$NON-NLS-1$ extensions[2] = "*"; //$NON-NLS-1$ filterNames[2] = BaseMessages.getString(WekaScoringMeta.PKG, "System.FileType.AllFiles"); //$NON-NLS-1$ } // get current file FileObject rootFile = null; FileObject initialFile = null; FileObject defaultInitialFile = null; try { if (m_wFilename.getText() != null) { String fname = transMeta.environmentSubstitute(m_wFilename.getText()); if (!Const.isEmpty(fname)) { initialFile = KettleVFS.getFileObject(fname); rootFile = initialFile.getFileSystem().getRoot(); } else { defaultInitialFile = KettleVFS.getFileObject(Spoon.getInstance().getLastFileOpened()); } } else { defaultInitialFile = KettleVFS.getFileObject("file:///c:/"); //$NON-NLS-1$ } if (rootFile == null) { rootFile = defaultInitialFile.getFileSystem().getRoot(); } VfsFileChooserDialog fileChooserDialog = Spoon.getInstance().getVfsFileChooserDialog(rootFile, initialFile); fileChooserDialog.setRootFile(rootFile); fileChooserDialog.setInitialFile(initialFile); fileChooserDialog.defaultInitialFile = rootFile; String in = (!Const.isEmpty(m_wFilename.getText())) ? initialFile.getName().getPath() : null; FileObject selectedFile = fileChooserDialog.open(shell, null, "file", //$NON-NLS-1$ true, in, extensions, filterNames, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE); if (selectedFile != null) { m_wFilename.setText(selectedFile.getURL().toString()); } // try to load model file and display model if (!loadModel()) { log.logError(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Log.FileLoadingError")); //$NON-NLS-1$ } } catch (Exception ex) { logError("A problem occurred", ex); //$NON-NLS-1$ } } }); m_wbSaveFilename.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { FileDialog dialog = new FileDialog(shell, SWT.SAVE); String[] extensions = null; String[] filterNames = null; if (XStream.isPresent()) { extensions = new String[3]; filterNames = new String[3]; extensions[0] = "*.model"; //$NON-NLS-1$ filterNames[0] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFileBinary"); //$NON-NLS-1$ extensions[1] = "*.xstreammodel"; //$NON-NLS-1$ filterNames[1] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFileXML"); //$NON-NLS-1$ extensions[2] = "*"; //$NON-NLS-1$ filterNames[2] = BaseMessages.getString(WekaScoringMeta.PKG, "System.FileType.AllFiles"); //$NON-NLS-1$ } else { extensions = new String[2]; filterNames = new String[2]; extensions[0] = "*.model"; //$NON-NLS-1$ filterNames[0] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFileBinary"); //$NON-NLS-1$ extensions[1] = "*"; //$NON-NLS-1$ filterNames[1] = BaseMessages.getString(WekaScoringMeta.PKG, "System.FileType.AllFiles"); //$NON-NLS-1$ } dialog.setFilterExtensions(extensions); if (m_wSaveFilename.getText() != null) { dialog.setFileName(transMeta.environmentSubstitute(m_wSaveFilename.getText())); } dialog.setFilterNames(filterNames); if (dialog.open() != null) { m_wSaveFilename.setText( dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName()); //$NON-NLS-1$ } } }); m_wTabFolder.setSelection(0); // Set the shell size, based upon previous time... setSize(); getData(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } return stepname; }
From source file:org.pentaho.di.trans.step.errorhandling.AbstractFileErrorHandler.java
/** * returns the OutputWiter if exists. Otherwhise it will create a new one. * * @return/*from w w w.ja v a 2s .com*/ * @throws KettleException */ Writer getWriter(Object source) throws KettleException { try { Writer outputStreamWriter = writers.get(source); if (outputStreamWriter != null) { return outputStreamWriter; } FileObject file = getReplayFilename(destinationDirectory, processingFilename, dateString, fileExtension, source); ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, file, baseStep.getTransMeta().getName(), baseStep.getStepname()); baseStep.addResultFile(resultFile); try { if (encoding == null) { outputStreamWriter = new OutputStreamWriter(KettleVFS.getOutputStream(file, false)); } else { outputStreamWriter = new OutputStreamWriter(KettleVFS.getOutputStream(file, false), encoding); } } catch (Exception e) { throw new KettleException(BaseMessages.getString(PKG, "AbstractFileErrorHandler.Exception.CouldNotCreateFileErrorHandlerForFile") + file.getName().getURI(), e); } writers.put(source, outputStreamWriter); return outputStreamWriter; } catch (KettleFileException e) { throw new KettleException(BaseMessages.getString(PKG, "AbstractFileErrorHandler.Exception.CouldNotCreateFileErrorHandlerForFile"), e); } }
From source file:org.pentaho.di.trans.step.errorhandling.FileErrorHandlerMissingFiles.java
public void handleNonExistantFile(FileObject file) throws KettleException { handleFile(file);//from w ww . j av a 2 s .com try { getWriter(NO_PARTS).write(THIS_FILE_DOES_NOT_EXIST); getWriter(NO_PARTS).write(Const.CR); } catch (Exception e) { throw new KettleException(BaseMessages.getString(PKG, "FileErrorHandlerMissingFiles.Exception.CouldNotCreateNonExistantFile") + file.getName().getURI(), e); } }
From source file:org.pentaho.di.trans.step.errorhandling.FileErrorHandlerMissingFiles.java
public void handleNonAccessibleFile(FileObject file) throws KettleException { handleFile(file);//from w w w. ja v a 2s . c o m try { getWriter(NO_PARTS).write(THIS_FILE_WAS_NOT_ACCESSIBLE); getWriter(NO_PARTS).write(Const.CR); } catch (Exception e) { throw new KettleException(BaseMessages.getString(PKG, "FileErrorHandlerMissingFiles.Exception.CouldNotCreateNonAccessibleFile") + file.getName().getURI(), e); } }
From source file:org.pentaho.di.trans.steps.accessinput.AccessInputMeta.java
public static String getFilename(FileObject fileObject) { FileName fileName = fileObject.getName(); String root = fileName.getRootURI(); if (!root.startsWith("file:")) { return fileName.getURI(); }//from ww w . j av a 2 s. c om if (root.endsWith(":/")) { root = root.substring(8, 10); } else { root = root.substring(7, root.length() - 1); } String fileString = root + fileName.getPath(); if (!"/".equals(Const.FILE_SEPARATOR)) { fileString = Const.replace(fileString, "/", Const.FILE_SEPARATOR); } return fileString; }
From source file:org.pentaho.di.trans.steps.exceloutput.ExcelOutput.java
private boolean createParentFolder(FileObject file) { boolean retval = true; // Check for parent folder FileObject parentfolder = null; try {/*from w w w. ja v a 2 s . co m*/ // Get parent folder parentfolder = file.getParent(); if (parentfolder.exists()) { if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "ExcelOutput.Log.ParentFolderExist", parentfolder.getName().toString())); } } else { if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "ExcelOutput.Log.ParentFolderNotExist", parentfolder.getName().toString())); } if (meta.isCreateParentFolder()) { parentfolder.createFolder(); if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "ExcelOutput.Log.ParentFolderCreated", parentfolder.getName().toString())); } } else { retval = false; logError(BaseMessages.getString(PKG, "ExcelOutput.Error.CanNotFoundParentFolder", parentfolder.getName().toString(), file.getName().toString())); } } } catch (Exception e) { retval = false; logError(BaseMessages.getString(PKG, "ExcelOutput.Log.CouldNotCreateParentFolder", parentfolder.getName().toString())); } finally { if (parentfolder != null) { try { parentfolder.close(); } catch (Exception ex) { // Ignore } } } return retval; }
From source file:org.pentaho.di.trans.steps.getxmldata.GetXMLData.java
private boolean ReadNextString() { try {/*from w w w . j a v a 2 s . c o m*/ // Grab another row ... data.readrow = getRow(); if (data.readrow == null) { // finished processing! if (log.isDetailed()) { logDetailed(BaseMessages.getString(PKG, "GetXMLData.Log.FinishedProcessing")); } return false; } if (first) { first = false; data.nrReadRow = getInputRowMeta().size(); data.inputRowMeta = getInputRowMeta(); data.outputRowMeta = data.inputRowMeta.clone(); meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore); // Get total previous fields data.totalpreviousfields = data.inputRowMeta.size(); // Create convert meta-data objects that will contain Date & Number formatters data.convertRowMeta = new RowMeta(); for (ValueMetaInterface valueMeta : data.convertRowMeta.getValueMetaList()) { data.convertRowMeta.addValueMeta( ValueMetaFactory.cloneValueMeta(valueMeta, ValueMetaInterface.TYPE_STRING)); } // For String to <type> conversions, we allocate a conversion meta data row as well... // data.convertRowMeta = data.outputRowMeta.cloneToType(ValueMetaInterface.TYPE_STRING); // Check is XML field is provided if (Const.isEmpty(meta.getXMLField())) { logError(BaseMessages.getString(PKG, "GetXMLData.Log.NoField")); throw new KettleException(BaseMessages.getString(PKG, "GetXMLData.Log.NoField")); } // cache the position of the field if (data.indexOfXmlField < 0) { data.indexOfXmlField = getInputRowMeta().indexOfValue(meta.getXMLField()); if (data.indexOfXmlField < 0) { // The field is unreachable ! logError(BaseMessages.getString(PKG, "GetXMLData.Log.ErrorFindingField", meta.getXMLField())); throw new KettleException(BaseMessages.getString(PKG, "GetXMLData.Exception.CouldnotFindField", meta.getXMLField())); } } } if (meta.isInFields()) { // get XML field value String Fieldvalue = getInputRowMeta().getString(data.readrow, data.indexOfXmlField); if (log.isDetailed()) { logDetailed(BaseMessages.getString(PKG, "GetXMLData.Log.XMLStream", meta.getXMLField(), Fieldvalue)); } if (meta.getIsAFile()) { FileObject file = null; try { // XML source is a file. file = KettleVFS.getFileObject(Fieldvalue, getTransMeta()); // Open the XML document if (!setDocument(null, file, false, false)) { throw new KettleException( BaseMessages.getString(PKG, "GetXMLData.Log.UnableCreateDocument")); } if (!applyXPath()) { throw new KettleException( BaseMessages.getString(PKG, "GetXMLData.Log.UnableApplyXPath")); } addFileToResultFilesname(file); if (log.isDetailed()) { logDetailed(BaseMessages.getString(PKG, "GetXMLData.Log.LoopFileOccurences", "" + data.nodesize, file.getName().getBaseName())); } } catch (Exception e) { throw new KettleException(e); } finally { try { if (file != null) { file.close(); } } catch (Exception e) { // Ignore close errors } } } else { boolean url = false; boolean xmltring = true; if (meta.isReadUrl()) { url = true; xmltring = false; } // Open the XML document if (!setDocument(Fieldvalue, null, xmltring, url)) { throw new KettleException( BaseMessages.getString(PKG, "GetXMLData.Log.UnableCreateDocument")); } // Apply XPath and set node list if (!applyXPath()) { throw new KettleException(BaseMessages.getString(PKG, "GetXMLData.Log.UnableApplyXPath")); } if (log.isDetailed()) { logDetailed(BaseMessages.getString(PKG, "GetXMLData.Log.LoopFileOccurences", "" + data.nodesize)); } } } } catch (Exception e) { logError(BaseMessages.getString(PKG, "GetXMLData.Log.UnexpectedError", e.toString())); stopAll(); logError(Const.getStackTracker(e)); setErrors(1); return false; } return true; }
From source file:org.pentaho.di.trans.steps.getxmldata.GetXMLDataMeta.java
/** * Since the exported transformation that runs this will reside in a ZIP file, we can't reference files relatively. So * what this does is turn the name of files into absolute paths OR it simply includes the resource in the ZIP file. * For now, we'll simply turn it into an absolute path and pray that the file is on a shared drive or something like * that./*from w w w . j av a2 s . com*/ * * @param space * the variable space to use * @param definitions * @param resourceNamingInterface * @param repository * The repository to optionally load other resources from (to be converted to XML) * @param metaStore * the metaStore in which non-kettle metadata could reside. * * @return the filename of the exported resource */ public String exportResources(VariableSpace space, Map<String, ResourceDefinition> definitions, ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore) throws KettleException { try { // The object that we're modifying here is a copy of the original! // So let's change the filename from relative to absolute by grabbing the file object... // In case the name of the file comes from previous steps, forget about this! // List<String> newFilenames = new ArrayList<String>(); if (!isInFields()) { FileInputList fileList = getFiles(space); if (fileList.getFiles().size() > 0) { for (FileObject fileObject : fileList.getFiles()) { // From : ${Internal.Transformation.Filename.Directory}/../foo/bar.xml // To : /home/matt/test/files/foo/bar.xml // // If the file doesn't exist, forget about this effort too! // if (fileObject.exists()) { // Convert to an absolute path and add it to the list. // newFilenames.add(fileObject.getName().getPath()); } } // Still here: set a new list of absolute filenames! // fileName = newFilenames.toArray(new String[newFilenames.size()]); fileMask = new String[newFilenames.size()]; // all null since converted to absolute path. fileRequired = new String[newFilenames.size()]; // all null, turn to "Y" : for (int i = 0; i < newFilenames.size(); i++) { fileRequired[i] = "Y"; } } } return null; } catch (Exception e) { throw new KettleException(e); } }