List of usage examples for org.apache.commons.vfs2.provider URLFileName getPath
public String getPath()
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileObject.java
/** * Convenience method that returns the container ( i.e. "bucket ) and path from the current URL. * /*from w w w . j a v a2 s .c o m*/ * @return A tuple containing the bucket name and the path. */ private Pair<String, String> getContainerAndPath() { Pair<String, String> res = null; try { URLFileName currName = (URLFileName) getName(); String currPathStr = currName.getPath(); currPathStr = StringUtils.stripStart(currPathStr, "/"); if (StringUtils.isBlank(currPathStr)) { log.warn(String.format("getContainerAndPath() : Path '%s' does not appear to be valid", currPathStr)); return null; } // Deal with the special case of the container root. if (StringUtils.contains(currPathStr, "/") == false) { // Container and root return new ImmutablePair<>(currPathStr, "/"); } String[] resArray = StringUtils.split(currPathStr, "/", 2); res = new ImmutablePair<>(resArray[0], resArray[1]); } catch (Exception ex) { log.error(String.format("getContainerAndPath() : Path does not appear to be valid"), ex); } return res; }
From source file:com.sludev.commons.vfs2.provider.azure.AzFileObject.java
/** * Convenience method that returns the container and path from the current URL. * /*w w w . j a va 2 s .c o m*/ * @return A tuple containing the container name and the path. */ protected Pair<String, String> getContainerAndPath() { Pair<String, String> res = null; try { URLFileName currName = (URLFileName) getName(); String currNameStr = currName.getPath(); currNameStr = StringUtils.stripStart(currNameStr, "/"); if (StringUtils.isBlank(currNameStr)) { log.warn(String.format("getContainerAndPath() : Path '%s' does not appear to be valid", currNameStr)); return null; } // Deal with the special case of the container root. if (StringUtils.contains(currNameStr, "/") == false) { // Container and root return new ImmutablePair<>(currNameStr, "/"); } String[] resArray = StringUtils.split(currNameStr, "/", 2); res = new ImmutablePair<>(resArray[0], resArray[1]); } catch (Exception ex) { log.error(String.format("getContainerAndPath() : Path does not appear to be valid"), ex); } return res; }
From source file:org.pentaho.big.data.impl.vfs.hdfs.HDFSFileNameParser.java
@Override public FileName parseUri(VfsComponentContext context, FileName base, String filename) throws FileSystemException { URLFileName fileNameURLFileName = (URLFileName) super.parseUri(context, base, filename); return new URLFileName(fileNameURLFileName.getScheme(), getHostNameCaseSensitive(filename), fileNameURLFileName.getPort(), fileNameURLFileName.getDefaultPort(), fileNameURLFileName.getUserName(), fileNameURLFileName.getPassword(), fileNameURLFileName.getPath(), fileNameURLFileName.getType(), fileNameURLFileName.getQueryString()); }
From source file:org.pentaho.big.data.impl.vfs.hdfs.HDFSFileNameParserTest.java
@Test public void testParseUriUserNameFilePath() throws FileSystemException { String filename = "hdfs://root:password@testUpperCaseHost:8080/long/test/name"; URLFileName hdfsFileName = (URLFileName) HDFSFileNameParser.getInstance().parseUri(null, null, filename); URLFileName urlFileName = (URLFileName) new URLFileNameParser(7000).parseUri(null, null, filename); assertEquals(8080, hdfsFileName.getPort()); assertEquals("root", hdfsFileName.getUserName()); assertEquals("/long/test/name", hdfsFileName.getPath()); assertEquals("password", hdfsFileName.getPassword()); assertEquals(urlFileName.getType(), hdfsFileName.getType()); assertEquals(urlFileName.getQueryString(), hdfsFileName.getQueryString()); }
From source file:org.pentaho.googlecloudstorage.vfs.GoogleCloudStorageFileObject.java
/** * Gets the blob from the Google Cloud Storage api for the file/folder * * @return The Blob that represents the file/folder *///from w w w. j av a 2s . com public Blob getBlob() { URLFileName urlFileName = (URLFileName) this.getName(); Bucket bucket = storage.get(urlFileName.getHostName()); if (urlFileName.getPath().equals(DELIMITER)) { return null; } String stripped = urlFileName.getPath().substring(1, urlFileName.getPath().length()); Blob blob = bucket.get(stripped); if (blob == null) { blob = bucket.get(stripped.concat(DELIMITER)); } return blob; }
From source file:org.pentaho.vfs.ui.VfsFileChooserDialog.java
public FileObject open(Shell applicationShell, String[] schemeRestrictions, String initialScheme, boolean showFileScheme, String fileName, String[] fileFilters, String[] fileFilterNames, boolean returnUserAuthenticatedFile, int fileDialogMode, boolean showLocation, boolean showCustomUI) { this.fileDialogMode = fileDialogMode; this.fileFilters = fileFilters; this.fileFilterNames = fileFilterNames; this.applicationShell = applicationShell; this.showFileScheme = showFileScheme; this.initialScheme = initialScheme; this.schemeRestrictions = schemeRestrictions; this.showLocation = showLocation; this.showCustomUI = showCustomUI; FileObject tmpInitialFile = initialFile; if (defaultInitialFile != null && rootFile == null) { try {/*from ww w .ja v a2s .co m*/ rootFile = defaultInitialFile.getFileSystem().getRoot(); initialFile = defaultInitialFile; } catch (FileSystemException ignored) { // well we tried } } createDialog(applicationShell); if (!showLocation) { comboPanel.setParent(fakeShell); } else { comboPanel.setParent(customUIPanel); } if (!showCustomUI) { customUIPanel.setParent(fakeShell); } else { customUIPanel.setParent(dialog); } // create our file chooser tool bar, contains parent folder combo and various controls createToolbarPanel(dialog); // create our vfs browser component createVfsBrowser(dialog); populateCustomUIPanel(dialog); if (fileDialogMode == VFS_DIALOG_SAVEAS) { createFileNamePanel(dialog, fileName); } else { // create file filter panel createFileFilterPanel(dialog); } // create our ok/cancel buttons createButtonPanel(dialog); initialFile = tmpInitialFile; // set the initial file selection try { if (initialFile != null || rootFile != null) { vfsBrowser.selectTreeItemByFileObject(initialFile != null ? initialFile : rootFile, true); updateParentFileCombo(initialFile != null ? initialFile : rootFile); setSelectedFile(initialFile != null ? initialFile : rootFile); openFileCombo.setText( initialFile != null ? initialFile.getName().getURI() : rootFile.getName().getURI()); } } catch (FileSystemException e) { MessageBox box = new MessageBox(dialog.getShell()); box.setText(Messages.getString("VfsFileChooserDialog.error")); //$NON-NLS-1$ box.setMessage(e.getMessage()); box.open(); } // set the size and show the dialog int height = 550; int width = 800; dialog.setSize(width, height); Rectangle bounds = dialog.getDisplay().getPrimaryMonitor().getClientArea(); int x = (bounds.width - width) / 2; int y = (bounds.height - height) / 2; dialog.setLocation(x, y); dialog.open(); if (rootFile != null && fileDialogMode == VFS_DIALOG_SAVEAS) { if (!rootFile.getFileSystem().hasCapability(Capability.WRITE_CONTENT)) { MessageBox messageDialog = new MessageBox(dialog.getShell(), SWT.OK); messageDialog.setText(Messages.getString("VfsFileChooserDialog.warning")); //$NON-NLS-1$ messageDialog.setMessage(Messages.getString("VfsFileChooserDialog.noWriteSupport")); //$NON-NLS-1$ messageDialog.open(); } } vfsBrowser.fileSystemTree.forceFocus(); while (!dialog.isDisposed()) { if (!dialog.getDisplay().readAndDispatch()) dialog.getDisplay().sleep(); } // we just woke up, we are probably disposed already.. if (!dialog.isDisposed()) { hideCustomPanelChildren(); dialog.dispose(); } if (okPressed) { FileObject returnFile = vfsBrowser.getSelectedFileObject(); if (returnFile != null && fileDialogMode == VFS_DIALOG_SAVEAS) { try { if (returnFile.getType().equals(FileType.FILE)) { returnFile = returnFile.getParent(); } returnFile = returnFile.resolveFile(enteredFileName); } catch (FileSystemException e) { e.printStackTrace(); } } // put user/pass on the filename so it comes out in the getUri call. if (!returnUserAuthenticatedFile) { // make sure to put the user/pass on the url if it's not there if (returnFile != null && returnFile.getName() instanceof URLFileName) { URLFileName urlFileName = (URLFileName) returnFile.getName(); if (urlFileName.getUserName() == null || urlFileName.getPassword() == null) { // set it String user = ""; String pass = ""; UserAuthenticator userAuthenticator = DefaultFileSystemConfigBuilder.getInstance() .getUserAuthenticator(returnFile.getFileSystem().getFileSystemOptions()); if (userAuthenticator != null) { UserAuthenticationData data = userAuthenticator .requestAuthentication(AUTHENTICATOR_TYPES); user = String.valueOf(data.getData(UserAuthenticationData.USERNAME)); pass = String.valueOf(data.getData(UserAuthenticationData.PASSWORD)); try { user = URLEncoder.encode(user, "UTF-8"); pass = URLEncoder.encode(pass, "UTF-8"); } catch (UnsupportedEncodingException e) { // ignore, just use the un encoded values } } // build up the url with user/pass on it int port = urlFileName.getPort(); String portString = (port < 1) ? "" : (":" + port); String urlWithUserPass = urlFileName.getScheme() + "://" + user + ":" + pass + "@" + urlFileName.getHostName() + portString + urlFileName.getPath(); try { returnFile = currentPanel.resolveFile(urlWithUserPass); } catch (FileSystemException e) { // couldn't resolve with user/pass on url??? interesting e.printStackTrace(); } } } } return returnFile; } else { return null; } }