Example usage for java.io File separatorChar

List of usage examples for java.io File separatorChar

Introduction

In this page you can find the example usage for java.io File separatorChar.

Prototype

char separatorChar

To view the source code for java.io File separatorChar.

Click Source Link

Document

The system-dependent default name-separator character.

Usage

From source file:filterviewplugin.FilterViewSettingsTab.java

public JPanel createSettingsPanel() {
    final EnhancedPanelBuilder panelBuilder = new EnhancedPanelBuilder(FormFactory.RELATED_GAP_COLSPEC.encode()
            + ',' + FormFactory.PREF_COLSPEC.encode() + ',' + FormFactory.RELATED_GAP_COLSPEC.encode() + ','
            + FormFactory.PREF_COLSPEC.encode() + ", fill:default:grow");
    final CellConstraints cc = new CellConstraints();

    final JLabel label = new JLabel(mLocalizer.msg("daysToShow", "Days to show"));

    panelBuilder.addRow();//from ww  w .ja  va  2  s  .c om
    panelBuilder.add(label, cc.xy(2, panelBuilder.getRow()));

    final SpinnerNumberModel model = new SpinnerNumberModel(3, 1, 7, 1);
    mSpinner = new JSpinner(model);
    mSpinner.setValue(mSettings.getDays());
    panelBuilder.add(mSpinner, cc.xy(4, panelBuilder.getRow()));

    panelBuilder.addParagraph(mLocalizer.msg("filters", "Filters to show"));

    mFilterList = new SelectableItemList(mSettings.getActiveFilterNames(),
            FilterViewSettings.getAvailableFilterNames());
    mIcons.clear();
    for (String filterName : FilterViewSettings.getAvailableFilterNames()) {
        mIcons.put(filterName, mSettings.getFilterIconName(mSettings.getFilter(filterName)));
    }
    mFilterList.addCenterRendererComponent(String.class, new SelectableItemRendererCenterComponentIf() {
        private DefaultListCellRenderer mRenderer = new DefaultListCellRenderer();

        public void calculateSize(JList list, int index, JPanel contentPane) {
        }

        public JPanel createCenterPanel(JList list, Object value, int index, boolean isSelected,
                boolean isEnabled, JScrollPane parentScrollPane, int leftColumnWidth) {
            DefaultListCellRenderer label = (DefaultListCellRenderer) mRenderer
                    .getListCellRendererComponent(list, value, index, isSelected, false);
            String filterName = value.toString();
            String iconFileName = mIcons.get(filterName);
            Icon icon = null;
            if (!StringUtils.isEmpty(iconFileName)) {
                try {
                    icon = FilterViewPlugin.getInstance().getIcon(
                            FilterViewSettings.getIconDirectoryName() + File.separatorChar + iconFileName);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                label.setIcon(icon);
            }
            String text = filterName;
            if (icon == null) {
                text += " (" + mLocalizer.msg("noIcon", "no icon") + ')';
            }
            label.setText(text);
            label.setHorizontalAlignment(SwingConstants.LEADING);
            label.setVerticalAlignment(SwingConstants.CENTER);
            label.setOpaque(false);

            JPanel panel = new JPanel(new BorderLayout());
            if (isSelected && isEnabled) {
                panel.setOpaque(true);
                panel.setForeground(list.getSelectionForeground());
                panel.setBackground(list.getSelectionBackground());
            } else {
                panel.setOpaque(false);
                panel.setForeground(list.getForeground());
                panel.setBackground(list.getBackground());
            }
            panel.add(label, BorderLayout.WEST);
            return panel;
        }
    });

    panelBuilder.addGrowingRow();
    panelBuilder.add(mFilterList, cc.xyw(2, panelBuilder.getRow(), panelBuilder.getColumnCount() - 1));

    panelBuilder.addRow();
    mFilterButton = new JButton(mLocalizer.msg("changeIcon", "Change icon"));
    mFilterButton.setEnabled(false);
    panelBuilder.add(mFilterButton, cc.xyw(2, panelBuilder.getRow(), 1));

    mRemoveButton = new JButton(mLocalizer.msg("deleteIcon", "Remove icon"));
    mRemoveButton.setEnabled(false);
    panelBuilder.add(mRemoveButton, cc.xyw(4, panelBuilder.getRow(), 1));

    mFilterButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            SelectableItem item = (SelectableItem) mFilterList.getSelectedValue();
            String filterName = (String) item.getItem();
            chooseIcon(filterName);
        }
    });

    mFilterList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            mFilterButton.setEnabled(mFilterList.getSelectedValue() != null);
            mRemoveButton.setEnabled(mFilterButton.isEnabled());
        }
    });

    mRemoveButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            SelectableItem item = (SelectableItem) mFilterList.getSelectedValue();
            String filterName = (String) item.getItem();
            mIcons.put(filterName, "");
            mFilterList.updateUI();
        }
    });

    return panelBuilder.getPanel();
}

