Example usage for java.util.regex Pattern quote

List of usage examples for java.util.regex Pattern quote

Introduction

In this page you can find the example usage for java.util.regex Pattern quote.

Prototype

public static String quote(String s) 

Source Link

Document

Returns a literal pattern String for the specified String .

Usage

From source file:hydrograph.ui.propertywindow.widgets.dialogs.join.JoinMapDialog.java

private void attachDropFunctionalityToMappingTable() {
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
    DropTarget target = new DropTarget(mappingTableViewer.getTable(), operations);
    target.setTransfer(types);/*from  w w w .ja  va  2  s  .  c  o m*/
    target.addDropListener(new DropTargetAdapter() {
        public void dragOver(DropTargetEvent event) {
            event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
        }

        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }

            String[] dropData = ((String) event.data).split(Pattern.quote(MAPPING_TABLE_ITEM_DELIMILATOR));
            List<String> tempOutputFieldList = getOutputFieldList();

            if (getDuplicateDropAllowed()) {
                for (String data : dropData) {
                    dropItem(data);
                }
            } else {
                for (String data : dropData) {
                    dropItem(data);
                    //Currently, we allowed duplicate values
                    /*if(!tempOutputFieldList.contains(StringUtils.lowerCase(data.split("\\.")[1]))){
                    }
                    else{
                       WidgetUtility.errorMessage(Messages.MAPPING_WINDOW_DUPLICATE_FIELD);
                       break;
                    }*/
                }
            }
            refreshButtonStatus();
        }
    });
}

From source file:org.apache.syncope.core.persistence.dao.impl.UserDAOImpl.java

/**
 * Split an attribute value recurring on provided literals/tokens.
 *
 * @param attrValue value to be split.//from ww w.  j a  v  a 2s .  c om
 * @param literals literals/tokens.
 * @return
 */
private List<String> split(final String attrValue, final List<String> literals) {

    final List<String> attrValues = new ArrayList<String>();

    if (literals.isEmpty()) {
        attrValues.add(attrValue);
    } else {

        for (String token : attrValue.split(Pattern.quote(literals.get(0)))) {

            attrValues.addAll(split(token, literals.subList(1, literals.size())));
        }
    }

    return attrValues;
}

From source file:ca.weblite.jdeploy.JDeploy.java

private File shallowest(File[] files) {
    File out = null;//from  w  w w .  j av a2  s .c om
    int depth = -1;
    for (File f : files) {
        int fDepth = f.getPath().split(Pattern.quote("\\") + "|" + Pattern.quote("/")).length;
        if (out == null || fDepth < depth) {
            depth = fDepth;
            out = f;
        }
    }
    return out;
}

From source file:net.sf.jasperreports.functions.standard.TextFunctions.java

public static String SUBSTITUTE(String originalText, String oldText, String newText, Integer occurrenceNum) {
    if (originalText == null || oldText == null || newText == null) {
        logHavingNullArguments();/*from  w ww .  j a  v a 2  s .  c o m*/
        return null;
    } else if (occurrenceNum == null) {
        // Replace all occurrences
        return originalText.replaceAll(Pattern.quote(oldText), Matcher.quoteReplacement(newText));
    } else {
        int startIdx = 0;
        int counter = 1;

        // Find the right occurrence
        while (startIdx < originalText.length() - 1) {
            // Locate the next index position of the occurrence of the old text
            int foundPosition = originalText.indexOf(oldText, startIdx);
            if (counter == occurrenceNum) {
                return REPLACE(originalText, foundPosition + 1, oldText.length(), newText);
            } else {
                startIdx = foundPosition + oldText.length();
                counter++;
            }
        }
        // Fall-back
        return null;
    }
}

From source file:com.datasalt.pangool.solr.SolrRecordWriter.java

