Example usage for org.apache.commons.lang3 SystemUtils USER_DIR

List of usage examples for org.apache.commons.lang3 SystemUtils USER_DIR

Introduction

In this page you can find the example usage for org.apache.commons.lang3 SystemUtils USER_DIR.

Prototype

String USER_DIR

To view the source code for org.apache.commons.lang3 SystemUtils USER_DIR.

Click Source Link

Document

The user.dir System Property.

Usage

From source file:org.apache.sshd.SshServerDevelopment.java

protected static final void testSftpAccess(BufferedReader in, PrintStream out, SshServer sshd)
        throws Exception {
    for (;;) {/*from  w w w.ja  v  a  2  s  .c  o  m*/
        String ans = getval(out, in, "root folder [u]ser/c(w)d/(r)oot/XXX path/(q)uit");
        if (isQuit(ans)) {
            break;
        }

        char op = StringUtils.isEmpty(ans) ? '\0' : Character.toLowerCase(ans.charAt(0));
        String path = null;
        switch (op) {
        case '\0':
        case 'u':
            path = SystemUtils.USER_HOME;
            break;
        case 'w':
            path = SystemUtils.USER_DIR;
            break;

        case 'r': {
            File[] roots = File.listRoots();
            if (ArrayUtils.isEmpty(roots)) {
                System.err.println("No roots listed");
                break;
            }

            if (roots.length == 1) {
                path = roots[0].getAbsolutePath();
                break;
            }

            File selected = inputListChoice(out, in, "Roots", Arrays.asList(roots), null);
            if (selected != null) {
                path = selected.getAbsolutePath();
            }
        }
            break;

        default: // assume a path
            path = ans;
        }

        if (StringUtils.isEmpty(path)) {
            continue;
        }

        final File rootDir = new File(path);
        NativeFileSystemFactory factory = new ExtendedNativeFileSystemFactory() {
            @Override
            protected File getSessionRootDir(Session session) {
                return rootDir;
            }
        };
        if (!rootDir.exists()) {
            ans = getval(out, in, "create " + rootDir + " y/[n]/q");
            if (isQuit(ans)) {
                continue;
            }

            if (!StringUtils.isEmpty(ans)) {
                factory.setCreateHome('y' == Character.toLowerCase(ans.charAt(0)));
            }
        }
        sshd.setFileSystemFactory(factory);
        break;
    }

    sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
    sshd.setCommandFactory(new ScpCommandFactory());
    sshd.setShellFactory(ECHO_SHELL);
    waitForExit(in, out, sshd);
}

From source file:pcgen.gui2.converter.panel.WriteDirectoryPanel.java

@Override
public boolean performAnalysis(CDOMObject pc) {
    TaskStrategyMessage.sendStatus(this, "Finding Data Directories");
    campaignList = pc.getListFor(ListKey.CAMPAIGN);
    path = pc.get(ObjectKey.WRITE_DIRECTORY);
    if (path != null) {
        fileLabel.setText(path.getAbsolutePath());
    } else {//from   w w  w.j  a v a 2 s .co  m
        PCGenSettings context = PCGenSettings.getInstance();
        String outputPathName = context.initProperty(PCGenSettings.CONVERT_OUTPUT_SAVE_PATH,
                SystemUtils.USER_DIR);
        path = new File(outputPathName);
    }
    pc.put(ObjectKey.WRITE_DIRECTORY, path);
    fireProgressEvent(ProgressEvent.ALLOWED);
    return true;
}

From source file:pcgen.gui2.converter.PCGenDataConvert.java

public static void main(String[] args) {
    Logging.log(Level.INFO, "Starting PCGen Data Converter v" + PCGenPropBundle.getVersionNumber()); //$NON-NLS-1$
    configFactory = new PropertyContextFactory(SystemUtils.USER_DIR);
    configFactory.registerAndLoadPropertyContext(ConfigurationSettings.getInstance());
    Main.loadProperties(true);/*w ww  . j a va 2 s.  com*/
    getConverter().setVisible(true);
}

From source file:pcgen.persistence.lst.DataLoadTest.java

