List of usage examples for org.apache.commons.lang StringUtils startsWith
public static boolean startsWith(String str, String prefix)
Check if a String starts with a specified prefix.
From source file:hydrograph.ui.graph.utility.DataViewerUtility.java
public void closeDataViewerWindows(Job job) { if (job == null) { return;//from www. j a v a2 s. co m } List<DebugDataViewer> dataViewerList = new ArrayList<>(); dataViewerList.addAll(JobManager.INSTANCE.getDataViewerMap().values()); Iterator<DebugDataViewer> iterator = dataViewerList.iterator(); while (iterator.hasNext()) { DebugDataViewer daDebugDataViewer = (DebugDataViewer) iterator.next(); String windowName = (String) daDebugDataViewer.getDataViewerWindowTitle(); if (StringUtils.startsWith(windowName, job.getConsoleName().replace(".", "_"))) { daDebugDataViewer.close(); JobManager.INSTANCE.getDataViewerMap().remove(windowName); iterator.remove(); } } }
From source file:com.sfs.beans.DetectBrowserBean.java
/** * Returns a boolean indicating whether the browser is any version of IE. * * @return the boolean for the IE flag// w w w . j a va 2s .c o m */ public boolean isIE() { boolean ie = false; if (StringUtils.startsWith(this.version, "ie")) { ie = true; } return ie; }
From source file:com.haulmont.cuba.gui.xml.layout.ScreenXmlParser.java
protected void replaceAssignParameters(Document document) { Map<String, String> assignedParams = new HashMap<>(); List<Element> assignElements = Dom4j.elements(document.getRootElement(), "assign"); ThemeConstantsManager themeManager = AppBeans.get(ThemeConstantsManager.NAME); for (Element assignElement : assignElements) { String name = assignElement.attributeValue("name"); if (StringUtils.isEmpty(name)) { throw new RuntimeException("'name' attribute of assign tag is empty"); }/*from w w w . j a v a 2s. com*/ String value = assignElement.attributeValue("value"); if (StringUtils.isEmpty(value)) { throw new RuntimeException("'value' attribute of assign tag is empty"); } if (StringUtils.startsWith(value, ThemeConstants.PREFIX)) { ThemeConstants theme = themeManager.getConstants(); value = theme.get(value.substring(ThemeConstants.PREFIX.length())); } assignedParams.put(name, value); } if (!assignedParams.isEmpty()) { Element layoutElement = document.getRootElement().element("layout"); if (layoutElement != null) { Dom4j.walkAttributesRecursive(layoutElement, (element, attribute) -> { String attributeValue = attribute.getValue(); if (StringUtils.isNotEmpty(attributeValue) && attributeValue.startsWith("${") && attributeValue.endsWith("}")) { String paramKey = attributeValue.substring(2, attributeValue.length() - 1); String assignedValue = assignedParams.get(paramKey); if (assignedValue == null) { throw new RuntimeException("Unable to find value of assign param: " + paramKey); } attribute.setValue(assignedValue); } }); } } }
From source file:io.kamax.mxisd.directory.DirectoryManager.java
public UserDirectorySearchResult search(URI target, String accessToken, String query) { if (StringUtils.startsWith(query, "@")) { query = query.substring(1);//from ww w . j a v a2s . com } log.info("Performing search for '{}'", query); log.info("Original request URL: {}", target); UserDirectorySearchResult result = new UserDirectorySearchResult(); if (cfg.getExclude().getHomeserver()) { log.info("Skipping HS directory data, disabled in config"); } else { URIBuilder builder = dns.transform(target); log.info("Querying HS at {}", builder); builder.setParameter("access_token", accessToken); HttpPost req = RestClientUtils.post(builder.toString(), new UserDirectorySearchRequest(query)); try (CloseableHttpResponse res = client.execute(req)) { int status = res.getStatusLine().getStatusCode(); Charset charset = ContentType.getOrDefault(res.getEntity()).getCharset(); String body = IOUtils.toString(res.getEntity().getContent(), charset); if (status != 200) { MatrixErrorInfo info = gson.fromJson(body, MatrixErrorInfo.class); if (StringUtils.equals("M_UNRECOGNIZED", info.getErrcode())) { // FIXME no hardcoding, use Enum log.warn("Homeserver does not support Directory feature, skipping"); } else { log.error("Homeserver returned an error while performing directory search"); throw new HttpMatrixException(status, info.getErrcode(), info.getError()); } } UserDirectorySearchResult resultHs = gson.fromJson(body, UserDirectorySearchResult.class); log.info("Found {} match(es) in HS for '{}'", resultHs.getResults().size(), query); result.getResults().addAll(resultHs.getResults()); if (resultHs.isLimited()) { result.setLimited(true); } } catch (JsonSyntaxException e) { throw new InternalServerError("Invalid JSON reply from the HS: " + e.getMessage()); } catch (IOException e) { throw new InternalServerError("Unable to query the HS: I/O error: " + e.getMessage()); } } for (IDirectoryProvider provider : providers) { log.info("Using Directory provider {}", provider.getClass().getSimpleName()); UserDirectorySearchResult resultProvider = provider.searchByDisplayName(query); log.info("Display name: found {} match(es) for '{}'", resultProvider.getResults().size(), query); result.getResults().addAll(resultProvider.getResults()); if (resultProvider.isLimited()) { result.setLimited(true); } resultProvider = provider.searchBy3pid(query); log.info("Threepid: found {} match(es) for '{}'", resultProvider.getResults().size(), query); result.getResults().addAll(resultProvider.getResults()); if (resultProvider.isLimited()) { result.setLimited(true); } } log.info("Total matches: {} - limited? {}", result.getResults().size(), result.isLimited()); return result; }
From source file:hydrograph.ui.validators.impl.FTPProtocolSelectionValidator.java
private boolean validatePort(String text, String propertyName) { if (StringUtils.isNotBlank(text)) { Matcher matcher = Pattern.compile("[\\d]*").matcher(text); if ((matcher.matches()) || ((StringUtils.startsWith(text, "@{") && StringUtils.endsWith(text, "}")) && !StringUtils.contains(text, "@{}"))) { return true; }/*from w w w. j a v a2s . co m*/ errorMessage = propertyName + " is mandatory"; } errorMessage = propertyName + " is not integer value or valid parameter"; return false; }
From source file:com.cognifide.actions.msg.replication.ReplicationMessageProducer.java
static String createPath(String relPath, String actionRoot, String randomPath) { final String path; if (StringUtils.startsWith(relPath, "/")) { path = relPath;//from w w w. j ava2 s. c om } else { final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); path = String.format("%s%s/%s", actionRoot, dateFormat.format(new Date()), relPath); } if (path.endsWith("/*")) { long now = new Date().getTime(); return String.format("%s%s/%s", StringUtils.removeEnd(path, "*"), generateRandomPathPart(randomPath), now); } else { return path; } }
From source file:com.intel.cosbench.driver.generator.RangeIntGenerator.java
public static RangeIntGenerator parse(String pattern) { try {//from w ww . java 2s .c o m return tryParseOld(pattern); } catch (Exception e1) { if (!StringUtils.startsWith(pattern, "r(")) return null; try { return tryParse(pattern); } catch (Exception e2) { } } String msg = "illegal iteration pattern: " + pattern; throw new ConfigException(msg); }
From source file:com.github.dbourdette.otto.source.Event.java
public Event parseValue(String key, String value) { if (StringUtils.startsWith(key, INTEGER_PREFIX)) { key = StringUtils.substringAfter(key, INTEGER_PREFIX); putInt(key, Integer.parseInt(value)); } else if (StringUtils.startsWith(key, BOOLEAN_PREFIX)) { key = StringUtils.substringAfter(key, BOOLEAN_PREFIX); putBoolean(key, Boolean.valueOf(value)); } else if (StringUtils.startsWith(key, DATE_PREFIX)) { key = StringUtils.substringAfter(key, DATE_PREFIX); putDate(key, DateTimeFormat.forPattern(DATE_PATTERN).parseDateTime(value)); } else {//from www . j ava 2 s.c o m putString(key, value); } return this; }
From source file:com.hangum.tadpole.rdb.erd.core.part.RelationEditPart.java
@Override protected IFigure createFigure() { PolylineConnection conn = new PolylineConnection(); conn.setConnectionRouter(new BendpointConnectionRouter()); Relation relation = (Relation) getModel(); conn.setSourceDecoration(new RelationDecorator(relation.getSource_kind().getName())); conn.setTargetDecoration(new RelationDecorator(relation.getTarget_kind().getName())); Label labelSourceTarget = new Label(); if (StringUtils.startsWith(relation.getDb().getDbType(), "SQLite")) { labelSourceTarget.setText(//from www. j a v a 2 s. c o m String.format("%s:%s", relation.getReferenced_column_name(), relation.getColumn_name())); } else { labelSourceTarget.setText(String.format("%s(%s:%s)", relation.getConstraint_name(), relation.getReferenced_column_name(), relation.getColumn_name())); } labelSourceTarget.setForegroundColor(ColorConstants.darkBlue()); labelSourceTarget.setBackgroundColor(ColorConstants.white()); labelSourceTarget.setToolTip( new Label(String.format("%s:%s", relation.getReferenced_column_name(), relation.getColumn_name()))); Table table = relation.getTarget(); if (table == null) { conn.add(labelSourceTarget, new ConnectionLocator(conn, ConnectionLocator.MIDDLE)); } else { EList<Relation> list = table.getIncomingLinks(); if (list.size() == 1) { conn.add(labelSourceTarget, new ConnectionLocator(conn, ConnectionLocator.MIDDLE)); } else { for (Relation tmpRelation : list) { if (StringUtils.equals(tmpRelation.getConstraint_name(), relation.getConstraint_name())) { ConnectionLocator cl = new ConnectionLocator(conn, ConnectionLocator.MIDDLE); cl.setGap(10); cl.setRelativePosition(PositionConstants.SOUTH); conn.add(labelSourceTarget, cl); } else { ConnectionLocator cl = new ConnectionLocator(conn, ConnectionLocator.MIDDLE); cl.setRelativePosition(PositionConstants.WEST); conn.add(labelSourceTarget, cl); } } } } return conn; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.datatools.dumprestore.DumpRestoreController.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { if (!isAuthorizedToDisplayPage(req, resp, REQUIRED_ACTION)) { return;//w w w . j a v a 2 s . c om } try { String action = req.getPathInfo(); if (ACTION_SELECT.equals(action)) { new DumpModelsAction(req, resp).redirectToFilename(); } else if (StringUtils.startsWith(action, ACTION_DUMP)) { new DumpModelsAction(req, resp).dumpModels(); } else { super.doGet(req, resp); } } catch (BadRequestException e) { // TODO Auto-generated catch block e.printStackTrace(); } }