static String relativePathForZipEntry(final String rawPath, final String baseName, final String root) {
    String relativePath = rawPath.replaceFirst(Pattern.quote(root.toString()), "");
    LOG.info(/*ww w  . j  a v a 2 s .com*/
            String.format("RawPath %s, baseName %s, root %s, first %s", rawPath, baseName, root, relativePath));

    if (relativePath.startsWith(Path.SEPARATOR)) {
        relativePath = relativePath.substring(1);
    }
    LOG.info(String.format("RawPath %s, baseName %s, root %s, post leading slash %s", rawPath, baseName, root,
            relativePath));
    if (relativePath.isEmpty()) {
        LOG.warn(String.format("No data after root (%s) removal from raw path %s", root, rawPath));
        return baseName;
    }
    // Construct the path that will be written to the zip file, including
    // removing any leading '/' characters
    String inZipPath = baseName + Path.SEPARATOR_CHAR + relativePath;

    LOG.info(String.format("RawPath %s, baseName %s, root %s, inZip 1 %s", rawPath, baseName, root, inZipPath));
    if (inZipPath.startsWith(Path.SEPARATOR)) {
        inZipPath = inZipPath.substring(1);
    }
    LOG.info(String.format("RawPath %s, baseName %s, root %s, inZip 2 %s", rawPath, baseName, root, inZipPath));

    return inZipPath;

}

From source file:com.all.downloader.p2p.phexcore.download.PhexDownloader.java

String extractHashcodeFromUrn(String urnSha1) {
    return urnSha1.replaceFirst(Pattern.quote(URN_PREFIX), "");
}

From source file:com.mediaworx.opencms.moduleutils.manifestgenerator.OpenCmsModuleManifestGenerator.java

/**
 * Replaces System file separators with a forward slash ("/") that's needed for the VFS
 * @param path  the path containing system file separators
 * @return the path with file separators replaced by "/"
 *///w  ww . j a v  a  2  s .  co m
private String fixVfsFileSeparator(String path) {
    if (!File.separator.equals("/")) {
        path = path.replaceAll(Pattern.quote(File.separator), "/");
    }
    return path;
}

From source file:endrov.ioImageCollections.EvIONamebasedImageset.java

/**
 * Get the relative path from one file to another, specifying the directory separator. 
 * If one of the provided resources does not exist, it is assumed to be a file unless it ends with '/' or
 * '\'./*ww w .  j a v  a  2s . co m*/
 * 
 * @param targetPath targetPath is calculated to this file
 * @param basePath basePath is calculated from this file
 * @param pathSeparator directory separator. The platform default is not assumed so that we can test Unix behaviour when running on Windows (for example)
 * @return
 */
public static String getRelativePath(String targetPath, String basePath, String pathSeparator) {
    // Normalize the paths
    String normalizedTargetPath = FilenameUtils.normalizeNoEndSeparator(targetPath);
    String normalizedBasePath = FilenameUtils.normalizeNoEndSeparator(basePath);

    // Undo the changes to the separators made by normalization
    if (pathSeparator.equals("/")) {
        normalizedTargetPath = FilenameUtils.separatorsToUnix(normalizedTargetPath);
        normalizedBasePath = FilenameUtils.separatorsToUnix(normalizedBasePath);

    } else if (pathSeparator.equals("\\")) {
        normalizedTargetPath = FilenameUtils.separatorsToWindows(normalizedTargetPath);
        normalizedBasePath = FilenameUtils.separatorsToWindows(normalizedBasePath);
    } else {
        throw new IllegalArgumentException("Unrecognised dir separator '" + pathSeparator + "'");
    }

    String[] base = normalizedBasePath.split(Pattern.quote(pathSeparator));
    String[] target = normalizedTargetPath.split(Pattern.quote(pathSeparator));

    // First get all the common elements. Store them as a string,
    // and also count how many of them there are.
    StringBuffer common = new StringBuffer();

    int commonIndex = 0;
    while (commonIndex < target.length && commonIndex < base.length
            && target[commonIndex].equals(base[commonIndex])) {
        common.append(target[commonIndex] + pathSeparator);
        commonIndex++;
    }

    if (commonIndex == 0) {
        // No single common path element. This most
        // likely indicates differing drive letters, like C: and D:.
        // These paths cannot be relativized.
        throw new PathResolutionException("No common path element found for '" + normalizedTargetPath
                + "' and '" + normalizedBasePath + "'");
    }

    // The number of directories we have to backtrack depends on whether the
    // base is a file or a dir
    // For example, the relative path from
    //
    // /foo/bar/baz/gg/ff to /foo/bar/baz
    //
    // ".." if ff is a file
    // "../.." if ff is a directory
    //
    // The following is a heuristic to figure out if the base refers to a file
    // or dir. It's not perfect, because
    // the resource referred to by this path may not actually exist, but it's
    // the best I can do
    boolean baseIsFile = true;

    File baseResource = new File(normalizedBasePath);

    if (baseResource.exists()) {
        baseIsFile = baseResource.isFile();

    } else if (basePath.endsWith(pathSeparator)) {
        baseIsFile = false;
    }

    StringBuffer relative = new StringBuffer();

    if (base.length != commonIndex) {
        int numDirsUp = baseIsFile ? base.length - commonIndex - 1 : base.length - commonIndex;

        for (int i = 0; i < numDirsUp; i++)
            relative.append(".." + pathSeparator);
    }
    relative.append(normalizedTargetPath.substring(common.length()));
    return relative.toString();
}

