List of usage examples for java.lang String replaceFirst
public String replaceFirst(String regex, String replacement)
From source file:com.dycody.android.idealnote.async.upgrade.UpgradeProcessor.java
/** * Adjustment of all the old attachments without mimetype field set into DB *//*from www.ja va2 s . c om*/ private void onUpgradeTo476() { final DbHelper dbHelper = DbHelper.getInstance(); for (Attachment attachment : dbHelper.getAllAttachments()) { if (attachment.getMime_type() == null) { String mimeType = StorageHelper.getMimeType(attachment.getUri().toString()); if (!TextUtils.isEmpty(mimeType)) { String type = mimeType.replaceFirst("/.*", ""); switch (type) { case "image": attachment.setMime_type(Constants.MIME_TYPE_IMAGE); break; case "video": attachment.setMime_type(Constants.MIME_TYPE_VIDEO); break; case "audio": attachment.setMime_type(Constants.MIME_TYPE_AUDIO); break; default: attachment.setMime_type(Constants.MIME_TYPE_FILES); break; } dbHelper.updateAttachment(attachment); } else { attachment.setMime_type(Constants.MIME_TYPE_FILES); } } } }
From source file:com.norconex.collector.http.filter.impl.ExtensionURLFilter.java
@Override public boolean acceptURL(String url) { if (StringUtils.isBlank(extensions)) { return getOnMatch() == OnMatch.INCLUDE; }//from w w w .j a v a2 s .c o m String urlExtension = url.replaceFirst("(.*\\.)(.*?)", "$2"); for (int i = 0; i < extensionParts.length; i++) { String ext = extensionParts[i]; if (!isCaseSensitive() && ext.equalsIgnoreCase(urlExtension)) { return getOnMatch() == OnMatch.INCLUDE; } else if (isCaseSensitive() && ext.equals(urlExtension)) { return getOnMatch() == OnMatch.INCLUDE; } } return getOnMatch() == OnMatch.EXCLUDE; }
From source file:name.vysoky.epub.Part.java
/** * Tool jTIDY work only with XHTML 1.0 and custom document type is problematic. * This method read file to memory, replace document type and save it back to the same file. * @throws IOException common input output error *///from w w w . j ava 2s. co m private void fixTidyDocumentAfterSave() throws IOException { String content = IOUtils.toString(new FileInputStream(getFile()), ENCODING); content = content.replaceFirst(XML_DECLARATION, EMPTY_STRING); content = content.replaceAll(JTIDY_DOCTYPE, EPUB_DOCTYPE); content = (content.startsWith("\n")) ? content.substring(1) : content; // remove empty line at start IOUtils.write(content, new FileOutputStream(getFile()), ENCODING); }
From source file:de.static_interface.reallifeplugin.database.AbstractTable.java
private String sqlToString(String sql, Object... paramObjects) { if (paramObjects == null || paramObjects.length < 1) { return sql; }/*from w w w . j av a2s .c om*/ for (Object paramObject : paramObjects) { sql = sql.replaceFirst("\\Q?\\E", paramObject.toString()); } return sql; }
From source file:org.fcrepo.mint.HttpPidMinter.java
/** * Remove unwanted text from the minter service response to produce the desired identifier. * Override this method for processing more complex than a simple regex replacement. * @param responseText the response text * @throws IOException if exception occurred * @return the response//from www.j a v a 2 s . c o m **/ protected String responseToPid(final String responseText) throws IOException { LOGGER.debug("responseToPid({})", responseText); if (!isBlank(regex)) { return responseText.replaceFirst(regex, ""); } else if (xpath != null) { try { return xpath(responseText, xpath); } catch (ParserConfigurationException | SAXException | XPathExpressionException e) { throw new IOException(e); } } else { return responseText; } }
From source file:org.archive.modules.CrawlMetadata.java
public String getUserAgent() { String userAgent = getUserAgentTemplate(); String contactURL = getOperatorContactUrl(); userAgent = userAgent.replaceFirst("@OPERATOR_CONTACT_URL@", contactURL); userAgent = userAgent.replaceFirst("@VERSION@", Matcher.quoteReplacement(ArchiveUtils.VERSION)); return userAgent; }
From source file:com.norconex.collector.core.filter.impl.ExtensionReferenceFilter.java
@Override public boolean acceptReference(String reference) { if (StringUtils.isBlank(extensions)) { return getOnMatch() == OnMatch.INCLUDE; }/*from www . jav a2 s.c o m*/ String refExtension = reference.replaceFirst("(.*\\.)(.*?)", "$2"); for (int i = 0; i < extensionParts.length; i++) { String ext = extensionParts[i]; if (!isCaseSensitive() && ext.equalsIgnoreCase(refExtension)) { return getOnMatch() == OnMatch.INCLUDE; } else if (isCaseSensitive() && ext.equals(refExtension)) { return getOnMatch() == OnMatch.INCLUDE; } } return getOnMatch() == OnMatch.EXCLUDE; }
From source file:org.socialhistoryservices.pid.service.StubPidResourceService.java
@Override public PidType getAnonymousPid(String pidId) throws HandleException { String normalisedPidId = pidId; if (pidId.startsWith(handleBaseUrl)) { normalisedPidId = pidId.replaceFirst(handleBaseUrl, ""); }/* www . ja va 2 s .c om*/ return mappingsService.convertHandleToPidType(handleDao.fetchHandleByPID(normalisedPidId)); }
From source file:org.socialhistoryservices.pid.service.StubPidResourceService.java
@Override public PidType getPid(String pidId) throws HandleException { String normalisedPidId = pidId; if (pidId.startsWith(handleBaseUrl)) { normalisedPidId = pidId.replaceFirst(handleBaseUrl, ""); }// w ww . ja v a2 s .c o m NAAuthentication.authorize(normalisedPidId); return mappingsService.convertHandleToPidType(handleDao.fetchHandleByPID(normalisedPidId)); }
From source file:com.apress.progwt.server.util.HostPrecedingPropertyPlaceholderConfigurer.java
public String resolvePlaceholder(String placeholder, Properties props) { try {/*from w w w . j a v a 2 s . c o m*/ if (placeholder.startsWith("HOST.")) { log.debug("Host: " + InetAddress.getLocalHost().getHostName() + " for property " + placeholder); String replace = placeholder.replaceFirst("HOST", InetAddress.getLocalHost().getHostName()); String prop = props.getProperty(replace); if (prop == null) { log.warn("Please define property: " + replace); } return prop; } else { log.debug("reg"); return props.getProperty(placeholder); } } catch (UnknownHostException e) { log.warn(e); return null; } }