From source file:com.adgear.data.plugin.IDLSchemaMojo.java

protected File getDir(File outputDir, Schema s) {
    final String namespace = s.getNamespace();
    if (namespace != null && !namespace.isEmpty()) {
        String path = namespace.replace('.', File.separatorChar) + File.separatorChar;
        return new File(outputDir, path);
    } else {/*from  w w w.ja va2s  . co  m*/
        return outputDir;
    }
}

From source file:com.stimulus.archiva.domain.FileSystem.java

public String getViewPath() {
    return getDir(applicationPath + File.separatorChar + "temp");
}

From source file:com.amalto.core.jobox.watch.JoboxListener.java

public void contextChanged(String jobFile, String context) {
    File entity = new File(jobFile);
    String sourcePath = jobFile;//from  ww w . j  a v  a2  s .  com
    int dotMark = jobFile.lastIndexOf("."); //$NON-NLS-1$
    int separateMark = jobFile.lastIndexOf(File.separatorChar);
    if (dotMark != -1) {
        sourcePath = System.getProperty("java.io.tmpdir") + File.separatorChar //$NON-NLS-1$
                + jobFile.substring(separateMark, dotMark);
    }
    try {
        JoboxUtil.extract(jobFile, System.getProperty("java.io.tmpdir") + File.separatorChar); //$NON-NLS-1$
    } catch (Exception e1) {
        LOGGER.error("Extraction exception occurred.", e1);
        return;
    }
    List<File> resultList = new ArrayList<File>();
    JoboxUtil.findFirstFile(null, new File(sourcePath), "classpath.jar", resultList); //$NON-NLS-1$
    if (!resultList.isEmpty()) {
        JarInputStream jarIn = null;
        JarOutputStream jarOut = null;
        try {
            JarFile jarFile = new JarFile(resultList.get(0));
            Manifest mf = jarFile.getManifest();
            jarIn = new JarInputStream(new FileInputStream(resultList.get(0)));
            Manifest newManifest = jarIn.getManifest();
            if (newManifest == null) {
                newManifest = new Manifest();
            }
            newManifest.getMainAttributes().putAll(mf.getMainAttributes());
            newManifest.getMainAttributes().putValue("activeContext", context); //$NON-NLS-1$
            jarOut = new JarOutputStream(new FileOutputStream(resultList.get(0)), newManifest);
            byte[] buf = new byte[4096];
            JarEntry entry;
            while ((entry = jarIn.getNextJarEntry()) != null) {
                if ("META-INF/MANIFEST.MF".equals(entry.getName())) { //$NON-NLS-1$
                    continue;
                }
                jarOut.putNextEntry(entry);
                int read;
                while ((read = jarIn.read(buf)) != -1) {
                    jarOut.write(buf, 0, read);
                }
                jarOut.closeEntry();
            }
        } catch (Exception e) {
            LOGGER.error("Extraction exception occurred.", e);
        } finally {
            IOUtils.closeQuietly(jarIn);
            IOUtils.closeQuietly(jarOut);
        }
        // re-zip file
        if (entity.getName().endsWith(".zip")) { //$NON-NLS-1$
            File sourceFile = new File(sourcePath);
            try {
                JoboxUtil.zip(sourceFile, jobFile);
            } catch (Exception e) {
                LOGGER.error("Zip exception occurred.", e);
            }
        }
    }
}

