List of usage examples for org.apache.commons.lang3 StringUtils removeEnd
public static String removeEnd(final String str, final String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
A null source string will return null .
From source file:net.eledge.android.europeana.gui.activity.RecordActivity.java
private void handleIntent(Intent intent) { String id = null;/*from w w w .jav a 2s .c o m*/ if (intent != null) { if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); // only one message sent during the beam NdefMessage msg = (NdefMessage) rawMsgs[0]; // record 0 contains the MIME type, record 1 is the AAR, if present id = new String(msg.getRecords()[0].getPayload()); } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { id = StringUtils.defaultIfBlank(intent.getDataString(), intent.getStringExtra(RECORD_ID)); } if (StringUtils.contains(id, "europeana.eu/")) { Uri uri = Uri.parse(id); List<String> paths = uri.getPathSegments(); if ((paths != null) && (paths.size() == 4)) { String collectionId = paths.get(paths.size() - 2); String recordId = StringUtils.removeEnd(paths.get(paths.size() - 1), ".html"); id = StringUtils.join("/", collectionId, "/", recordId); } else { // invalid url/id, cancel opening record id = null; } } if (StringUtils.isNotBlank(id)) { openRecord(id); } } }
From source file:com.norconex.jef4.suite.JobSuite.java
public static void stop(File indexFile) throws IOException { if (indexFile == null || !indexFile.exists() || !indexFile.isFile()) { throw new JEFException("Invalid index file: " + indexFile); }//from w w w. j ava 2s. co m String stopPath = StringUtils.removeEnd(indexFile.getAbsolutePath(), "index"); stopPath += ".stop"; if (!new File(stopPath).createNewFile()) { throw new IOException("Could not create stop file: " + stopPath); } }
From source file:com.xpn.xwiki.objects.classes.PropertyClass.java
/** * Each type of XClass property is identified by a string that specifies the data type of the property value (e.g. * 'String', 'Number', 'Date') without disclosing implementation details. The internal implementation of an XClass * property type can change over time but its {@code classType} should not. * <p>/*from w w w.j av a 2 s. co m*/ * The {@code classType} can be used as a hint to lookup various components related to this specific XClass property * type. See {@link com.xpn.xwiki.internal.objects.classes.PropertyClassProvider} for instance. * * @return an identifier for the data type of the property value (e.g. 'String', 'Number', 'Date') */ public String getClassType() { // By default the hint is computed by removing the Class suffix, if present, from the Java simple class name // (without the package). Subclasses can overwrite this method to use a different hint format. return StringUtils.removeEnd(getClass().getSimpleName(), "Class"); }
From source file:com.norconex.importer.handler.splitter.impl.TranslatorSplitter.java
private ImporterMetadata translateFields(SplittableDocument doc, Translator translator, String sourceLang, String targetLang) throws Exception { ImporterMetadata childMeta = new ImporterMetadata(); if (ignoreNonTranslatedFields) { if (fieldsToTranslate == null) { return childMeta; }/*from w w w . j ava 2s. c o m*/ for (String key : fieldsToTranslate) { List<String> values = doc.getMetadata().get(key); if (values != null) { childMeta.put(key, values); } } } else { childMeta.load(doc.getMetadata()); if (fieldsToTranslate == null) { return childMeta; } } StringBuilder b = new StringBuilder(); for (int i = 0; i < fieldsToTranslate.length; i++) { List<String> values = doc.getMetadata().get(fieldsToTranslate[i]); for (String value : values) { b.append("[" + value.replaceAll("[\n\\[\\]]", " ") + "]"); } b.append("\n"); } if (b.length() == 0) { return childMeta; } String txt = translator.translate(b.toString(), sourceLang, targetLang); List<String> lines = IOUtils.readLines(new StringReader(txt)); int index = 0; for (String line : lines) { line = StringUtils.removeStart(line, "["); line = StringUtils.removeEnd(line, "]"); String[] values = StringUtils.splitByWholeSeparator(line, "]["); childMeta.setString(fieldsToTranslate[index], values); index++; } return childMeta; }
From source file:com.xpn.xwiki.plugin.watchlist.WatchListEvent.java
/** * @param objectDiffs List of object diff * @param isXWikiClass is the diff to compute the diff for a xwiki class, the other possibility being a plain xwiki * object//from w ww .j a va2s . c o m * @param documentFullName full name of the document the diff is computed for * @param diff the diff plugin API * @return The HTML diff */ private String getObjectsHTMLDiff(List<List<ObjectDiff>> objectDiffs, boolean isXWikiClass, String documentFullName, DiffPluginApi diff) { StringBuffer result = new StringBuffer(); String propSeparator = ": "; String prefix = (isXWikiClass) ? "class" : "object"; try { for (List<ObjectDiff> oList : objectDiffs) { if (oList.size() > 0) { Div mainDiv = createDiffDiv(prefix + "Diff"); Span objectName = createDiffSpan(prefix + "ClassName"); if (isXWikiClass) { objectName.addElement(getFullName()); } else { objectName.addElement(oList.get(0).getClassName()); } mainDiv.addElement(prefix + HTML_IMG_PLACEHOLDER_SUFFIX); mainDiv.addElement(objectName); for (ObjectDiff oDiff : oList) { String propDiff = getPropertyHTMLDiff(oDiff, diff); if (!StringUtils.isBlank(oDiff.getPropName()) && !StringUtils.isBlank(propDiff)) { Div propDiv = createDiffDiv("propDiffContainer"); Span propNameSpan = createDiffSpan("propName"); propNameSpan.addElement(oDiff.getPropName() + propSeparator); String shortPropType = StringUtils.removeEnd(oDiff.getPropType(), "Class") .toLowerCase(); if (StringUtils.isBlank(shortPropType)) { // When the diff shows a property that has been deleted, its type is not available. shortPropType = HTML_IMG_METADATA_PREFIX; } propDiv.addElement(shortPropType + HTML_IMG_PLACEHOLDER_SUFFIX); propDiv.addElement(propNameSpan); Div propDiffDiv = createDiffDiv("propDiff"); propDiffDiv.addElement(propDiff); propDiv.addElement(propDiffDiv); mainDiv.addElement(propDiv); } } result.append(mainDiv); } } } catch (XWikiException e) { // Catch the exception to be sure we won't send emails containing stacktraces to users. e.printStackTrace(); } return result.toString(); }
From source file:de.tuberlin.uebb.jbop.optimizer.ClassNodeBuilder.java
/** * Initializes a classField in the default lastConstructor * (eg: if fieldType of field "field" is "TestObject", field = new TestObject() is called). * //from w ww .j a v a2s .c om * Numbers and Strings are used to assign "field", every other value leads to new Object. * * @param object * the object to Use. * @return the abstract optimizer test */ public ClassNodeBuilder initWith(final Object object) { if (isInterface) { return this; } final InsnList list = new InsnList(); if (object instanceof String || object instanceof Number || object instanceof Boolean || object instanceof Character) { list.add(new VarInsnNode(Opcodes.ALOAD, 0)); final AbstractInsnNode numberNode = NodeHelper.getInsnNodeFor(object); list.add(numberNode); if (lastField.desc.startsWith("L") && object instanceof Number) { list.add(ConstructorBuilder.getBoxingNode(lastField)); } list.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, lastField.name, lastField.desc)); } else { list.add(new VarInsnNode(ALOAD, 0)); list.add(newObject(lastField.desc)); list.add(new MethodInsnNode(INVOKESPECIAL, StringUtils.removeEnd(StringUtils.removeStart(lastField.desc, "L"), ";"), "<init>", "()V")); list.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, lastField.name, lastField.desc)); } addToConstructor(list); return this; }
From source file:io.wcm.handler.richtext.impl.RichTextRewriteContentHandlerImpl.java
/** * Converts the RTE externalized form of media reference to internal form. * @param ref Externalize media reference * @return Internal media reference/*from w w w . j av a 2 s. c o m*/ */ private String unexternalizeImageRef(String ref) { String unexternalizedRef = ref; if (StringUtils.isNotEmpty(unexternalizedRef)) { // decode if required unexternalizedRef = decodeIfEncoded(unexternalizedRef); // TODO: implementation has to be aligned with MediaSource implementations! // remove default servlet extension that is needed for inline images in RTE unexternalizedRef = StringUtils.removeEnd(unexternalizedRef, "/" + JcrConstants.JCR_CONTENT + ".default"); unexternalizedRef = StringUtils.removeEnd(unexternalizedRef, "/_jcr_content.default"); } return unexternalizedRef; }
From source file:de.tuberlin.uebb.jbop.optimizer.ClassNodeBuilder.java
/** * Creates Instruction to instantiate a new Object of type "desc". * /*w w w . j a va 2 s . c o m*/ * @param desc * the desc * @return the insn list */ private InsnList newObject(final String desc) { final InsnList list = new InsnList(); final String fieldDesc = StringUtils.removeEnd(StringUtils.removeStart(desc, "L"), ";"); final TypeInsnNode node = new TypeInsnNode(Opcodes.NEW, fieldDesc); list.add(node); list.add(new InsnNode(DUP)); return list; }
From source file:com.google.dart.tools.debug.core.server.ServerDebugTarget.java
private void printExceptionToStdout(VmValue exception) { String text = exception.getText(); int index = text.indexOf('\n'); if (index != -1) { text = text.substring(0, index).trim(); }//from ww w.j a v a 2s . c o m fireStreamAppended("Breaking on exception: " + text); try { VmIsolate isolate = exception.getIsolate(); connection.evaluateObject(isolate, exception, "toString()", new VmCallback<VmValue>() { @Override public void handleResult(VmResult<VmValue> result) { if (result.isError()) { fireStreamAppended("\n"); } else { String desc = result.getResult().getText(); desc = StringUtils.removeStart(desc, "\""); desc = StringUtils.removeEnd(desc, "\""); fireStreamAppended(": " + desc + "\n"); } } }); } catch (IOException e) { } }
From source file:com.neophob.sematrix.core.glue.Collector.java
/** * load a saved preset./*from ww w .j a v a 2 s .com*/ * * @param preset the new current status */ public void setCurrentStatus(List<String> preset) { LOG.log(Level.FINEST, "--------------"); long start = System.currentTimeMillis(); setLoadingPresent(true); for (String s : preset) { s = StringUtils.trim(s); s = StringUtils.removeEnd(s, ";"); LOG.log(Level.FINEST, "LOAD PRESET: " + s); MessageProcessor.processMsg(StringUtils.split(s, ' '), false, null); } setLoadingPresent(false); long needed = System.currentTimeMillis() - start; LOG.log(Level.INFO, "Preset loaded in " + needed + "ms"); }