From source file:com.wegas.core.Helper.java

/**
 * Insensitive contains/*  w  ww  .  j  a v a 2s .com*/
 *
 * @param text     text to search in
 * @param criteria criteria to search for
 * @return match
 */
public static Boolean insensitiveContains(String text, String criteria) {
    if (text == null) {
        return false;
    }
    return Pattern.compile(Pattern.quote(criteria), Pattern.CASE_INSENSITIVE)
            .matcher(StringEscapeUtils.unescapeHtml4(text)).find();
}

From source file:edu.usu.sdl.openstorefront.service.SystemServiceImpl.java

@Override
public HelpSectionAll getAllHelp(Boolean includeAdmin) {
    HelpSectionAll helpSectionAll = new HelpSectionAll();

    HelpSection helpSectionExample = new HelpSection();
    helpSectionExample.setAdminSection(includeAdmin);

    List<HelpSection> helpSections = persistenceService.queryByExample(HelpSection.class, helpSectionExample);

    if (helpSections.isEmpty() == false) {

        //Root Section
        HelpSection helpSectionRoot = new HelpSection();
        helpSectionRoot.setTitle(PropertiesManager.getValue(PropertiesManager.KEY_APPLICATION_TITLE));
        helpSectionRoot.setContent("<center><h2>User Guide</h2>Version: "
                + PropertiesManager.getApplicationVersion() + "</center>");
        helpSectionAll.setHelpSection(helpSectionRoot);

        for (HelpSection helpSection : helpSections) {
            String codeTokens[] = helpSection.getSectionNumber().split(Pattern.quote("."));
            HelpSectionAll rootHelp = helpSectionAll;
            StringBuilder codeKey = new StringBuilder();
            for (String codeToken : codeTokens) {
                codeKey.append(codeToken);
                //put in stubs as needed
                boolean found = false;
                String compare = codeKey.toString();
                if (codeKey.toString().length() == 1) {
                    compare += ".";
                }//from   www  . j a  v a 2  s .c o  m
                for (HelpSectionAll child : rootHelp.getChildSections()) {
                    if (child.getHelpSection().getSectionNumber().equals(compare)) {
                        found = true;
                        rootHelp = child;
                        break;
                    }
                }
                if (!found) {
                    HelpSectionAll newChild = new HelpSectionAll();
                    HelpSection childHelp = new HelpSection();
                    childHelp.setSectionNumber(compare);
                    newChild.setHelpSection(childHelp);
                    rootHelp.getChildSections().add(newChild);
                    rootHelp = newChild;
                }
                codeKey.append(".");
            }
            rootHelp.setHelpSection(helpSection);
        }
    }
    //reorder help number so missing sections do cause holes
    reorderHelpSectionTitles(helpSectionAll, "");
    return helpSectionAll;
}