From source file:loci.formats.in.MIASReader.java

@Override
public int getRequiredDirectories(String[] files) throws FormatException, IOException {
    final StringBuilder commonParent = new StringBuilder();

    int dirCount = 0;

    String[] dirs = files[0].split(File.separatorChar == '/' ? "/" : "\\\\");
    for (String dir : dirs) {
        boolean canAppend = true;
        for (String f : files) {
            if (!f.startsWith(commonParent.toString() + dir)) {
                canAppend = false;//  w w  w  . j  a v a2  s  . co m
                break;
            }
        }

        if (canAppend) {
            commonParent.append(dir);
            commonParent.append(File.separator);
            dirCount++;
        }
    }

    int maxDirCount = 0;
    for (String f : files) {
        int parentDirCount = f.split(File.separatorChar == '/' ? "/" : "\\\\").length - 1;
        if (parentDirCount > maxDirCount) {
            maxDirCount = parentDirCount;
        }
    }

    return (int) Math.max(3 - (maxDirCount - dirCount), 0);
}

From source file:net.sourceforge.mavenhippo.SourceCodeBeanFinder.java

private String denormalizePath(String path) {
    String result;//from  w  w w.  ja  v  a2 s . c o  m
    Matcher matcher = START_WITH_SLASH_PATTERN.matcher(path);
    if (matcher.find()) {
        result = path.substring(matcher.end());
    } else {
        result = path;
    }
    return result.replace('/', File.separatorChar);
}

From source file:com.consol.citrus.admin.service.FileBrowserService.java

private boolean isSystemWindows() {
    return File.separatorChar == WINDOWS_SEPARATOR;
}

From source file:hudson.tasks.Mailer.java

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
        throws IOException, InterruptedException {
    if (debug)//from   www  .j a v a  2  s.c  o m
        listener.getLogger().println("Running mailer");
    // substitute build parameters
    EnvVars env = build.getEnvironment(listener);
    String recip = env.expand(recipients);

    return new MailSender(recip, dontNotifyEveryUnstableBuild, sendToIndividuals, descriptor().getCharset()) {
        /** Check whether a path (/-separated) will be archived. */
        @Override
        public boolean artifactMatches(String path, AbstractBuild<?, ?> build) {
            ArtifactArchiver aa = build.getProject().getPublishersList().get(ArtifactArchiver.class);
            if (aa == null) {
                LOGGER.finer("No ArtifactArchiver found");
                return false;
            }
            String artifacts = aa.getArtifacts();
            for (String include : artifacts.split("[, ]+")) {
                String pattern = include.replace(File.separatorChar, '/');
                if (pattern.endsWith("/")) {
                    pattern += "**";
                }
                if (SelectorUtils.matchPath(pattern, path)) {
                    LOGGER.log(Level.FINER, "DescriptorImpl.artifactMatches true for {0} against {1}",
                            new Object[] { path, pattern });
                    return true;
                }
            }
            LOGGER.log(Level.FINER, "DescriptorImpl.artifactMatches for {0} matched none of {1}",
                    new Object[] { path, artifacts });
            return false;
        }
    }.execute(build, listener);
}

From source file:gmgen.util.MiscUtilities.java

/**
 *  Checks if the specified string is a URL.
 *
 *@param  str  The string to check//from  ww  w . j  av a  2s  .c  o  m
 *@return      True if the string is a URL, false otherwise
 *@since       GMGen 3.3
 */
