List of usage examples for org.apache.commons.lang3 StringUtils startsWith
public static boolean startsWith(final CharSequence str, final CharSequence prefix)
Check if a CharSequence starts with a specified prefix.
null s are handled without exceptions.
From source file:org.xwiki.refactoring.internal.splitter.DefaultDocumentSplitter.java
/** * @param document the document whose anchors to update * @param fragments see {@link #collectDocumentFragments(List)} */// ww w. j a v a 2 s . c o m private void updateAnchors(WikiDocument document, Map<String, String> fragments) { for (LinkBlock linkBlock : document.getXdom().<LinkBlock>getBlocks(new ClassBlockMatcher(LinkBlock.class), Axes.DESCENDANT)) { ResourceReference reference = linkBlock.getReference(); ResourceType resoureceType = reference.getType(); String fragment = null; if ((ResourceType.DOCUMENT.equals(resoureceType) || ResourceType.SPACE.equals(resoureceType)) && StringUtils.isEmpty(reference.getReference())) { fragment = reference.getParameter(ANCHOR_PARAMETER); } else if (StringUtils.startsWith(reference.getReference(), "#") && (ResourceType.PATH.equals(resoureceType) || ResourceType.URL.equals(resoureceType))) { fragment = reference.getReference().substring(1); } String targetDocument = fragments.get(fragment); if (targetDocument != null && !targetDocument.equals(document.getFullName())) { // The fragment has been moved so we need to update the link. reference.setType(ResourceType.DOCUMENT); reference.setReference(targetDocument); reference.setParameter(ANCHOR_PARAMETER, fragment); } } }
From source file:org.xwiki.rendering.internal.macro.dashboard.EditableGadgetRenderer.java
/** * @return the renderer corresponding to the "annotated" version of the current target syntax *///from w ww .j a v a 2s . com protected BlockRenderer getGadgetContentRenderer() { // Get the current syntax Syntax currentTargetSyntax = renderingContext.getTargetSyntax(); if (currentTargetSyntax == null) { // (it should never happen actually) return defaultGadgetContentRenderer; } // Get the annotated syntax corresponding to the current target syntax String annotatedTargetSyntax = currentTargetSyntax.toIdString(); if (!StringUtils.startsWith(annotatedTargetSyntax, ANNOTATED_SYNTAXES_PREFIX)) { annotatedTargetSyntax = ANNOTATED_SYNTAXES_PREFIX + annotatedTargetSyntax; } try { return componentManager.getInstance(BlockRenderer.class, annotatedTargetSyntax); } catch (ComponentLookupException e) { logger.warn("Failed to load the syntax [{}].", annotatedTargetSyntax); // Failback to the default renderer return defaultGadgetContentRenderer; } }
From source file:org.xwiki.rendering.macro.groovy.SecurityTest.java
@Test public void testExecutionWhenNoSecureCustomizerAndNoRights() throws Exception { // Conclusion: When running with no customizer and no PR, execution fails. try {/* w w w. ja va 2 s.c o m*/ testExecution(false, false, false, false); Assert.fail("Should have thrown an exception here!"); } catch (MacroExecutionException expected) { Assert.assertTrue(StringUtils.startsWith(expected.getMessage(), "The execution of the [groovy] script macro is not allowed.")); } }
From source file:rs.metropolitan.data_changer.lists.ToList.java
@Override public ArrayList<String> changeString(String data) { String left = "{"; String right = "}"; String doubleQuote = "\""; String seps = ","; if (StringUtils.startsWith(data, left) && StringUtils.endsWith(data, right)) { String cleaned = StringUtils.remove(data, left); cleaned = StringUtils.remove(cleaned, right); cleaned = StringUtils.remove(cleaned, doubleQuote); System.out.println(cleaned); StringTokenizer st = new StringTokenizer(cleaned, seps); while (st.hasMoreTokens()) { ArraylistString.add(st.nextToken()); }//from ww w . jav a 2s .c o m } return ArraylistString; }
From source file:samples.ObjectPredicator.java
public static <T extends CharSequence> Predicate<T> startsWith(final CharSequence prefix) { return t -> StringUtils.startsWith(t, prefix); }
From source file:software.coolstuff.springframework.owncloud.service.impl.AbstractOwncloudServiceTest.java
private boolean isNoResourceLocation() { return !StringUtils.startsWith(properties.getLocation(), "file:") && !StringUtils.startsWith(properties.getLocation(), "classpath:"); }
From source file:software.coolstuff.springframework.owncloud.service.impl.AbstractOwncloudServiceTest.java
private String merge(String templateName, Context context) throws IOException { String prefixedTemplateName = templateName; if (!StringUtils.startsWith(templateName, VELOCITY_PATH_PREFIX)) { prefixedTemplateName = VELOCITY_PATH_PREFIX + templateName; if (StringUtils.startsWith(templateName, "/")) { prefixedTemplateName = VELOCITY_PATH_PREFIX + StringUtils.substring(templateName, 1); }// w w w . ja va 2s. c o m } Template template = velocityEngine.getTemplate(prefixedTemplateName); try (Writer writer = new StringWriter()) { template.merge(context, writer); writer.flush(); return writer.toString(); } }
From source file:software.coolstuff.springframework.owncloud.service.impl.local.file.OwncloudLocalFileTest.java
default Resource getResourceOf(ResourceLoader resourceLoader, String testCase) { if (!(this instanceof OwncloudLocalModifyingFileTest)) { return null; }// w w w . j a va 2 s.c om OwncloudLocalModifyingFileTest modifyingFileResourceTest = (OwncloudLocalModifyingFileTest) this; String path = "/"; if (StringUtils.isNotBlank(modifyingFileResourceTest.getResourcePrefix())) { if (StringUtils.startsWith(modifyingFileResourceTest.getResourcePrefix(), "/")) { path = StringUtils.appendIfMissing(modifyingFileResourceTest.getResourcePrefix(), "/"); } else { path += StringUtils.appendIfMissing(modifyingFileResourceTest.getResourcePrefix(), "/"); } } return resourceLoader.getResource("classpath:" + path + testCase + ".xml"); }
From source file:software.coolstuff.springframework.owncloud.service.impl.local.OwncloudLocalFileTestExecutionListener.java
@Override public void beforeTestClass(TestContext testContext) throws Exception { if (isTestClassAssignableFromOwncloudLocalFileTest(testContext)) { Class<?> testClass = testContext.getTestClass(); ActiveProfiles activeProfiles = AnnotationUtils.findAnnotation(testClass, ActiveProfiles.class); OwncloudProperties owncloudProperties = loadProperties(activeProfiles.value()); if (StringUtils.startsWith(owncloudProperties.getLocation(), "file:")) { copyResource(owncloudProperties); }//from w w w .j av a 2 s. c o m } }
From source file:software.coolstuff.springframework.owncloud.service.impl.local.OwncloudLocalResourceServiceImpl.java
private Path resolveLocation(URI relativeTo) { Path location = getRootLocationOfAuthenticatedUser(); if (relativeTo == null || StringUtils.isBlank(relativeTo.getPath())) { return location; }//from w w w.ja va 2 s .co m createDirectoryIfNotExists(location); String relativeToPath = relativeTo.getPath(); if (StringUtils.startsWith(relativeToPath, "/")) { relativeToPath = relativeToPath.substring(1); } return location.resolve(relativeToPath); }