List of usage examples for org.apache.commons.vfs FileObject getURL
public URL getURL() throws FileSystemException;
From source file:org.josso.tooling.gshell.install.test.VFSTest.java
@Test public void testUnjarExploded() throws Exception { FileObject home = fsm.resolveFile(System.getProperty("java.home")); assert home.exists() : "JAVA_HOME folder not found ? " + home.getName().getFriendlyURI(); FileObject target = fsm.resolveFile(new File(".").getAbsolutePath() + "/target"); assert target.exists() : "target folder not found : " + target.getName().getFriendlyURI(); FileObject targetFolder = target.resolveFile("unjar"); targetFolder.createFolder();//from w ww.ja va2 s. co m FileObject srcFile = home.resolveFile("./lib/rt.jar"); assert srcFile.exists() : "File not found " + srcFile.getURL(); log.info("JAR FILE : " + srcFile.getName().getFriendlyURI()); log.info("ROOT : " + srcFile.getName().getRoot()); log.info("ROOT URI : " + srcFile.getName().getRootURI()); log.info("PATH DECODED: " + srcFile.getName().getPathDecoded()); log.info("ROOT DECODED: " + srcFile.getName().getRoot().getPathDecoded()); log.info("PATH : " + srcFile.getName().getPath()); assert installer.installJar(srcFile, targetFolder, "rt.jar-exploded", true, true) : "Cannot unjar exploded !"; }
From source file:org.josso.tooling.gshell.install.test.VFSTest.java
@Test public void testUnjar() throws Exception { FileObject home = fsm.resolveFile(System.getProperty("java.home")); assert home.exists() : "JAVA_HOME folder not found ? " + home.getName().getFriendlyURI(); FileObject target = fsm.resolveFile(new File(".").getAbsolutePath() + "/target"); assert target.exists() : "target folder not found : " + target.getName().getFriendlyURI(); FileObject targetFolder = target.resolveFile("unjar"); targetFolder.createFolder();//from w w w .ja v a 2 s .c o m FileObject srcFile = home.resolveFile("./lib/rt.jar"); assert srcFile.exists() : "File not found " + srcFile.getURL(); assert installer.installJar(srcFile, targetFolder, "rt.jar", false, true) : "Cannot unjar !"; }
From source file:org.mule.transports.vfs.VFSMessageDispatcher.java
protected void doDispatch(UMOEvent event) throws Exception { try {//from w ww. ja v a 2 s. com Object data = event.getTransformedMessage(); String filename = (String) event.getProperty(VFSConnector.PROPERTY_FILENAME); if (filename == null) { String outPattern = (String) event.getProperty(VFSConnector.PROPERTY_OUTPUT_PATTERN); if (outPattern == null) { outPattern = connector.getOutputPattern(); } filename = generateFilename(event, outPattern); } if (filename == null) { throw new IOException("Filename is null"); } FileObject file = dirObject.resolveFile(filename); byte[] buf; if (data instanceof byte[]) { buf = (byte[]) data; } else { buf = data.toString().getBytes(); } logger.info("Writing file to: " + file.getURL()); OutputStream outputStream = file.getContent().getOutputStream(connector.isOutputAppend()); try { outputStream.write(buf); } finally { outputStream.close(); } } catch (Exception e) { Exception handled = e; if (e instanceof FileSystemException) { handled = new ConnectException(e, this); } getConnector().handleException(handled); } }
From source file:org.openbi.kettle.plugins.parquetoutput.ParquetOutputDialog.java
public String open() { Shell parent = getParent();/*from w ww. j a v a2 s. c o m*/ Display display = parent.getDisplay(); shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN); props.setLook(shell); setShellImage(shell, input); ModifyListener lsMod = new ModifyListener() { public void modifyText(ModifyEvent e) { input.setChanged(); } }; changed = input.hasChanged(); FormLayout formLayout = new FormLayout(); formLayout.marginWidth = Const.FORM_MARGIN; formLayout.marginHeight = Const.FORM_MARGIN; shell.setLayout(formLayout); shell.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.DialogTitle")); int middle = props.getMiddlePct(); int margin = Const.MARGIN; // Stepname line wlStepname = new Label(shell, SWT.RIGHT); wlStepname.setText(BaseMessages.getString(PKG, "System.Label.StepName")); props.setLook(wlStepname); fdlStepname = new FormData(); fdlStepname.left = new FormAttachment(0, 0); fdlStepname.top = new FormAttachment(0, margin); fdlStepname.right = new FormAttachment(middle, -margin); wlStepname.setLayoutData(fdlStepname); wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); wStepname.setText(stepname); props.setLook(wStepname); wStepname.addModifyListener(lsMod); fdStepname = new FormData(); fdStepname.left = new FormAttachment(middle, 0); fdStepname.top = new FormAttachment(0, margin); fdStepname.right = new FormAttachment(100, 0); wStepname.setLayoutData(fdStepname); wTabFolder = new CTabFolder(shell, SWT.BORDER); props.setLook(wTabFolder, Props.WIDGET_STYLE_TAB); wTabFolder.setSimple(false); // //////////////////////// // START OF FILE TAB/// // / wFileTab = new CTabItem(wTabFolder, SWT.NONE); wFileTab.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.FileTab.TabTitle")); Composite wFileComp = new Composite(wTabFolder, SWT.NONE); props.setLook(wFileComp); FormLayout fileLayout = new FormLayout(); fileLayout.marginWidth = 3; fileLayout.marginHeight = 3; wFileComp.setLayout(fileLayout); // Filename line wlFilename = new Label(wFileComp, SWT.RIGHT); wlFilename.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.Filename.Label")); props.setLook(wlFilename); fdlFilename = new FormData(); fdlFilename.left = new FormAttachment(0, 0); fdlFilename.top = new FormAttachment(0, margin); fdlFilename.right = new FormAttachment(middle, -margin); wlFilename.setLayoutData(fdlFilename); wbFilename = new Button(wFileComp, SWT.PUSH | SWT.CENTER); props.setLook(wbFilename); wbFilename.setText(BaseMessages.getString(PKG, "System.Button.Browse")); fdbFilename = new FormData(); fdbFilename.right = new FormAttachment(100, 0); fdbFilename.top = new FormAttachment(0, 0); wbFilename.setLayoutData(fdbFilename); wFilename = new TextVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wFilename); wFilename.addModifyListener(lsMod); fdFilename = new FormData(); fdFilename.left = new FormAttachment(middle, 0); fdFilename.top = new FormAttachment(0, margin); fdFilename.right = new FormAttachment(wbFilename, -margin); wFilename.setLayoutData(fdFilename); // Create Schema File // wlFilenameInField = new Label(wFileComp, SWT.RIGHT); wlFilenameInField.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.FilenameInField.Label")); props.setLook(wlFilenameInField); fdlFilenameInField = new FormData(); fdlFilenameInField.left = new FormAttachment(0, 0); fdlFilenameInField.top = new FormAttachment(wFilename, margin); fdlFilenameInField.right = new FormAttachment(middle, -margin); wlFilenameInField.setLayoutData(fdlFilenameInField); wFilenameInField = new Button(wFileComp, SWT.CHECK); props.setLook(wFilenameInField); fdFilenameInField = new FormData(); fdFilenameInField.left = new FormAttachment(middle, 0); fdFilenameInField.top = new FormAttachment(wFilename, margin); fdFilenameInField.right = new FormAttachment(100, 0); wFilenameInField.setLayoutData(fdFilenameInField); wFilenameInField.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); setFilenameInField(); } }); // input Field Line wlFilenameField = new Label(wFileComp, SWT.RIGHT); wlFilenameField.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.FilenameField.Label")); props.setLook(wlFilenameField); fdlFilenameField = new FormData(); fdlFilenameField.left = new FormAttachment(0, 0); fdlFilenameField.right = new FormAttachment(middle, -margin); fdlFilenameField.top = new FormAttachment(wFilenameInField, margin); wlFilenameField.setLayoutData(fdlFilenameField); wFilenameField = new ComboVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wFilenameField); wFilenameField.addModifyListener(lsMod); fdFilenameField = new FormData(); fdFilenameField.left = new FormAttachment(middle, 0); fdFilenameField.top = new FormAttachment(wFilenameInField, margin); fdFilenameField.right = new FormAttachment(100, 0); wFilenameField.setLayoutData(fdFilenameField); wFilenameField.setEnabled(false); wFilenameField.addFocusListener(new FocusListener() { public void focusLost(org.eclipse.swt.events.FocusEvent e) { } public void focusGained(org.eclipse.swt.events.FocusEvent e) { Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT); shell.setCursor(busy); getFields(); shell.setCursor(null); busy.dispose(); } }); /* End */ // Clean Output // wlCleanOutput = new Label(wFileComp, SWT.RIGHT); wlCleanOutput.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.CleanOutput.Label")); props.setLook(wlCleanOutput); fdlCleanOutput = new FormData(); fdlCleanOutput.left = new FormAttachment(0, 0); fdlCleanOutput.top = new FormAttachment(wFilenameField, margin); fdlCleanOutput.right = new FormAttachment(middle, -margin); wlCleanOutput.setLayoutData(fdlCleanOutput); wCleanOutput = new Button(wFileComp, SWT.CHECK); wCleanOutput.setToolTipText(BaseMessages.getString(PKG, "ParquetOutputDialog.CleanOutput.Tooltip")); props.setLook(wCleanOutput); fdCleanOutput = new FormData(); fdCleanOutput.left = new FormAttachment(middle, 0); fdCleanOutput.top = new FormAttachment(wFilenameField, margin); fdCleanOutput.right = new FormAttachment(100, 0); wCleanOutput.setLayoutData(fdCleanOutput); wCleanOutput.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); // Create Parent Folder? // wlCreateParentFolder = new Label(wFileComp, SWT.RIGHT); wlCreateParentFolder.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.CreateParentFolder.Label")); props.setLook(wlCreateParentFolder); fdlCreateParentFolder = new FormData(); fdlCreateParentFolder.left = new FormAttachment(0, 0); fdlCreateParentFolder.top = new FormAttachment(wCleanOutput, margin); fdlCreateParentFolder.right = new FormAttachment(middle, -margin); wlCreateParentFolder.setLayoutData(fdlCreateParentFolder); wCreateParentFolder = new Button(wFileComp, SWT.CHECK); wCreateParentFolder .setToolTipText(BaseMessages.getString(PKG, "ParquetOutputDialog.CreateParentFolder.Tooltip")); props.setLook(wCreateParentFolder); fdCreateParentFolder = new FormData(); fdCreateParentFolder.left = new FormAttachment(middle, 0); fdCreateParentFolder.top = new FormAttachment(wCleanOutput, margin); fdCreateParentFolder.right = new FormAttachment(100, 0); wCreateParentFolder.setLayoutData(fdCreateParentFolder); wCreateParentFolder.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); // Create multi-part file? wlAddStepnr = new Label(wFileComp, SWT.RIGHT); wlAddStepnr.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.AddStepnr.Label")); props.setLook(wlAddStepnr); fdlAddStepnr = new FormData(); fdlAddStepnr.left = new FormAttachment(0, 0); fdlAddStepnr.top = new FormAttachment(wCreateParentFolder, margin); fdlAddStepnr.right = new FormAttachment(middle, -margin); wlAddStepnr.setLayoutData(fdlAddStepnr); wAddStepnr = new Button(wFileComp, SWT.CHECK); props.setLook(wAddStepnr); fdAddStepnr = new FormData(); fdAddStepnr.left = new FormAttachment(middle, 0); fdAddStepnr.top = new FormAttachment(wCreateParentFolder, margin); fdAddStepnr.right = new FormAttachment(100, 0); wAddStepnr.setLayoutData(fdAddStepnr); wAddStepnr.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); // Create multi-part file? wlAddPartnr = new Label(wFileComp, SWT.RIGHT); wlAddPartnr.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.AddPartnr.Label")); props.setLook(wlAddPartnr); fdlAddPartnr = new FormData(); fdlAddPartnr.left = new FormAttachment(0, 0); fdlAddPartnr.top = new FormAttachment(wAddStepnr, margin); fdlAddPartnr.right = new FormAttachment(middle, -margin); wlAddPartnr.setLayoutData(fdlAddPartnr); wAddPartnr = new Button(wFileComp, SWT.CHECK); props.setLook(wAddPartnr); fdAddPartnr = new FormData(); fdAddPartnr.left = new FormAttachment(middle, 0); fdAddPartnr.top = new FormAttachment(wAddStepnr, margin); fdAddPartnr.right = new FormAttachment(100, 0); wAddPartnr.setLayoutData(fdAddPartnr); wAddPartnr.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); // Create multi-part file? wlAddDate = new Label(wFileComp, SWT.RIGHT); wlAddDate.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.AddDate.Label")); props.setLook(wlAddDate); fdlAddDate = new FormData(); fdlAddDate.left = new FormAttachment(0, 0); fdlAddDate.top = new FormAttachment(wAddPartnr, margin); fdlAddDate.right = new FormAttachment(middle, -margin); wlAddDate.setLayoutData(fdlAddDate); wAddDate = new Button(wFileComp, SWT.CHECK); props.setLook(wAddDate); fdAddDate = new FormData(); fdAddDate.left = new FormAttachment(middle, 0); fdAddDate.top = new FormAttachment(wAddPartnr, margin); fdAddDate.right = new FormAttachment(100, 0); wAddDate.setLayoutData(fdAddDate); wAddDate.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); // System.out.println("wAddDate.getSelection()="+wAddDate.getSelection()); } }); // Create multi-part file? wlAddTime = new Label(wFileComp, SWT.RIGHT); wlAddTime.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.AddTime.Label")); props.setLook(wlAddTime); fdlAddTime = new FormData(); fdlAddTime.left = new FormAttachment(0, 0); fdlAddTime.top = new FormAttachment(wAddDate, margin); fdlAddTime.right = new FormAttachment(middle, -margin); wlAddTime.setLayoutData(fdlAddTime); wAddTime = new Button(wFileComp, SWT.CHECK); props.setLook(wAddTime); fdAddTime = new FormData(); fdAddTime.left = new FormAttachment(middle, 0); fdAddTime.top = new FormAttachment(wAddDate, margin); fdAddTime.right = new FormAttachment(100, 0); wAddTime.setLayoutData(fdAddTime); wAddTime.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); // Specify date time format? wlSpecifyFormat = new Label(wFileComp, SWT.RIGHT); wlSpecifyFormat.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.SpecifyFormat.Label")); props.setLook(wlSpecifyFormat); fdlSpecifyFormat = new FormData(); fdlSpecifyFormat.left = new FormAttachment(0, 0); fdlSpecifyFormat.top = new FormAttachment(wAddTime, margin); fdlSpecifyFormat.right = new FormAttachment(middle, -margin); wlSpecifyFormat.setLayoutData(fdlSpecifyFormat); wSpecifyFormat = new Button(wFileComp, SWT.CHECK); props.setLook(wSpecifyFormat); wSpecifyFormat.setToolTipText(BaseMessages.getString(PKG, "ParquetOutputDialog.SpecifyFormat.Tooltip")); fdSpecifyFormat = new FormData(); fdSpecifyFormat.left = new FormAttachment(middle, 0); fdSpecifyFormat.top = new FormAttachment(wAddTime, margin); fdSpecifyFormat.right = new FormAttachment(100, 0); wSpecifyFormat.setLayoutData(fdSpecifyFormat); wSpecifyFormat.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); setDateTimeFormat(); } }); // DateTimeFormat wlDateTimeFormat = new Label(wFileComp, SWT.RIGHT); wlDateTimeFormat.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.DateTimeFormat.Label")); props.setLook(wlDateTimeFormat); fdlDateTimeFormat = new FormData(); fdlDateTimeFormat.left = new FormAttachment(0, 0); fdlDateTimeFormat.top = new FormAttachment(wSpecifyFormat, margin); fdlDateTimeFormat.right = new FormAttachment(middle, -margin); wlDateTimeFormat.setLayoutData(fdlDateTimeFormat); wDateTimeFormat = new ComboVar(transMeta, wFileComp, SWT.BORDER | SWT.READ_ONLY); wDateTimeFormat.setEditable(true); props.setLook(wDateTimeFormat); wDateTimeFormat.addModifyListener(lsMod); fdDateTimeFormat = new FormData(); fdDateTimeFormat.left = new FormAttachment(middle, 0); fdDateTimeFormat.top = new FormAttachment(wSpecifyFormat, margin); fdDateTimeFormat.right = new FormAttachment(75, 0); wDateTimeFormat.setLayoutData(fdDateTimeFormat); String[] dats = Const.getDateFormats(); for (String dat : dats) { wDateTimeFormat.add(dat); } // Add File to the result files name wlAddToResult = new Label(wFileComp, SWT.RIGHT); wlAddToResult.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.AddFileToResult.Label")); props.setLook(wlAddToResult); fdlAddToResult = new FormData(); fdlAddToResult.left = new FormAttachment(0, 0); fdlAddToResult.top = new FormAttachment(wDateTimeFormat, 2 * margin); fdlAddToResult.right = new FormAttachment(middle, -margin); wlAddToResult.setLayoutData(fdlAddToResult); wAddToResult = new Button(wFileComp, SWT.CHECK); wAddToResult.setToolTipText(BaseMessages.getString(PKG, "ParquetOutputDialog.AddFileToResult.Tooltip")); props.setLook(wAddToResult); fdAddToResult = new FormData(); fdAddToResult.left = new FormAttachment(middle, 0); fdAddToResult.top = new FormAttachment(wDateTimeFormat, 2 * margin); fdAddToResult.right = new FormAttachment(100, 0); wAddToResult.setLayoutData(fdAddToResult); SelectionAdapter lsSelR = new SelectionAdapter() { public void widgetSelected(SelectionEvent arg0) { input.setChanged(); } }; wAddToResult.addSelectionListener(lsSelR); fdFileComp = new FormData(); fdFileComp.left = new FormAttachment(0, 0); fdFileComp.top = new FormAttachment(0, 0); fdFileComp.right = new FormAttachment(100, 0); fdFileComp.bottom = new FormAttachment(100, 0); wFileComp.setLayoutData(fdFileComp); wFileComp.layout(); wFileTab.setControl(wFileComp); // /////////////////////////////////////////////////////////// // / END OF FILE TAB // /////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////// // / START OF CONTENT TAB // /////////////////////////////////////////////////////////// wContentTab = new CTabItem(wTabFolder, SWT.NONE); wContentTab.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.ContentTab.TabTitle")); FormLayout contentLayout = new FormLayout(); contentLayout.marginWidth = Const.FORM_MARGIN; contentLayout.marginHeight = Const.FORM_MARGIN; Composite wContentComp = new Composite(wTabFolder, SWT.NONE); wContentComp.setLayout(contentLayout); props.setLook(wContentComp); // Block size Line wlBlockSize = new Label(wContentComp, SWT.RIGHT); wlBlockSize.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.BlockSize.Label")); props.setLook(wlBlockSize); fdlBlockSize = new FormData(); fdlBlockSize.left = new FormAttachment(0, 0); fdlBlockSize.right = new FormAttachment(middle, -margin); fdlBlockSize.top = new FormAttachment(0, margin); wlBlockSize.setLayoutData(fdlBlockSize); wBlockSize = new TextVar(transMeta, wContentComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wBlockSize); wBlockSize.addModifyListener(lsMod); fdBlockSize = new FormData(); fdBlockSize.left = new FormAttachment(middle, 0); fdBlockSize.top = new FormAttachment(0, margin); fdBlockSize.right = new FormAttachment(100, 0); wBlockSize.setLayoutData(fdBlockSize); wBlockSize.addModifyListener(lsMod); /* End */ // Page size Line wlPageSize = new Label(wContentComp, SWT.RIGHT); wlPageSize.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.PageSize.Label")); props.setLook(wlPageSize); fdlPageSize = new FormData(); fdlPageSize.left = new FormAttachment(0, 0); fdlPageSize.right = new FormAttachment(middle, -margin); fdlPageSize.top = new FormAttachment(wBlockSize, margin); wlPageSize.setLayoutData(fdlPageSize); wPageSize = new TextVar(transMeta, wContentComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wPageSize); wPageSize.addModifyListener(lsMod); fdPageSize = new FormData(); fdPageSize.left = new FormAttachment(middle, 0); fdPageSize.top = new FormAttachment(wBlockSize, margin); fdPageSize.right = new FormAttachment(100, 0); wPageSize.setLayoutData(fdPageSize); wPageSize.addModifyListener(lsMod); /* End */ // Compression // // DateTimeFormat wlCompression = new Label(wContentComp, SWT.RIGHT); wlCompression.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.Compression.Label")); props.setLook(wlCompression); fdlCompression = new FormData(); fdlCompression.left = new FormAttachment(0, 0); fdlCompression.top = new FormAttachment(wPageSize, margin); fdlCompression.right = new FormAttachment(middle, -margin); wlCompression.setLayoutData(fdlCompression); wCompression = new ComboVar(transMeta, wContentComp, SWT.BORDER | SWT.READ_ONLY); wCompression.setEditable(true); props.setLook(wCompression); wCompression.addModifyListener(lsMod); fdCompression = new FormData(); fdCompression.left = new FormAttachment(middle, 0); fdCompression.top = new FormAttachment(wPageSize, margin); fdCompression.right = new FormAttachment(75, 0); wCompression.setLayoutData(fdCompression); String[] compressions = ParquetOutputMeta.compressionTypes; for (String compression : compressions) { wCompression.add(compression); } // Use configured block size line wlDictionaryCompression = new Label(wContentComp, SWT.RIGHT); wlDictionaryCompression .setText(BaseMessages.getString(PKG, "ParquetOutputDialog.DictionaryCompression.Label")); props.setLook(wlDictionaryCompression); fdlDictionaryCompression = new FormData(); fdlDictionaryCompression.left = new FormAttachment(0, 0); fdlDictionaryCompression.top = new FormAttachment(wCompression, margin); fdlDictionaryCompression.right = new FormAttachment(middle, -margin); wlDictionaryCompression.setLayoutData(fdlDictionaryCompression); wDictionaryCompression = new Button(wContentComp, SWT.CHECK); wDictionaryCompression .setToolTipText(BaseMessages.getString(PKG, "ParquetOutputDialog.DictionaryCompression.Tooltip")); props.setLook(wDictionaryCompression); fdDictionaryCompression = new FormData(); fdDictionaryCompression.left = new FormAttachment(middle, 0); fdDictionaryCompression.top = new FormAttachment(wCompression, margin); fdDictionaryCompression.right = new FormAttachment(100, 0); wDictionaryCompression.setLayoutData(fdDictionaryCompression); wDictionaryCompression.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent arg0) { input.setChanged(); } }); fdContentComp = new FormData(); fdContentComp.left = new FormAttachment(0, 0); fdContentComp.top = new FormAttachment(0, 0); fdContentComp.right = new FormAttachment(100, 0); fdContentComp.bottom = new FormAttachment(100, 0); wContentComp.setLayoutData(fdContentComp); wContentComp.layout(); wContentTab.setControl(wContentComp); // /////////////////////////////////////////////////////////// // / END OF CONTENT TAB // /////////////////////////////////////////////////////////// // Fields tab... // wFieldsTab = new CTabItem(wTabFolder, SWT.NONE); wFieldsTab.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.FieldsTab.TabTitle")); FormLayout fieldsLayout = new FormLayout(); fieldsLayout.marginWidth = Const.FORM_MARGIN; fieldsLayout.marginHeight = Const.FORM_MARGIN; Composite wFieldsComp = new Composite(wTabFolder, SWT.NONE); wFieldsComp.setLayout(fieldsLayout); props.setLook(wFieldsComp); wGet = new Button(wFieldsComp, SWT.PUSH); wGet.setText(BaseMessages.getString(PKG, "System.Button.GetFields")); wGet.setToolTipText(BaseMessages.getString(PKG, "System.Tooltip.GetFields")); fdGet = new FormData(); fdGet.right = new FormAttachment(50, -4 * margin); fdGet.bottom = new FormAttachment(100, 0); wGet.setLayoutData(fdGet); final int FieldsCols = 3; final int FieldsRows = input.getOutputFields().length; colinf = new ColumnInfo[FieldsCols]; colinf[0] = new ColumnInfo(BaseMessages.getString(PKG, "ParquetOutputDialog.StreamColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false); colinf[1] = new ColumnInfo(BaseMessages.getString(PKG, "ParquetOutputDialog.Path.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false); colinf[2] = new ColumnInfo(BaseMessages.getString(PKG, "ParquetOutputDialog.Nullable.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, YES_NO_COMBO, false); wFields = new TableView(transMeta, wFieldsComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, FieldsRows, lsMod, props); fdFields = new FormData(); fdFields.left = new FormAttachment(0, 0); fdFields.top = new FormAttachment(0, 0); fdFields.right = new FormAttachment(100, 0); fdFields.bottom = new FormAttachment(wGet, -margin); wFields.setLayoutData(fdFields); // // Search the fields in the background final Runnable runnable = new Runnable() { public void run() { StepMeta stepMeta = transMeta.findStep(stepname); if (stepMeta != null) { try { RowMetaInterface row = transMeta.getPrevStepFields(stepMeta); // Remember these fields... for (int i = 0; i < row.size(); i++) { inputFields.put(row.getValueMeta(i).getName(), i); } setComboBoxes(); } catch (KettleException e) { logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message")); } } } }; new Thread(runnable).start(); fdFieldsComp = new FormData(); fdFieldsComp.left = new FormAttachment(0, 0); fdFieldsComp.top = new FormAttachment(0, 0); fdFieldsComp.right = new FormAttachment(100, 0); fdFieldsComp.bottom = new FormAttachment(100, 0); wFieldsComp.setLayoutData(fdFieldsComp); wFieldsComp.layout(); wFieldsTab.setControl(wFieldsComp); fdTabFolder = new FormData(); fdTabFolder.left = new FormAttachment(0, 0); fdTabFolder.top = new FormAttachment(wStepname, margin); fdTabFolder.right = new FormAttachment(100, 0); fdTabFolder.bottom = new FormAttachment(100, -50); wTabFolder.setLayoutData(fdTabFolder); wOK = new Button(shell, SWT.PUSH); wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); wCancel = new Button(shell, SWT.PUSH); wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); setButtonPositions(new Button[] { wOK, wCancel }, margin, wTabFolder); wDevelopedBy = new Link(shell, SWT.PUSH); wDevelopedBy.setText( "Developed by Inquidia Consulting (<a href=\"http://www.inquidia.com\">www.inquidia.com</a>)"); fdDevelopedBy = new FormData(); fdDevelopedBy.right = new FormAttachment(100, margin); fdDevelopedBy.bottom = new FormAttachment(100, margin); wDevelopedBy.setLayoutData(fdDevelopedBy); wDevelopedBy.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent selectionEvent) { Program.launch("http://www.inquidia.com"); } }); // Add listeners lsOK = new Listener() { public void handleEvent(Event e) { ok(); } }; lsGet = new Listener() { public void handleEvent(Event e) { get(); } }; lsCancel = new Listener() { public void handleEvent(Event e) { cancel(); } }; wOK.addListener(SWT.Selection, lsOK); wGet.addListener(SWT.Selection, lsGet); wCancel.addListener(SWT.Selection, lsCancel); lsDef = new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent e) { ok(); } }; wStepname.addSelectionListener(lsDef); wFilename.addSelectionListener(lsDef); wBlockSize.addSelectionListener(lsDef); wPageSize.addSelectionListener(lsDef); // Whenever something changes, set the tooltip to the expanded version: wFilename.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { wFilename.setToolTipText(transMeta.environmentSubstitute(wFilename.getText())); } }); /* TODO: Add VFS file chooser. */ wbFilename.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { try { // Setup file type filtering String[] fileFilters = null; String[] fileFilterNames = null; fileFilters = new String[] { "*" }; fileFilterNames = new String[] { BaseMessages.getString(PKG, "System.FileType.AllFiles") }; // Get current file FileObject rootFile = null; FileObject initialFile = null; FileObject defaultInitialFile = null; if (wFilename.getText() != null) { String fileName = transMeta.environmentSubstitute(wFilename.getText()); if (fileName != null && !fileName.equals("")) { try { initialFile = KettleVFS.getFileObject(fileName); rootFile = initialFile.getFileSystem().getRoot(); defaultInitialFile = initialFile; } catch (Exception ex) { // Ignore, unable to obtain initial file, use default } } } if (rootFile == null) { defaultInitialFile = KettleVFS.getFileObject(Spoon.getInstance().getLastFileOpened()); rootFile = defaultInitialFile.getFileSystem().getRoot(); initialFile = defaultInitialFile; } VfsFileChooserDialog fileChooserDialog = Spoon.getInstance().getVfsFileChooserDialog(rootFile, initialFile); fileChooserDialog.defaultInitialFile = defaultInitialFile; FileObject selectedFile = fileChooserDialog.open(shell, null, HadoopSpoonPlugin.HDFS_SCHEME, true, null, fileFilters, fileFilterNames, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE_OR_DIRECTORY); if (selectedFile != null) { wFilename.setText(selectedFile.getURL().toString()); } } catch (KettleFileException ex) { log.logError( BaseMessages.getString(PKG, "HadoopFileInputDialog.FileBrowser.KettleFileException")); } catch (FileSystemException ex) { log.logError( BaseMessages.getString(PKG, "HadoopFileInputDialog.FileBrowser.FileSystemException")); } } }); // Detect X or ALT-F4 or something that kills this window... shell.addShellListener(new ShellAdapter() { public void shellClosed(ShellEvent e) { cancel(); } }); lsResize = new Listener() { public void handleEvent(Event event) { Point size = shell.getSize(); wFields.setSize(size.x - 10, size.y - 50); wFields.table.setSize(size.x - 10, size.y - 50); wFields.redraw(); } }; shell.addListener(SWT.Resize, lsResize); wTabFolder.setSelection(0); // Set the shell size, based upon previous time... setSize(); getData(); input.setChanged(changed); setFilenameInField(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } return stepname; }
From source file:org.pentaho.di.core.plugins.BasePluginType.java
protected List<JarFileAnnotationPlugin> findAnnotatedClassFiles(String annotationClassName) { JarFileCache jarFileCache = JarFileCache.getInstance(); List<JarFileAnnotationPlugin> classFiles = new ArrayList<JarFileAnnotationPlugin>(); // We want to scan the plugins folder for plugin.xml files... ///* w w w.j a v a 2 s .c o m*/ for (PluginFolderInterface pluginFolder : getPluginFolders()) { if (pluginFolder.isPluginAnnotationsFolder()) { try { // Get all the jar files in the plugin folder... // FileObject[] fileObjects = jarFileCache.getFileObjects(pluginFolder); if (fileObjects != null) { for (FileObject fileObject : fileObjects) { // These are the jar files : find annotations in it... // AnnotationDB annotationDB = jarFileCache.getAnnotationDB(fileObject); // These are the jar files : find annotations in it... // Set<String> impls = annotationDB.getAnnotationIndex().get(annotationClassName); if (impls != null) { for (String fil : impls) { classFiles.add(new JarFileAnnotationPlugin(fil, fileObject.getURL(), fileObject.getParent().getURL())); } } } } } catch (Exception e) { e.printStackTrace(); } } } return classFiles; }
From source file:org.pentaho.di.core.plugins.BasePluginType.java
/** * Create a new URL class loader with the jar file specified. Also include all the jar files in the lib folder next to * that file.// www . j a v a 2 s . co m * * @param jarFileUrl * The jar file to include * @param classLoader * the parent class loader to use * @return The URL class loader */ protected URLClassLoader createUrlClassLoader(URL jarFileUrl, ClassLoader classLoader) { List<URL> urls = new ArrayList<URL>(); // Also append all the files in the underlying lib folder if it exists... // try { String libFolderName = new File(URLDecoder.decode(jarFileUrl.getFile(), "UTF-8")).getParent() + "/lib"; if (new File(libFolderName).exists()) { PluginFolder pluginFolder = new PluginFolder(libFolderName, false, true, searchLibDir); FileObject[] libFiles = pluginFolder.findJarFiles(true); for (FileObject libFile : libFiles) { urls.add(libFile.getURL()); } } } catch (Exception e) { LogChannel.GENERAL.logError( "Unexpected error searching for jar files in lib/ folder next to '" + jarFileUrl + "'", e); } urls.add(jarFileUrl); return new KettleURLClassLoader(urls.toArray(new URL[urls.size()]), classLoader); }
From source file:org.pentaho.di.core.plugins.JarFileCache.java
public AnnotationDB getAnnotationDB(FileObject fileObject) throws FileSystemException, IOException { AnnotationDB result = annotationMap.get(fileObject); if (result == null) { result = new AnnotationDB(); result.scanArchives(fileObject.getURL()); annotationMap.put(fileObject, result); }//from ww w .j ava2 s . c o m return result; }
From source file:org.pentaho.di.job.entries.hadooptransjobexecutor.DistributedCacheUtil.java
/** * Stages the source file or folder to a Hadoop file system and sets their permission and replication value appropriately * to be used with the Distributed Cache. WARNING: This will delete the contents of dest before staging the archive. * * @param source File or folder to copy to the file system. If it is a folder all contents will be copied into dest. * @param fs Hadoop file system to store the contents of the archive in * @param dest Destination to copy source into. If source is a file, the new file name will be exactly dest. If source * is a folder its contents will be copied into dest. For more info see * {@link FileSystem#copyFromLocalFile(org.apache.hadoop.fs.Path, org.apache.hadoop.fs.Path)}. * @param overwrite Should an existing file or folder be overwritten? If not an exception will be thrown. * @throws IOException Destination exists is not a directory * @throws KettleFileException Source does not exist or destination exists and overwrite is false. *///from www. jav a2 s . co m public void stageForCache(FileObject source, FileSystem fs, Path dest, boolean overwrite) throws IOException, KettleFileException { if (!source.exists()) { throw new KettleFileException(BaseMessages.getString(DistributedCacheUtil.class, "DistributedCacheUtil.SourceDoesNotExist", source)); } if (fs.exists(dest)) { if (overwrite) { // It is a directory, clear it out fs.delete(dest, true); } else { throw new KettleFileException(BaseMessages.getString(DistributedCacheUtil.class, "DistributedCacheUtil.DestinationExists", dest.toUri().getPath())); } } // Use the same replication we'd use for submitting jobs short replication = (short) fs.getConf().getInt("mapred.submit.replication", 10); Path local = new Path(source.getURL().getPath()); fs.copyFromLocalFile(local, dest); fs.setPermission(dest, CACHED_FILE_PERMISSION); fs.setReplication(dest, replication); }
From source file:org.pentaho.di.job.entries.hadooptransjobexecutor.DistributedCacheUtil.java
/** * Recursively searches for all files starting at the directory provided with the extension provided. If no extension * is provided all files will be returned. * * @param root Directory to start the search for files in * @param extension File extension to search for. If null all files will be returned. * @return List of absolute path names to all files found in {@code dir} and its subdirectories. * @throws KettleFileException/*ww w . j a v a 2 s .co m*/ * @throws FileSystemException */ public List<String> findFiles(FileObject root, final String extension) throws FileSystemException { FileObject[] files = root.findFiles(new FileSelector() { @Override public boolean includeFile(FileSelectInfo fileSelectInfo) throws Exception { return extension == null || extension.equals(fileSelectInfo.getFile().getName().getExtension()); } @Override public boolean traverseDescendents(FileSelectInfo fileSelectInfo) throws Exception { return FileType.FOLDER.equals(fileSelectInfo.getFile().getType()); } }); if (files == null) { return Collections.EMPTY_LIST; } List<String> paths = new ArrayList<String>(); for (FileObject file : files) { try { paths.add(file.getURL().toURI().getPath()); } catch (URISyntaxException ex) { throw new FileSystemException("Error getting URI of file: " + file.getURL().getPath()); } } return paths; }
From source file:org.pentaho.di.job.entries.hadooptransjobexecutor.DistributedCacheUtil.java
/** * Extract a zip archive to a directory. * * @param archive Zip archive to extract * @param dest Destination directory. This must not exist! * @return Directory the zip was extracted into * @throws IllegalArgumentException when the archive file does not exist or the destination directory already exists * @throws IOException//from ww w . j a v a 2 s . c o m * @throws KettleFileException */ public FileObject extract(FileObject archive, FileObject dest) throws IOException, KettleFileException { if (!archive.exists()) { throw new IllegalArgumentException("archive does not exist: " + archive.getURL().getPath()); } if (dest.exists()) { throw new IllegalArgumentException("destination already exists"); } dest.createFolder(); try { byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; int len = 0; ZipInputStream zis = new ZipInputStream(archive.getContent().getInputStream()); try { ZipEntry ze; while ((ze = zis.getNextEntry()) != null) { FileObject entry = KettleVFS.getFileObject(dest + Const.FILE_SEPARATOR + ze.getName()); if (ze.isDirectory()) { entry.createFolder(); continue; } OutputStream os = KettleVFS.getOutputStream(entry, false); try { while ((len = zis.read(buffer)) > 0) { os.write(buffer, 0, len); } } finally { if (os != null) { os.close(); } } } } finally { if (zis != null) { zis.close(); } } } catch (Exception ex) { // Try to clean up the temp directory and all files if (!deleteDirectory(dest)) { throw new KettleFileException("Could not clean up temp dir after error extracting", ex); } throw new KettleFileException("error extracting archive", ex); } return dest; }