public static boolean isURL(String str) {
    int fsIndex = Math.max(str.indexOf(File.separatorChar), str.indexOf('/'));

    if (fsIndex == 0) {
        // /etc/passwd
        return false;
    } else if (fsIndex == 2) {
        // C:\AUTOEXEC.BAT
        return false;
    }

    int cIndex = str.indexOf(':');

    if (cIndex <= 1) {
        // D:\WINDOWS
        return false;
    } else if ((fsIndex != -1) && (cIndex > fsIndex)) {
        // /tmp/RTF::read.pm
        return false;
    }

    return true;
}

From source file:com.sshtools.daemon.authentication.AuthorizationFileVerification.java

private SshPublicKey getAuthorizedKey(String username, String algorithm, byte[] encoded) throws IOException {
    NativeAuthenticationProvider provider = NativeAuthenticationProvider.getInstance();

    String userHome = provider.getHomeDirectory(username); //, nativeSettings);

    if (userHome == null) {
        log.warn("There is no home directory for " + username + " is available");
    }/*www. ja v a  2s.c o  m*/

    // Replace '\' with '/' because when we use it in String.replaceAll
    // for some reason it removes them?
    if (userHome != null) {
        userHome = userHome.replace('\\', '/');
    }

    ServerConfiguration config = (ServerConfiguration) ConfigurationLoader
            .getConfiguration(ServerConfiguration.class);
    String authorizationFile;
    String userConfigDir = config.getUserConfigDirectory();

    // First replace any '\' with '/' (Becasue replaceAll removes them!)
    userConfigDir = userConfigDir.replace('\\', '/');

    // Replace any home directory tokens
    if ((userConfigDir.indexOf("%D") > -1) && (userHome == null)) {
        throw new IOException(
                "<UserConfigDirectory> requires home directory, but none available for " + username);
    }

    int idx = 0;

    while ((idx = userConfigDir.indexOf("%D", idx + 1)) > -1) {
        StringBuffer buf = new StringBuffer(userConfigDir);
        buf = buf.replace(idx, idx + 1, userHome);
        userConfigDir = buf.toString();
    }

    idx = 0;

    while ((idx = userConfigDir.indexOf("%U", idx + 1)) > -1) {
        StringBuffer buf = new StringBuffer(userConfigDir);
        buf = buf.replace(idx, idx + 1, username);
        userConfigDir = buf.toString();
    }

    // Replace the '/' with File.seperator and trim
    userConfigDir = userConfigDir.replace('/', File.separatorChar).trim();

    if (!userConfigDir.endsWith(File.separator)) {
        userConfigDir += File.separator;
    }

    authorizationFile = userConfigDir + config.getAuthorizationFile();

    // Load the authorization file
    File file = new File(authorizationFile);

    if (!file.exists()) {
        log.info("authorizationFile: " + authorizationFile + " does not exist.");
        throw new IOException("authorizationFile: " + authorizationFile + " does not exist.");
    }

    FileInputStream in = new FileInputStream(file);
    Authorization keys;

    try {
        keys = new Authorization(in);
    } catch (Exception e) {
        throw new AuthenticationProtocolException("Failed to load authorized keys file " + authorizationFile);
    }

    //      SshPublicKey key = SshPublicKeyFile.parse(encoded);
    Iterator it = keys.getAuthorizedKeys().iterator();

    SshKeyPair pair = SshKeyPairFactory.newInstance(algorithm);
    SshPublicKey authorizedKey = null;
    SshPublicKey key = pair.decodePublicKey(encoded);
    boolean valid = false;
    String keyfile;

    while (it.hasNext()) {
        keyfile = (String) it.next();

        // Look for the file in the user config dir first
        file = new File(userConfigDir + keyfile);

        // If it does not exist then look absolute
        if (!file.exists()) {
            file = new File(keyfile);
        }

        if (file.exists()) {
            // Try to open the public key in the default file format
            // otherwise attempt the supported key formats
            SshPublicKeyFile pkf = SshPublicKeyFile.parse(file);
            authorizedKey = pkf.toPublicKey();

            if (authorizedKey.equals(key)) {
                return authorizedKey;
            }
        } else {
            log.info("Failed attempt to load key file " + keyfile);
        }
    }

    throw new IOException("");
}