List of usage examples for org.apache.commons.lang StringUtils remove
public static String remove(String str, char remove)
Removes all occurrences of a character from within the source string.
From source file:org.apache.blur.console.util.SearchUtil.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static Map<String, Object> fetchRow(String table, String query, String[] families, User user, String securityUser) throws IOException, TException { try {/*from w w w.ja va 2s. c om*/ Iface client = Config.getClient(user, securityUser); Selector selector = new Selector(); String rowid = StringUtils.remove(query, "rowid:"); selector.setRowId(rowid); selector.setColumnFamiliesToFetch(new HashSet<String>(Arrays.asList(families))); Map<String, Object> results = new HashMap<String, Object>(); long startTime = System.currentTimeMillis(); FetchResult fetchRow = client.fetchRow(table, selector); results.put(TIME_KEY, System.currentTimeMillis() - startTime); results.put(TOTAL_KEY, fetchRow.getRowResult().getRow() == null ? 0 : 1); Map<String, List> rows = new HashMap<String, List>(); Row row = fetchRow.getRowResult().getRow(); if (row != null && row.getRecords() != null) { for (Record record : row.getRecords()) { String family = record.getFamily(); List<ResultRow> fam = (List<ResultRow>) getFam(family, rows, false); ResultRow rowData = getRow(row.getId(), fam); rowData.getRecords().add(buildRow(record.getColumns(), record.getRecordId())); } } results.put(DATA_KEY, rows); results.put(FAMILY_KEY, new HashSet<String>(Arrays.asList(families))); return results; } finally { UserContext.reset(); } }
From source file:org.apache.cassandra.cql3.CreateIndexStatementTest.java
/** * Removes the quotes from the specified index name. * * @param indexName the index name from which the quotes must be removed. * @return the unquoted index name.//from w w w. j a va 2s . com */ private static String removeQuotes(String indexName) { return StringUtils.remove(indexName, '\"'); }
From source file:org.apache.gobblin.data.management.copy.writer.TarArchiveInputStreamDataWriter.java
/** * Untars the passed in {@link FileAwareInputStream} to the task's staging directory. Uses the name of the root * {@link TarArchiveEntry} in the stream as the directory name for the untarred file. The method also commits the data * by moving the file from staging to output directory. * * @see org.apache.gobblin.data.management.copy.writer.FileAwareInputStreamDataWriter#write(org.apache.gobblin.data.management.copy.FileAwareInputStream) *///from w w w.j av a 2 s.c o m @Override public void writeImpl(InputStream inputStream, Path writeAt, CopyableFile copyableFile) throws IOException { this.closer.register(inputStream); TarArchiveInputStream tarIn = new TarArchiveInputStream(inputStream); final ReadableByteChannel inputChannel = Channels.newChannel(tarIn); TarArchiveEntry tarEntry; // flush the first entry in the tar, which is just the root directory tarEntry = tarIn.getNextTarEntry(); String tarEntryRootName = StringUtils.remove(tarEntry.getName(), Path.SEPARATOR); log.info("Unarchiving at " + writeAt); try { while ((tarEntry = tarIn.getNextTarEntry()) != null) { // the API tarEntry.getName() is misleading, it is actually the path of the tarEntry in the tar file String newTarEntryPath = tarEntry.getName().replace(tarEntryRootName, writeAt.getName()); Path tarEntryStagingPath = new Path(writeAt.getParent(), newTarEntryPath); if (!FileUtils.isSubPath(writeAt.getParent(), tarEntryStagingPath)) { throw new IOException( String.format("Extracted file: %s is trying to write outside of output directory: %s", tarEntryStagingPath, writeAt.getParent())); } if (tarEntry.isDirectory() && !this.fs.exists(tarEntryStagingPath)) { this.fs.mkdirs(tarEntryStagingPath); } else if (!tarEntry.isDirectory()) { FSDataOutputStream out = this.fs.create(tarEntryStagingPath, true); final WritableByteChannel outputChannel = Channels.newChannel(out); try { StreamCopier copier = new StreamCopier(inputChannel, outputChannel); if (isInstrumentationEnabled()) { copier.withCopySpeedMeter(this.copySpeedMeter); } this.bytesWritten.addAndGet(copier.copy()); if (isInstrumentationEnabled()) { log.info("File {}: copied {} bytes, average rate: {} B/s", copyableFile.getOrigin().getPath(), this.copySpeedMeter.getCount(), this.copySpeedMeter.getMeanRate()); } else { log.info("File {} copied.", copyableFile.getOrigin().getPath()); } } finally { out.close(); outputChannel.close(); } } } } finally { tarIn.close(); inputChannel.close(); inputStream.close(); } }
From source file:org.apache.jackrabbit.core.query.lucene.JahiaNodeIndexer.java
/** * Adds the value to the document both as faceted field which will be indexed with a keyword analyzer which does not modify the term. * * @param doc The document to which to add the field * @param fieldName The name of the field to add * @param internalValue The value for the field to add to the document. *//*from w w w. j a v a 2 s. c o m*/ protected void addHierarchicalFacetValue(Document doc, String fieldName, Object internalValue) { final String stringValue = (String) internalValue.toString(); if (stringValue.length() == 0) { return; } ItemId itemId = (ItemId) internalValue; int idx = fieldName.indexOf(':'); fieldName = fieldName.substring(0, idx + 1) + FACET_PREFIX + fieldName.substring(idx + 1); final List<String> hierarchyPaths = new ArrayList<String>(); final List<String> parentIds = new ArrayList<String>(); try { NodeState node = (NodeState) stateProvider.getItemState(itemId); Name typeName = node.getNodeTypeName(); boolean isCategoryType = typeName.toString().equals("{" + Constants.JAHIANT_NS + "}" + "category"); NodeState parent = (NodeState) stateProvider.getItemState(node.getParentId()); while (typeName.equals(parent.getNodeTypeName())) { hierarchyPaths .add(StringUtils.remove(resolver.getJCRPath(hierarchyMgr.getPath(node.getNodeId())), "0:")); parentIds.add(node.getNodeId().toString()); node = parent; parent = (NodeState) stateProvider.getItemState(node.getParentId()); } String jcrPath = resolver.getJCRPath(hierarchyMgr.getPath(node.getNodeId())); // we stop either at the root (/) or in case of categories also at /sites/systemsite while (!"/".equals(jcrPath) && (!isCategoryType || !("0:/0:sites/0:systemsite").equals(jcrPath))) { parentIds.add(node.getNodeId().toString()); node = (NodeState) stateProvider.getItemState(node.getParentId()); jcrPath = resolver.getJCRPath(hierarchyMgr.getPath(node.getNodeId())); } } catch (NoSuchItemStateException e) { if (logger.isDebugEnabled()) { logger.debug(e.getMessage(), e); } } catch (ItemStateException e) { logger.error(e.getMessage(), e); } catch (RepositoryException e) { logger.error(e.getMessage(), e); } int hierarchyIndex = hierarchyPaths.size(); for (String path : hierarchyPaths) { doc.add(new Field(fieldName, true, hierarchyIndex + path, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO)); hierarchyIndex--; } for (String id : parentIds) { doc.add(new Field(FACET_HIERARCHY, false, id, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO)); } }
From source file:org.apache.jackrabbit.core.query.lucene.JahiaSearchIndex.java
protected boolean isNodeExcluded(final NodeState node) throws RepositoryException { try {//from w w w . j av a 2s .com // manage translation nodes String nodeTypeName = JahiaNodeIndexer.getTypeNameAsString(node.getNodeTypeName(), getContext().getNamespaceRegistry()); NodeState nodeToProcess = Constants.JAHIANT_TRANSLATION.equals(nodeTypeName) ? (NodeState) getContext().getItemStateManager().getItemState(node.getParentId()) : node; String localPath = null; for (JahiaIndexingConfigurationImpl.ExcludedType excludedType : ((JahiaIndexingConfigurationImpl) getIndexingConfig()) .getExcludesTypesByPath()) { if (!excludedType.matchesNodeType(nodeToProcess)) { continue; } if (localPath == null) { localPath = StringUtils.remove(getNamespaceMappings().translatePath( getContext().getHierarchyManager().getPath(nodeToProcess.getId()).getNormalizedPath()), "0:"); } if (excludedType.matchPath(localPath)) { // do not index the content return true; } } } catch (ItemStateException e) { log.debug("While indexing translation node unable to get its parent item", e); return true; } return false; }
From source file:org.apache.lucene.search.SearchFiles.java
/** * This demonstrates a typical paging search scenario, where the search engine presents * pages of size n to the user. The user can then go to the next page if interested in * the next hits./*from ww w .j a v a 2 s.co m*/ * * When the query is executed for the first time, then only enough results are collected * to fill 5 result pages. If the user wants to page beyond this limit, then the query * is executed another time and all hits are collected. * */ public static void doPagingSearch(BufferedReader in, Searcher searcher, Query query, int hitsPerPage, boolean raw) throws IOException { // Collect enough docs to show 5 pages TopDocCollector collector = new TopDocCollector(5 * hitsPerPage); searcher.search(query, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; int numTotalHits = collector.getTotalHits(); System.out.println(numTotalHits + " total matching documents"); int start = 0; int end = Math.min(numTotalHits, hitsPerPage); SearchUtil searchUtil = new SearchUtil(); while (true) { if (end > hits.length) { System.out.println("Only results 1 - " + hits.length + " of " + numTotalHits + " total matching documents collected."); System.out.println("Collect more (y/n) ?"); String line = in.readLine(); if (line.length() == 0 || line.charAt(0) == 'n') { break; } collector = new TopDocCollector(numTotalHits); searcher.search(query, collector); hits = collector.topDocs().scoreDocs; } end = Math.min(hits.length, start + hitsPerPage); for (int i = start; i < end; i++) { if (raw) { // output raw format System.out.println("doc=" + hits[i].doc + " score=" + hits[i].score); continue; } Document doc = searcher.doc(hits[i].doc); String path = doc.get("path"); if (path != null) { System.out.println((i + 1) + ". " + path); try { searchUtil.parse(new File(path)); } catch (InterruptedException e) { e.printStackTrace(); } /*String title = doc.get("title"); if (title != null) { System.out.println(" Title: " + doc.get("title")); }*/ String title = SearchUtil.getTitle(searchUtil.getContents()); String contents = SearchUtil.removeTitle(searchUtil.getContents(), title); contents = SearchUtil.removeJspTags(contents); contents = SearchUtil.removeDirty(contents, "\"", "/>", 2); contents = SearchUtil.removeDirty(contents, "\"", "\">", 2); contents = StringUtils.remove(contents, "\" >"); contents = SearchUtil.removeDirty(contents, "[", "]", 1); contents = StringUtils.replace(contents, " ", ""); contents = StringUtils.replace(contents, "", ""); contents = StringUtils.replace(contents, "", ""); contents = StringUtils.replace(contents, "Back To Top", ""); contents = StringUtils.replace(contents, "Learn More", ""); contents = StringUtils.replace(contents, "View Here", ""); contents = StringUtils.replace(contents, "Submit App", ""); String displayStr = SearchUtil.createDisplayStr(contents, queryString); displayStr = SearchUtil.highlightSearchWord(displayStr, queryString); System.out.println(" title: " + title); System.out.println(" contents: " + contents); System.out.println(" displayStr: " + displayStr); } else { System.out.println((i + 1) + ". " + "No path for this document"); } System.out.println("================================================================"); } if (numTotalHits >= end) { boolean quit = false; while (true) { System.out.print("Press "); if (start - hitsPerPage >= 0) { System.out.print("(p)revious page, "); } if (start + hitsPerPage < numTotalHits) { System.out.print("(n)ext page, "); } System.out.println("(q)uit or enter number to jump to a page."); String line = in.readLine(); if (line.length() == 0 || line.charAt(0) == 'q') { quit = true; break; } if (line.charAt(0) == 'p') { start = Math.max(0, start - hitsPerPage); break; } else if (line.charAt(0) == 'n') { if (start + hitsPerPage < numTotalHits) { start += hitsPerPage; } break; } else { int page = Integer.parseInt(line); if ((page - 1) * hitsPerPage < numTotalHits) { start = (page - 1) * hitsPerPage; break; } else { System.out.println("No such page"); } } } if (quit) break; end = Math.min(numTotalHits, start + hitsPerPage); } } }
From source file:org.apache.lucene.search.SearchUtil.java
public static String createDisplayStr(String contents, String searchText) { if (contents.indexOf("Dashboard Dev Center - Technical Resources") != -1) { String _break = ""; System.out.println(_break); }//from w w w . j a v a 2s.c o m if (contents != null && contents.length() <= 150) { return contents; } //Remove some special characters contents = StringUtils.remove(contents, "\""); contents = StringUtils.remove(contents, "\'"); contents = StringUtils.remove(contents, "("); contents = StringUtils.remove(contents, ")"); contents = StringUtils.remove(contents, "{"); contents = StringUtils.remove(contents, "}"); contents = StringUtils.remove(contents, "["); contents = StringUtils.remove(contents, "]"); searchText = StringUtils.replace(searchText, " ", " "); String originalContents = contents; contents = contents.toLowerCase(); //for case-insensitive searching String displayStr = ""; searchText = searchText.toLowerCase(); boolean andCondition = false; //user searched using query: "apply your ideas" if (searchText.indexOf("\"") != -1 && searchText.lastIndexOf("\"") != -1) { andCondition = true; } searchText = searchText.replace("\"", ""); String[] searchTextArray = null; if (contents != null && contents.trim().length() > 0 && andCondition && contents.indexOf(searchText) != -1) { searchTextArray = new String[] { searchText }; } else { //user searched using query: apply your ideas searchTextArray = searchText.split(" "); } for (int i = 0; i < searchTextArray.length; i++) { if (contents.indexOf(searchTextArray[i] + " ") != -1) { displayStr = displayStr(originalContents, contents, searchTextArray[i] + " "); if (displayStr.length() > 0) { return displayStr; } } } if (displayStr.length() == 0) { if (originalContents.length() > 100) { displayStr = originalContents.substring(0, 99); } else { displayStr = originalContents; } displayStr = displayStr.substring(0, displayStr.trim().lastIndexOf(" ") + 1); } return displayStr; }
From source file:org.apache.maven.scm.provider.svn.svnjava.command.status.SvnStatusHandler.java
/** * This is an implementation of {@link ISVNStatusHandler#handleStatus(org.tmatesoft.svn.core.wc.SVNStatus) *//*from w ww .j a va 2 s . co m*/ public void handleStatus(SVNStatus status) { /* Gets the status of file/directory/symbolic link text contents. * It is SVNStatusType who contains information on the state of an * item. */ SVNStatusType contentsStatus = status.getCombinedNodeAndContentsStatus(); //status.getContentsStatus(); ScmFileStatus scmStatus = null; if (contentsStatus == SVNStatusType.STATUS_MODIFIED) { scmStatus = ScmFileStatus.MODIFIED; } else if (contentsStatus == SVNStatusType.STATUS_CONFLICTED) { scmStatus = ScmFileStatus.CONFLICT; } else if (contentsStatus == SVNStatusType.STATUS_MERGED) { /* The file item was merGed (changes that came from the repository * did not overlap local changes and were merged into the file). * "G" */ scmStatus = ScmFileStatus.PATCHED; } else if (contentsStatus == SVNStatusType.STATUS_DELETED) { /* The file, directory or symbolic link item has been scheduled for * Deletion from the repository. * "D" */ scmStatus = ScmFileStatus.DELETED; } else if (contentsStatus == SVNStatusType.STATUS_ADDED) { /* The file, directory or symbolic link item has been scheduled for * Addition to the repository. * "A" */ scmStatus = ScmFileStatus.ADDED; } else if (contentsStatus == SVNStatusType.STATUS_UNVERSIONED) { /* The file, directory or symbolic link item is not under version * control. * "?" */ scmStatus = ScmFileStatus.UNKNOWN; } else if (contentsStatus == SVNStatusType.STATUS_EXTERNAL) { /* The item is unversioned, but is used by an eXternals definition. * "X" */ scmStatus = ScmFileStatus.UNKNOWN; } else if (contentsStatus == SVNStatusType.STATUS_IGNORED) { /* The file, directory or symbolic link item is not under version * control, and is configured to be Ignored during 'add', 'import' * and 'status' operations. * "I" */ // We don't care about files that are ignored. scmStatus = null; } else if (contentsStatus == SVNStatusType.STATUS_MISSING || contentsStatus == SVNStatusType.STATUS_INCOMPLETE) { /* The file, directory or symbolic link item is under version * control but is missing or somehow incomplete. The item can be * missing if it is removed using a command incompatible with the * native Subversion command line client (for example, just removed * from the filesystem). In the case the item is a directory, it * can be incomplete if the user happened to interrupt a checkout * or update. * "!" */ // TODO: This isn't the right status here. ScmFileStatus doesn't have an error. scmStatus = ScmFileStatus.UNKNOWN; } else if (contentsStatus == SVNStatusType.STATUS_OBSTRUCTED) { /* The file, directory or symbolic link item is in the repository * as one kind of object, but what's actually in the user's working * copy is some other kind. For example, Subversion might have a * file in the repository, but the user removed the file and * created a directory in its place, without using the 'svn delete' * or 'svn add' command (or JavaSVN analogues for them). * "~" */ // TODO: This isn't the right status here. ScmFileStatus doesn't have an error. scmStatus = ScmFileStatus.CONFLICT; } else if (contentsStatus == SVNStatusType.STATUS_REPLACED) { /* The file, directory or symbolic link item was Replaced in the * user's working copy; that is, the item was deleted, and a new * item with the same name was added (within a single revision). * While they may have the same name, the repository considers them * to be distinct objects with distinct histories. * "R" */ scmStatus = ScmFileStatus.ADDED; } else if (contentsStatus == SVNStatusType.STATUS_NONE || contentsStatus == SVNStatusType.STATUS_NORMAL) { /* * The item was not modified (normal). * " " */ // Ignore these scmStatus = null; } /* * Now getting the status of properties of an item. SVNStatusType also * contains information on the properties state. */ SVNStatusType propertiesStatus = status.getPropertiesStatus(); /* * Default - properties are normal (unmodified). */ if (scmStatus == null && propertiesStatus == SVNStatusType.STATUS_MODIFIED) { /* * Properties were modified. * "M" */ scmStatus = ScmFileStatus.MODIFIED; } else if (scmStatus == null && propertiesStatus == SVNStatusType.STATUS_CONFLICTED) { /* * Properties are in conflict with the repository. * "C" */ scmStatus = ScmFileStatus.CONFLICT; } // Only add files and not directories to our list. if (scmStatus != null && status.getKind() != SVNNodeKind.DIR) { String normalizedPath = FilenameUtils.normalizeFilename(status.getFile().getAbsolutePath()); normalizedPath = StringUtils.remove(normalizedPath, FilenameUtils.normalizeFilename(this.baseDir.getAbsolutePath())); normalizedPath = StringUtils.removeStart(normalizedPath, "/"); files.add(new ScmFile(normalizedPath, scmStatus)); } }
From source file:org.apache.myfaces.trinidaddemo.webapp.SourceCodeServlet.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { String webPage = req.getServletPath(); // remove the '*.source' suffix that maps to this servlet int source = webPage.indexOf(".source"); webPage = webPage.substring(0, source); //remove "/faces" mapping webPage = StringUtils.remove(webPage, "/faces"); // get the actual file location of the requested resource String realPath = getServletConfig().getServletContext().getRealPath(webPage); // output an HTML page res.setContentType("text/plain"); // print some html ServletOutputStream out = res.getOutputStream(); // print the file InputStream in = null;/*from w ww .j ava 2s. co m*/ try { in = new BufferedInputStream(new FileInputStream(realPath)); int ch; while ((ch = in.read()) != -1) { out.print((char) ch); } } finally { if (in != null) in.close(); // very important } }
From source file:org.apache.qpid.server.security.access.ObjectProperties.java
public static List<String> getAllPropertyNames() { List<String> properties = new ArrayList<String>(); for (Property property : Property.values()) { properties.add(StringUtils.remove(property.name(), '_').toLowerCase()); }//from w w w. ja v a 2s.c om return properties; }