List of usage examples for java.lang String regionMatches
public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
From source file:de.walware.docmlet.tex.internal.ui.editors.LtxCommandCompletionProposal.java
@Override public boolean validate(final IDocument document, final int offset, final DocumentEvent event) { try {// ww w . j a v a 2 s . c o m final int start = getReplacementOffset(); final String prefix = document.get(start, offset - start); return prefix.regionMatches(true, 0, fCommand.getControlWord(), 0, prefix.length()); } catch (final BadLocationException e) { return false; } }
From source file:uk.ac.ebi.eva.pipeline.io.mappers.VariantVcfFactory.java
/** * Replace "chr" references only at the beginning of the chromosome name. * For instance, tomato has SL2.40ch00 and that should be kept that way *//* w w w. j a v a 2 s . c om*/ private String getChromosomeWithoutPrefix(String[] fields) { String chromosome = fields[0]; boolean ignoreCase = true; int startOffset = 0; String prefixToRemove = "chr"; if (chromosome.regionMatches(ignoreCase, startOffset, prefixToRemove, startOffset, prefixToRemove.length())) { return chromosome.substring(prefixToRemove.length()); } return chromosome; }
From source file:org.lockss.util.UrlUtil.java
/** * Takes a javascript url of the following formats: * javascript:newWindow('http://www.example.com/link3.html') * javascript:popup('http://www.example.com/link3.html') * and resolves it to a URL/*ww w . ja va 2s . co m*/ */ public static String parseJavascriptUrl(String jsUrl) { int jsIdx = StringUtil.indexOfIgnoreCase(jsUrl, "javascript:"); if (jsIdx < 0) { log.debug("Doesn't appear to be a javascript URL: " + jsUrl); return null; } int protocolEnd = jsIdx + "javascript:".length(); int funcEnd = -1; for (int ix = 0; ix < supportedJSFunctions.length && funcEnd == -1; ix++) { if (jsUrl.regionMatches(true, protocolEnd, supportedJSFunctions[ix], 0, supportedJSFunctions[ix].length())) { funcEnd = protocolEnd + supportedJSFunctions[ix].length(); log.debug3("matched supported JS function " + supportedJSFunctions[ix]); break; } } if (funcEnd == -1) { // if we got here, there was no match log.debug("Can't parse js url: " + jsUrl); return null; } int urlStart = funcEnd + 1;//+1 to skip the "(" char firstChar = jsUrl.charAt(urlStart); if (firstChar == '\'') { urlStart++; } String url = jsUrl.substring(urlStart); return StringUtil.truncateAtAny(url, ")'"); }
From source file:org.simplx.args.MainArgs.java
private static boolean abbreviation(String str, String name) { return str.regionMatches(true, 0, name, 0, str.length()); }
From source file:cn.edu.zjnu.acm.judge.controller.MailController.java
@GetMapping({ "/sendpage", "/send" }) @SuppressWarnings("AssignmentToMethodParameter") public String sendpage(Model model, @RequestParam(value = "reply", defaultValue = "-1") long reply, @RequestParam(value = "to", defaultValue = "") String userId, Authentication authentication) { String title = ""; String content = ""; if (reply != -1) { Mail parent = mailMapper.findOne(reply); if (parent == null) { throw new MessageException("No such mail", HttpStatus.NOT_FOUND); }/*ww w .ja v a 2 s. c om*/ String toUser = parent.getTo(); if (!UserDetailService.isUser(authentication, toUser)) { throw new MessageException("invalid access", HttpStatus.FORBIDDEN); } userId = parent.getFrom(); title = parent.getTitle(); content = parent.getContent(); if (!title.regionMatches(true, 0, "re:", 0, 3)) { title = "Re:" + title; } mailMapper.setReply(reply); } model.addAttribute("to", userId); model.addAttribute("title", title); model.addAttribute("content", JudgeUtils.getReplyString(content)); return "mails/sendpage"; }
From source file:org.openvpms.report.openoffice.OpenOfficeDocument.java
/** * Returns the user text fields./*from ww w .ja va 2 s. c om*/ * * @return the user text fields, keyed on name * @throws OpenOfficeException if the fields can't be accessed */ protected Map<String, Field> getUserTextFields() { Map<String, Field> result = new LinkedHashMap<String, Field>(); XNameAccess fields = getTextFieldMasters(); for (String elementName : fields.getElementNames()) { try { // need to do a case insensitive comparison for OVPMS-749 if (elementName.regionMatches(true, 0, USER_FIELD_PREFIX, 0, USER_FIELD_PREFIX.length())) { String name = elementName.substring(USER_FIELD_PREFIX.length()); Object fieldMaster = fields.getByName(elementName); XPropertySet propertySet = UnoRuntime.queryInterface(XPropertySet.class, fieldMaster); String value = (String) propertySet.getPropertyValue("Content"); Field field = new Field(name, value, propertySet); result.put(name, field); } } catch (Exception exception) { throw new OpenOfficeException(exception, FailedToGetUserFields); } } return result; }
From source file:br.com.carlosrafaelgn.fplay.ActivityBrowserRadio.java
private void addPlaySelectedItem(final boolean play) { if (radioStationList.getSelection() < 0) return;/*from w w w . j ava 2s .c om*/ try { final RadioStation radioStation = radioStationList.getItemT(radioStationList.getSelection()); if (radioStation.m3uUri == null || radioStation.m3uUri.length() < 0) { UI.toast(getApplication(), R.string.error_file_not_found); return; } Player.songs.addingStarted(); SongAddingMonitor.start(getHostActivity()); (new Thread("Checked Radio Station Adder Thread") { @Override public void run() { AndroidHttpClient client = null; HttpResponse response = null; InputStream is = null; InputStreamReader isr = null; BufferedReader br = null; try { if (Player.getState() == Player.STATE_TERMINATED || Player.getState() == Player.STATE_TERMINATING) { Player.songs.addingEnded(); return; } client = AndroidHttpClient.newInstance( "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36 Debian"); response = client.execute(new HttpGet(radioStation.m3uUri)); final StatusLine statusLine = response.getStatusLine(); final int s = statusLine.getStatusCode(); if (s == HttpStatus.SC_OK) { is = response.getEntity().getContent(); isr = new InputStreamReader(is, "UTF-8"); br = new BufferedReader(isr, 1024); ArrayList<String> lines = new ArrayList<String>(8); String line; while ((line = br.readLine()) != null) { line = line.trim(); if (line.length() > 0 && line.charAt(0) != '#' && (line.regionMatches(true, 0, "http://", 0, 7) || line.regionMatches(true, 0, "https://", 0, 8))) lines.add(line); } if (Player.getState() == Player.STATE_TERMINATED || Player.getState() == Player.STATE_TERMINATING) { Player.songs.addingEnded(); return; } if (lines.size() == 0) { Player.songs.addingEnded(); MainHandler.toast(R.string.error_gen); } else { //instead of just using the first available address, let's use //one from the middle ;) Player.songs.addFiles(new FileSt[] { new FileSt(lines.get(lines.size() >> 1), radioStation.title, null, 0) }, null, 1, play, false, true); } } else { Player.songs.addingEnded(); MainHandler.toast( (s >= 400 && s < 500) ? R.string.error_file_not_found : R.string.error_gen); } } catch (Throwable ex) { Player.songs.addingEnded(); MainHandler.toast(ex); } finally { try { if (client != null) client.close(); } catch (Throwable ex) { } try { if (is != null) is.close(); } catch (Throwable ex) { } try { if (isr != null) isr.close(); } catch (Throwable ex) { } try { if (br != null) br.close(); } catch (Throwable ex) { } br = null; isr = null; is = null; client = null; response = null; System.gc(); } } }).start(); } catch (Throwable ex) { Player.songs.addingEnded(); UI.toast(getApplication(), ex.getMessage()); } }
From source file:org.energy_home.jemma.internal.device.zgd.StreamGobbler.java
private String getOS() { if (os != null) return os; String osName = System.getProperties().getProperty("os.name"); //$NON-NLS-1$ if (osName.regionMatches(true, 0, Constants.OS_WIN32, 0, 3)) return Constants.OS_WIN32; if (osName.equalsIgnoreCase(Constants.INTERNAL_OS_SUNOS)) return Constants.OS_SOLARIS; if (osName.equalsIgnoreCase(Constants.INTERNAL_OS_LINUX)) return Constants.OS_LINUX; if (osName.equalsIgnoreCase(Constants.INTERNAL_OS_AIX)) return Constants.OS_AIX; if (osName.equalsIgnoreCase(Constants.INTERNAL_OS_HPUX)) return Constants.OS_HPUX; if (osName.regionMatches(true, 0, Constants.INTERNAL_OS_MACOSX, 0, Constants.INTERNAL_OS_MACOSX.length())) return Constants.OS_MACOSX; return Constants.OS_UNKNOWN; }
From source file:org.talend.camel.designer.ui.wizards.actions.JavaCamelJobScriptsExportWSAction.java
@Override public final void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { this.monitor = monitor; String groupId = getGroupId(); String routeName = getArtifactId(); String routeVersion = getArtifactVersion(); // FIXME temporary solution, should be replaced by proper handling // of MicroService vs. KAR build. boolean isCreatingMicroService = false; Boolean oldMS = RouteProcessingExchange.isCreatingMicroService.get(); RouteProcessingExchange.isCreatingMicroService.set(Boolean.FALSE); try {//from w w w . j av a2s .com prepareJobBuild(); Boolean isMS = RouteProcessingExchange.isCreatingMicroService.get(); if (isMS != null) { isCreatingMicroService = isMS.booleanValue(); } } catch (Exception e) { throw new InvocationTargetException(e); } finally { RouteProcessingExchange.isCreatingMicroService.set(oldMS); if (oldMS == null) { RouteProcessingExchange.resetMavenOffline(); } } // FIXME may require some further actions to get all POMs. if (ProcessorUtilities.isGeneratePomOnly()) { return; } featuresModel = new FeaturesModel(groupId, routeName, routeVersion); try { File routeFile; try { routeFile = File.createTempFile("route", FileConstants.JAR_FILE_SUFFIX, new File(getTempDir())); // $NON-NLS-1$ addBuildArtifact(routeObject, "jar", routeFile); } catch (IOException e) { throw new InvocationTargetException(e); } BundleModel routeModel = new BundleModel(groupId, routeName, routeVersion, routeFile); final ProcessItem routeProcess = (ProcessItem) routeObject.getProperty().getItem(); if (featuresModel.addBundle(routeModel)) { CamelFeatureUtil.addFeatureAndBundles(routeProcess, featuresModel); featuresModel.setConfigName(routeObject.getLabel()); featuresModel.setContexts(JobContextUtils.getContextsMap(routeProcess)); exportAllReferenceJobs(routeName, routeProcess); final Set<String> routelets = new HashSet<>(); exportAllReferenceRoutelets(routeName, routeProcess, routelets); exportRouteBundle(routeObject, routeFile, version, null, null, bundleVersion, null, routelets, null); } try { if (destinationKar != null) { // FIXME should be replaced by proper handling of // microservice vs. KAR creation. String dest = destinationKar; int suffixNdx = dest.length() - 4; String suffix = "kar"; if (isCreatingMicroService) { if (dest.regionMatches(true, suffixNdx, ".kar", 0, 4)) { dest = dest.substring(0, suffixNdx) + ".jar"; suffix = "jar"; } else if (dest.regionMatches(true, suffixNdx, ".zip", 0, 4)) { suffix = "zip"; } } else { if (dest.regionMatches(true, suffixNdx, ".zip", 0, 4)) { Boolean isZip = (Boolean) manager.getExportChoice().get(ExportChoice.needMavenScript); if (isZip == null || !isZip.booleanValue()) { dest = dest.substring(0, suffixNdx) + ".kar"; } } } addBuildArtifact(routeObject, suffix, new File(dest)); } IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService(); ITalendProcessJavaProject talendProcessJavaProject = runProcessService .getTalendJobJavaProject(routeObject.getProperty()); FilesUtils.copyFile(featuresModel.getContent(), new File(talendProcessJavaProject.getBundleResourcesFolder().getLocation().toOSString() + File.separator + "feature.xml")); // Build project and collect build artifacts try { buildJob(); } catch (Exception ex) { throw new InvocationTargetException(ex); } collectBuildArtifacts(); } catch (Exception e) { e.printStackTrace(); } processResults(featuresModel, monitor); } finally { // remove generated files removeTempFiles(); } }
From source file:org.omegat.util.TMXReader2.java
/** * Get ParsedTuv from list of Tuv for specific language. * // ww w . j av a 2s. c om * Language choosed by:<br> * - with the same language+country<br> * - if not exist, then with the same language but without country<br> * - if not exist, then with the same language with whatever country<br> */ protected ParsedTuv getTuvByLang(Language lang) { String langLanguage = lang.getLanguageCode(); String langCountry = lang.getCountryCode(); ParsedTuv tuvLC = null; // Tuv with the same language+country ParsedTuv tuvL = null; // Tuv with the same language only, without country ParsedTuv tuvLW = null; // Tuv with the same language+whatever country for (int i = 0; i < currentTu.tuvs.size(); i++) { ParsedTuv tuv = currentTu.tuvs.get(i); String tuvLang = tuv.lang; if (!langLanguage.regionMatches(true, 0, tuvLang, 0, 2)) { // language not equals - there is no sense to processing continue; } if (tuvLang.length() < 3) { // language only, without country tuvL = tuv; } else if (langCountry.regionMatches(true, 0, tuvLang, 3, 2)) { // the same country tuvLC = tuv; } else { // other country tuvLW = tuv; } } ParsedTuv bestTuv; if (tuvLC != null) { bestTuv = tuvLC; } else if (tuvL != null) { bestTuv = tuvL; } else { bestTuv = tuvLW; } return bestTuv; }