List of usage examples for org.apache.commons.vfs FileObject getName
public FileName getName();
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
protected boolean backupFile(FileObject src, FileObject targetDir) { try {/*from ww w . ja v a 2 s . c o m*/ int attempt = 1; FileObject bkp = targetDir.resolveFile(src.getName().getBaseName() + ".bkp." + attempt); while (bkp.exists() && attempt < 99) { attempt++; bkp = targetDir.resolveFile(src.getName().getBaseName() + ".bkp." + attempt); } if (bkp.exists()) { getPrinter().printActionErrStatus("Backup", src.getName().getBaseName(), "Too many backups already"); return false; } bkp.copyFrom(src, Selectors.SELECT_SELF); getPrinter().printActionOkStatus("Backup", src.getName().getBaseName(), bkp.getName().getFriendlyURI()); return true; } catch (IOException e) { getPrinter().printActionErrStatus("Backup", src.getName().getBaseName(), e.getMessage()); return false; } }
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
public boolean backupGatewayConfigurations(boolean remove) { try {//w w w.jav a 2 s. co m FileObject[] libs = targetJOSSOConfDir.getChildren(); for (int i = 0; i < libs.length; i++) { FileObject cfgFile = libs[i]; if (!cfgFile.getType().getName().equals(FileType.FILE.getName())) { // ignore folders continue; } if (cfgFile.getName().getBaseName().startsWith("josso-") && !cfgFile.getName().getBaseName().startsWith("josso-agent") && (cfgFile.getName().getBaseName().endsWith(".xml") || (cfgFile.getName().getBaseName().endsWith(".properties")))) { //backup files in the same folder they're installed in backupFile(cfgFile, cfgFile.getParent()); if (remove) { cfgFile.delete(); } } } } catch (Exception e) { getPrinter().printErrStatus("BackupGatewayConfigurations", e.getMessage()); return false; } return true; }
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
public boolean updateAgentConfiguration(String idpHostName, String idpPort, String idpType) { if (agentConfigFileInstalled) { String hostAndPort = idpHostName; if (!idpPort.equals("80")) { hostAndPort += ":" + idpPort; }/*from w ww .j a v a2 s.c o m*/ if (!hostAndPort.equals("localhost:8080") || idpType.equals("atricore-idbus")) { try { FileObject agentConfigFile = targetJOSSOConfDir.resolveFile("josso-agent-config.xml"); if (agentConfigFile.exists()) { log.error("DEPRECATED API CALL:updateAgentConfiguration"); // Get a DOM document of the josso-agent-config.xml Node configXmlDom = readContentAsDom(agentConfigFile); String gatewayLoginUrl = "http://" + hostAndPort; String gatewayLogoutUrl = "http://" + hostAndPort; // TODO : PB-1 should also be variable! if (idpType.equals("atricore-idbus")) { gatewayLoginUrl += "/IDBUS/BP-1/JOSSO/SSO/REDIR"; gatewayLogoutUrl += "/IDBUS/BP-1/JOSSO/SLO/REDIR"; } else { gatewayLoginUrl += "/josso/signon/login.do"; gatewayLogoutUrl += "/josso/signon/logout.do"; } String updateIDP = "<xupdate:update select=\"//gatewayLoginUrl\">" + gatewayLoginUrl + "</xupdate:update>"; updateIDP += "<xupdate:update select=\"//gatewayLogoutUrl\">" + gatewayLogoutUrl + "</xupdate:update>"; updateIDP += "<xupdate:update select=\"//@endpoint\">" + hostAndPort + "</xupdate:update>"; updateIDP += "<xupdate:update select=\"//property[@name='ignoredReferrers']/list/value\">" + "http://" + hostAndPort + "/IDBUS</xupdate:update>"; if (idpType.equals("atricore-idbus")) { updateIDP += "<xupdate:append select=\"//protocol:ws-service-locator\">"; updateIDP += "<xupdate:attribute name=\"identityManagerServicePath\">IDBUS/BP-1/JOSSO/SSOIdentityManager/SOAP</xupdate:attribute>"; updateIDP += "<xupdate:attribute name=\"identityProviderServicePath\">IDBUS/BP-1/JOSSO/SSOIdentityProvider/SOAP</xupdate:attribute>"; updateIDP += "<xupdate:attribute name=\"sessionManagerServicePath\">IDBUS/BP-1/JOSSO/SSOSessionManager/SOAP</xupdate:attribute>"; updateIDP += "</xupdate:append>"; } String updateIDPQryStr = XUpdateUtil.XUPDATE_START + updateIDP + XUpdateUtil.XUPDATE_END; log.debug("XUPDATE QUERY: \n" + updateIDPQryStr); XUpdateQuery updateIDPQry = new XUpdateQueryImpl(); updateIDPQry.setQString(updateIDPQryStr); updateIDPQry.execute(configXmlDom); getPrinter().printActionOkStatus("Configure", "IDP type", idpType); getPrinter().printActionOkStatus("Configure", "IDP host and port", hostAndPort); // Write modifications to file writeContentFromDom(configXmlDom, agentConfigFile); getPrinter().printActionOkStatus("Save", agentConfigFile.getName().getBaseName(), agentConfigFile.getName().getFriendlyURI()); return true; } } catch (Exception e) { getPrinter().printErrStatus("UpdateAgentConfiguration", e.getMessage()); return false; } } } return false; }
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
public boolean removeOldComponents(boolean backup) { try {//from w w w . j av a2 s .c om FileObject[] sharedLibs = targetJOSSOSharedLibDir.getChildren(); for (int i = 0; i < sharedLibs.length; i++) { FileObject jarFile = sharedLibs[i]; if (!jarFile.getType().getName().equals(FileType.FILE.getName())) { // ignore folders continue; } if (jarFile.getName().getBaseName().startsWith("josso-") && jarFile.getName().getBaseName().endsWith(".jar")) { if (backup) { // backup files in the same folder they're installed in backupFile(jarFile, jarFile.getParent()); } jarFile.delete(); } } FileObject[] libs = targetJOSSOLibDir.getChildren(); for (int i = 0; i < libs.length; i++) { FileObject jarFile = libs[i]; if (!jarFile.getType().getName().equals(FileType.FILE.getName())) { // ignore folders continue; } if (jarFile.getName().getBaseName().startsWith("josso-") && jarFile.getName().getBaseName().endsWith(".jar")) { if (backup) { // backup files in the same folder they're installed in backupFile(jarFile, jarFile.getParent()); } jarFile.delete(); } } } catch (Exception e) { getPrinter().printErrStatus("RemoveOldComponents", e.getMessage()); return false; } return true; }
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
public boolean removeOldJar(String fullJarName, FileObject destDir, boolean backup) { try {// w ww . j a v a2 s.co m if (fullJarName.endsWith(".jar") && fullJarName.lastIndexOf("-") != -1) { String jarNameWithoutVersion = fullJarName.substring(0, fullJarName.lastIndexOf("-")); FileObject[] files = destDir.getChildren(); for (int i = 0; i < files.length; i++) { FileObject file = files[i]; if (!file.getType().getName().equals(FileType.FILE.getName())) { // ignore folders continue; } String fileName = file.getName().getBaseName(); if (fileName.startsWith(jarNameWithoutVersion) && fileName.endsWith(".jar") && fileName .substring(jarNameWithoutVersion.length(), jarNameWithoutVersion.length() + 2) .matches("-[0-9]|\\.j")) { if (backup) { // backup files in the same folder they're installed in backupFile(file, file.getParent()); } file.delete(); break; } } } } catch (Exception e) { getPrinter().printErrStatus("RemoveOldJar", e.getMessage()); return false; } return true; }
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
public boolean installJar(FileObject srcFile, FileObject destFolder, String newName, boolean explode, boolean replace) throws IOException { try {//from w ww . j a v a 2 s .c o m if (explode) { FileObject jarFile = getFileSystemManager() .resolveFile("jar:" + srcFile.getName().getFriendlyURI()); if (log.isDebugEnabled()) log.debug("Exploding JAR [" + srcFile.getName().getFriendlyURI() + "] to [" + destFolder.getName().getFriendlyURI() + "]"); installFolder(jarFile, destFolder, newName, replace); } else { installFile(srcFile, destFolder, newName, replace); } getPrinter().printActionOkStatus("Unjar", srcFile.getName().getBaseName(), destFolder.getName().getFriendlyURI()); return true; } catch (FileSystemException e) { log.error("Cannot unjar file " + srcFile.getName().getFriendlyURI() + " : " + e.getMessage(), e); getPrinter().printActionErrStatus("Unjar", srcFile.getName().getBaseName(), e.getMessage()); } return false; }
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
protected boolean installFile(String fileName, FileObject srcDir, FileObject destDir, boolean replace) throws IOException { try {//from w w w .j a v a 2 s. c o m FileObject srcFile = srcDir.resolveFile(fileName); return installFile(srcFile, destDir, srcFile.getName().getBaseName(), replace); } finally { printer.flush(); } }
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
protected boolean installFile(FileObject srcFile, FileObject destDir, boolean replace) throws IOException { return installFile(srcFile, destDir, srcFile.getName().getBaseName(), replace); }
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
protected boolean installFile(FileObject srcFile, FileObject destDir, String newName, boolean replace) throws IOException { try {/* w w w.ja v a 2s . c o m*/ String fname = srcFile.getName().getBaseName(); if (srcFile == null || !srcFile.exists()) { printInstallErrStatus(fname, "Source file not found " + fname); throw new IOException("Source file not found " + fname); } // Validates src and dest files if (destDir == null || !destDir.exists()) { printInstallErrStatus(fname, "Target directory not found " + destDir.getURL()); throw new IOException("Target directory not found " + destDir.getURL()); } FileObject destFile = destDir.resolveFile(newName); boolean exists = destFile.exists(); if (!replace && exists) { printInstallWarnStatus(fname, "Not replaced (see --replace option)"); if (fname.equals("josso-agent-config.xml")) { agentConfigFileInstalled = false; } return false; } FileUtil.copyContent(srcFile, destFile); printInstallOkStatus(fname, (exists ? "Replaced " : "Created ") + destFile.getName().getFriendlyURI()); return true; } finally { printer.flush(); } }
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
/** * @param srcFolder/* w w w. j a v a 2 s . c o m*/ * @param destDir * @param replace * @throws java.io.IOException */ protected void installFolder(FileObject srcFolder, FileObject destDir, String newName, boolean replace) throws IOException { // Check destination folder if (!destDir.exists()) { printInstallErrStatus(srcFolder.getName().getBaseName(), "Target directory not found " + destDir.getName().getBaseName()); throw new IOException("Target directory not found " + destDir.getName().getBaseName()); } // This is the new folder we're creating in destination. FileObject newFolder = destDir.resolveFile(newName); boolean exists = newFolder.exists(); if (!replace && exists) { printInstallWarnStatus(newFolder.getName().getBaseName(), "Not replaced (see --replace option)"); return; } if (exists) { // remove all descendents (removes old jars and other files when upgrading josso gateway) newFolder.delete(Selectors.EXCLUDE_SELF); } newFolder.copyFrom(srcFolder, Selectors.SELECT_ALL); // Copy ALL descendats printInstallOkStatus(srcFolder.getName().getBaseName(), (exists ? "Replaced " : "Created ") + newFolder.getName().getFriendlyURI()); }