List of usage examples for org.apache.commons.lang StringUtils substringBefore
public static String substringBefore(String str, String separator)
Gets the substring before the first occurrence of a separator.
From source file:org.apache.sling.query.mock.ResourceMock.java
@Override public Resource getChild(String relPath) { if (StringUtils.contains(relPath, '/')) { String firstPart = StringUtils.substringBefore(relPath, "/"); String rest = StringUtils.substringAfter(relPath, "/"); if (children.containsKey(firstPart)) { return children.get(firstPart).getChild(rest); }//from w ww . jav a 2 s .c o m } else if (children.containsKey(relPath)) { return children.get(relPath); } return null; }
From source file:org.apache.sling.superimposing.impl.SuperimposingManagerImpl.java
/** * Find all existing superimposing registrations using all query defined in service configuration. * @param resolver Resource resolver//from w ww . ja v a 2 s . c om * @return All superimposing registrations */ @SuppressWarnings("unchecked") private List<Resource> findSuperimposings(ResourceResolver resolver) { List<Resource> allResources = new ArrayList<Resource>(); for (String queryString : this.findAllQueries) { if (!StringUtils.contains(queryString, "|")) { throw new IllegalArgumentException( "Query string does not contain query syntax seperated by '|': " + queryString); } String queryLanguage = StringUtils.substringBefore(queryString, "|"); String query = StringUtils.substringAfter(queryString, "|"); allResources.addAll(IteratorUtils.toList(resolver.findResources(query, queryLanguage))); } return allResources; }
From source file:org.apache.usergrid.chop.webapp.elasticsearch.Util.java
/** * Converts a string to map. String should have this format: {2=b, 1=a}. *///from w ww . j ava 2 s .co m public static Map<String, String> getMap(Map<String, Object> json, String key) { HashMap<String, String> map = new HashMap<String, String>(); String str = getString(json, key); if (StringUtils.isEmpty(str) || !str.startsWith("{") || !str.endsWith("}") || str.equals("{}")) { return map; } String values[] = StringUtils.substringBetween(str, "{", "}").split(","); for (String s : values) { map.put(StringUtils.substringBefore(s, "=").trim(), StringUtils.substringAfter(s, "=").trim()); } return map; }
From source file:org.apdplat.platform.util.ReflectionUtils.java
/** * Class.getSimpleName()?javassist??//from w w w .j a v a 2s.c o m * * @see Class#getSimpleName() */ public static String getSimpleSurname(Class<?> clazz) { if (clazz == null) { return null; } return StringUtils.substringBefore(clazz.getSimpleName(), "_$$_"); }
From source file:org.apdplat.platform.util.ReflectionUtils.java
/** * Class.getName()?javassist??// www. ja v a 2 s . c o m * * @see Class#getName() */ public static String getSurname(Class<?> clazz) { if (clazz == null) { return null; } return StringUtils.substringBefore(clazz.getName(), "_$$_"); }
From source file:org.apdplat.platform.util.Struts2Utils.java
public static void render(final String contentType, final String content, final String... headers) { try {/*from ww w .ja va 2 s . c o m*/ //?headers? String encoding = ENCODING_DEFAULT; boolean noCache = NOCACHE_DEFAULT; for (String header : headers) { String headerName = StringUtils.substringBefore(header, ":"); String headerValue = StringUtils.substringAfter(header, ":"); if (StringUtils.equalsIgnoreCase(headerName, ENCODING_PREFIX)) { encoding = headerValue; } else if (StringUtils.equalsIgnoreCase(headerName, NOCACHE_PREFIX)) { noCache = Boolean.parseBoolean(headerValue); } else { throw new IllegalArgumentException(headerName + "??header"); } } HttpServletResponse response = ServletActionContext.getResponse(); //headers? String fullContentType = contentType + ";charset=" + encoding; response.setContentType(fullContentType); if (noCache) { response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); } response.getWriter().write(content); response.getWriter().flush(); } catch (IOException e) { LOG.error(e.getMessage(), e); } }
From source file:org.artifactory.maven.MavenMetadataCalculator.java
private boolean createSnapshotsMetadata(RepoPath repoPath, ItemNode treeNode) { if (!folderContainsPoms(treeNode)) { return false; }//from w ww .j a va 2 s . co m List<ItemNode> folderItems = treeNode.getChildren(); Iterable<ItemNode> poms = Iterables.filter(folderItems, new Predicate<ItemNode>() { @Override public boolean apply(@Nullable ItemNode input) { return (input != null) && MavenNaming.isPom(input.getItemInfo().getName()); } }); RepoPath firstPom = poms.iterator().next().getRepoPath(); MavenArtifactInfo artifactInfo = MavenArtifactInfo.fromRepoPath(firstPom); if (!artifactInfo.isValid()) { return true; } Metadata metadata = new Metadata(); metadata.setGroupId(artifactInfo.getGroupId()); metadata.setArtifactId(artifactInfo.getArtifactId()); String baseVersion = StringUtils.substringBefore(artifactInfo.getVersion(), "-"); metadata.setVersion(baseVersion + MavenNaming.SNAPSHOT_SUFFIX); Versioning versioning = new Versioning(); metadata.setVersioning(versioning); versioning.setLastUpdatedTimestamp(new Date()); Snapshot snapshot = new Snapshot(); versioning.setSnapshot(snapshot); LocalRepoDescriptor localRepoDescriptor = getRepositoryService() .localOrCachedRepoDescriptorByKey(repoPath.getRepoKey()); SnapshotVersionBehavior snapshotBehavior = localRepoDescriptor.getSnapshotVersionBehavior(); String latestUniquePom = getLatestUniqueSnapshotPomName(poms); if (snapshotBehavior.equals(SnapshotVersionBehavior.NONUNIQUE) || (snapshotBehavior.equals(SnapshotVersionBehavior.DEPLOYER) && latestUniquePom == null)) { snapshot.setBuildNumber(1); } else if (snapshotBehavior.equals(SnapshotVersionBehavior.UNIQUE)) { // take the latest unique snapshot file file if (latestUniquePom != null) { snapshot.setBuildNumber(MavenNaming.getUniqueSnapshotVersionBuildNumber(latestUniquePom)); snapshot.setTimestamp(MavenNaming.getUniqueSnapshotVersionTimestamp(latestUniquePom)); } if (ConstantValues.mvnMetadataVersion3Enabled.getBoolean()) { List<SnapshotVersion> snapshotVersions = Lists .newArrayList(getFolderItemSnapshotVersions(folderItems)); if (!snapshotVersions.isEmpty()) { versioning.setSnapshotVersions(snapshotVersions); } } } saveMetadata(repoPath, metadata); return true; }
From source file:org.artifactory.maven.MavenMetadataCalculator.java
private Collection<SnapshotVersion> getFolderItemSnapshotVersions(Collection<ItemNode> folderItems) { List<SnapshotVersion> snapshotVersionsToReturn = Lists.newArrayList(); Map<SnapshotVersionType, ModuleInfo> latestSnapshotVersions = Maps.newHashMap(); for (ItemNode folderItem : folderItems) { String folderItemPath = folderItem.getItemInfo().getRelPath(); if (MavenNaming.isUniqueSnapshot(folderItemPath)) { ModuleInfo folderItemModuleInfo; if (MavenNaming.isPom(folderItemPath)) { folderItemModuleInfo = ModuleInfoUtils.moduleInfoFromDescriptorPath(folderItemPath, RepoLayoutUtils.MAVEN_2_DEFAULT); } else { folderItemModuleInfo = ModuleInfoUtils.moduleInfoFromArtifactPath(folderItemPath, RepoLayoutUtils.MAVEN_2_DEFAULT); }/*from w w w . j a va 2s . c om*/ if (!folderItemModuleInfo.isValid() || !folderItemModuleInfo.isIntegration()) { continue; } SnapshotVersionType folderItemSnapshotVersionType = new SnapshotVersionType( folderItemModuleInfo.getExt(), folderItemModuleInfo.getClassifier()); if (latestSnapshotVersions.containsKey(folderItemSnapshotVersionType)) { SnapshotComparator snapshotComparator = createSnapshotComparator(); ModuleInfo latestSnapshotVersion = latestSnapshotVersions.get(folderItemSnapshotVersionType); if (snapshotComparator.compare(folderItemModuleInfo, latestSnapshotVersion) > 0) { latestSnapshotVersions.put(folderItemSnapshotVersionType, folderItemModuleInfo); } } else { latestSnapshotVersions.put(folderItemSnapshotVersionType, folderItemModuleInfo); } } } for (ModuleInfo latestSnapshotVersion : latestSnapshotVersions.values()) { SnapshotVersion snapshotVersion = new SnapshotVersion(); snapshotVersion.setClassifier(latestSnapshotVersion.getClassifier()); snapshotVersion.setExtension(latestSnapshotVersion.getExt()); String fileItegRev = latestSnapshotVersion.getFileIntegrationRevision(); snapshotVersion.setVersion(latestSnapshotVersion.getBaseRevision() + "-" + fileItegRev); snapshotVersion.setUpdated(StringUtils.remove(StringUtils.substringBefore(fileItegRev, "-"), '.')); snapshotVersionsToReturn.add(snapshotVersion); } return snapshotVersionsToReturn; }
From source file:org.b3log.latke.client.LatkeClient.java
/** * Gets the backup file name filed value with the specified repository backup file name and field name. * /*from ww w. j ava2 s.com*/ * <p> * A repository backup file (not restored yet) name: "1_5_1334889225650.json", ${pageNum}_${pageSize}_${backupTime}.json * </p> * * <p> * A repository backup file (restored) name: "1_5_1334889225470_1334889225650.json", * ${pageNum}_${pageSize}_${backupTime}_${restoreTime}.json * </p> * * @param repositoryBackupFileName the specified repository backup file name * @param field the specified, for example ${pageNum} * @return backup file name filed value, returns {@code null} if not found */ private static String getBackupFileNameField(final String repositoryBackupFileName, final String field) { final String[] fields = repositoryBackupFileName.split("_"); if ("${pageNum}".equals(field) && fields.length > 0) { return fields[0]; } if ("${pageSize}".equals(field) && fields.length > 1) { return fields[1]; } if ("${backupTime}".equals(field) && fields.length > 2) { return StringUtils.substringBefore(fields[2], ".json"); } if ("${restoreTime}".equals(field) && fields.length > 3) { return StringUtils.substringBefore(fields[3], ".json"); } return null; }
From source file:org.b3log.latke.Latkes.java
/** * Initializes {@linkplain RuntimeEnv runtime environment}. * * <p>//from ww w . java 2 s . com * Sets the current {@link RuntimeMode runtime mode} to {@link RuntimeMode#DEVELOPMENT development mode}. * </p> * * @see RuntimeEnv */ public static void initRuntimeEnv() { if (null != runtimeEnv) { return; } LOGGER.log(Level.TRACE, "Initializes runtime environment from configuration file"); final String runtimeEnvValue = LATKE_PROPS.getProperty("runtimeEnv"); if (null != runtimeEnvValue) { runtimeEnv = RuntimeEnv.valueOf(runtimeEnvValue); } runtimeEnv = RuntimeEnv.LOCAL; if (null == runtimeMode) { final String runtimeModeValue = LATKE_PROPS.getProperty("runtimeMode"); if (null != runtimeModeValue) { runtimeMode = RuntimeMode.valueOf(runtimeModeValue); } else { LOGGER.log(Level.TRACE, "Can't parse runtime mode in latke.properties, default to [PRODUCTION]"); runtimeMode = RuntimeMode.PRODUCTION; } } LOGGER.log(Level.INFO, "Latke is running on [{0}] with mode [{1}]", new Object[] { Latkes.getRuntimeEnv(), Latkes.getRuntimeMode() }); if (RuntimeEnv.LOCAL == runtimeEnv) { // Read local database configurations final RuntimeDatabase runtimeDatabase = getRuntimeDatabase(); LOGGER.log(Level.INFO, "Runtime database is [{0}]", runtimeDatabase); if (RuntimeDatabase.H2 == runtimeDatabase) { final String newTCPServer = Latkes.getLocalProperty("newTCPServer"); if ("true".equals(newTCPServer)) { LOGGER.log(Level.INFO, "Starting H2 TCP server"); final String jdbcURL = Latkes.getLocalProperty("jdbc.URL"); if (Strings.isEmptyOrNull(jdbcURL)) { throw new IllegalStateException("The jdbc.URL in local.properties is required"); } final String[] parts = jdbcURL.split(":"); if (parts.length != Integer.valueOf("5")/* CheckStyle.... */) { throw new IllegalStateException( "jdbc.URL should like [jdbc:h2:tcp://localhost:8250/~/] (the port part is required)"); } String port = parts[parts.length - 1]; port = StringUtils.substringBefore(port, "/"); LOGGER.log(Level.TRACE, "H2 TCP port [{0}]", port); try { h2 = org.h2.tools.Server .createTcpServer(new String[] { "-tcpPort", port, "-tcpAllowOthers" }).start(); } catch (final SQLException e) { final String msg = "H2 TCP server create failed"; LOGGER.log(Level.ERROR, msg, e); throw new IllegalStateException(msg); } LOGGER.info("Started H2 TCP server"); } } } locale = new Locale("en_US"); }