private static void loadGameModes() {
    String configFolder = "testsuite";
    String pccLoc = TestHelper.findDataFolder();
    System.out.println("Got data folder of " + pccLoc);
    try {/*from   ww  w  . j a v  a  2s  .  c o  m*/
        TestHelper.createDummySettingsFile(TEST_CONFIG_FILE, configFolder, pccLoc);
    } catch (IOException e) {
        Logging.errorPrint("DataTest.loadGameModes failed", e);
    }

    PropertyContextFactory configFactory = new PropertyContextFactory(SystemUtils.USER_DIR);
    configFactory.registerAndLoadPropertyContext(ConfigurationSettings.getInstance(TEST_CONFIG_FILE));
    Main.loadProperties(false);
    PCGenTask loadPluginTask = Main.createLoadPluginTask();
    loadPluginTask.execute();
    GameModeFileLoader gameModeFileLoader = new GameModeFileLoader();
    gameModeFileLoader.execute();
    CampaignFileLoader campaignFileLoader = new CampaignFileLoader();
    campaignFileLoader.execute();
}

From source file:pcgen.system.ConfigurationSettings.java

/**
 * @return the current user directory
 */
public static String getUserDir() {
    return SystemUtils.USER_DIR;
}

From source file:pcgen.system.ConfigurationSettings.java

private static String expandRelativePath(String path) {
    if (path.startsWith("@")) {
        path = SystemUtils.USER_DIR + File.separator + path.substring(1);
    }//  www .ja  va  2 s .c  om
    return path;
}

From source file:pcgen.system.ConfigurationSettings.java

private static String unexpandRelativePath(String path) {
    if (path.startsWith(SystemUtils.USER_DIR + File.separator)) {
        path = '@' + path.substring(SystemUtils.USER_DIR.length() + 1);
    }/*from   w  w  w  .java  2  s .  c o m*/
    return path;
}

From source file:pcgen.system.Main.java

private static String getConfigPath() {
    //TODO: convert to a proper command line argument instead of a -D java property
    // First see if it was specified on the command line
    String aPath = System.getProperty("pcgen.config"); //$NON-NLS-1$
    if (aPath != null) {
        File testPath = new File(aPath);
        // Then make sure it's an existing folder
        if (testPath.exists() && testPath.isDirectory()) {
            return aPath;
        }/*from  w  ww.  ja va  2 s  .com*/
    }
    // Otherwise return user dir
    return SystemUtils.USER_DIR;
}

From source file:pcgen.system.Main.java

public static boolean loadCharacterAndExport(String characterFile, String exportSheet, String outputFile,
        String configFile) {/*from   ww w .  ja  va  2 s  .  c o m*/
    Main.characterFile = characterFile;
    Main.exportSheet = exportSheet;
    Main.outputFile = outputFile;

    configFactory = new PropertyContextFactory(SystemUtils.USER_DIR);
    configFactory.registerAndLoadPropertyContext(ConfigurationSettings.getInstance(configFile));
    return startupWithoutGUI();
}

From source file:pcgen.util.TestHelper.java

public static void loadGameModes(String testConfigFile) {
    String configFolder = "testsuite";
    String pccLoc = TestHelper.findDataFolder();
    System.out.println("Got data folder of " + pccLoc);
    try {/*from w ww .  j a  v  a 2  s  . c  o m*/
        TestHelper.createDummySettingsFile(testConfigFile, configFolder, pccLoc);
    } catch (IOException e) {
        Logging.errorPrint("DataTest.loadGameModes failed", e);
    }

    PropertyContextFactory configFactory = new PropertyContextFactory(SystemUtils.USER_DIR);
    configFactory.registerAndLoadPropertyContext(ConfigurationSettings.getInstance(testConfigFile));
    Main.loadProperties(false);
    PCGenTask loadPluginTask = Main.createLoadPluginTask();
    loadPluginTask.execute();
    GameModeFileLoader gameModeFileLoader = new GameModeFileLoader();
    gameModeFileLoader.execute();
    CampaignFileLoader campaignFileLoader = new CampaignFileLoader();
    campaignFileLoader.execute();
}