List of usage examples for org.apache.commons.lang3 StringUtils removeStart
public static String removeStart(final String str, final String remove)
Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.
A null source string will return null .
From source file:org.xwiki.url.ExtendedURL.java
/** * @param url the URL being wrapped/*from www. j ava 2 s . c om*/ * @param ignorePrefix the ignore prefix must start with "/" (eg "/xwiki"). It can be empty or null too in which * case it's not used * @throws org.xwiki.resource.CreateResourceReferenceException if the passed URL is invalid which can happen if it * has incorrect encoding */ public ExtendedURL(URL url, String ignorePrefix) throws CreateResourceReferenceException { this.wrappedURL = url; // Convert the URL to a URI since URI performs correctly decoding. // Note that this means that this method only accepts valid URLs (with proper encoding) URI internalURI; try { internalURI = url.toURI(); } catch (URISyntaxException e) { throw new CreateResourceReferenceException(String.format("Invalid URL [%s]", url), e); } this.uri = internalURI; // Extract the path after the ignore prefix String rawPath = getURI().getRawPath(); if (!StringUtils.isEmpty(ignorePrefix)) { // Allow the passed ignore prefix to not contain the leading "/" String normalizedIgnorePrefix = ignorePrefix; if (!ignorePrefix.startsWith(URL_SEPARATOR)) { normalizedIgnorePrefix = URL_SEPARATOR + ignorePrefix; } if (!getURI().getPath().startsWith(normalizedIgnorePrefix)) { throw new CreateResourceReferenceException( String.format("URL Path [%s] doesn't start with [%s]", getURI().getPath(), ignorePrefix)); } rawPath = rawPath.substring(normalizedIgnorePrefix.length()); } // Remove leading "/" if any rawPath = StringUtils.removeStart(rawPath, URL_SEPARATOR); this.segments = extractPathSegments(rawPath); this.parameters = extractParameters(internalURI); }
From source file:org.xwiki.url.internal.ExtendedURL.java
/** * @param url the URL being wrapped/*from www . jav a 2 s . c o m*/ * @param ignorePrefix the ignore prefix must start with "/" (eg "/xwiki"). It can be empty or null too in which * case it's not used * @throws URLCreationException if the passed URL is invalid which can happen if it has incorrect encoding */ public ExtendedURL(URL url, String ignorePrefix) throws URLCreationException { // Convert the URL to a URI since URI performs correctly decoding. // Note that this means that this method only accepts valid URLs (with proper encoding) URI internalURI; try { internalURI = url.toURI(); } catch (URISyntaxException e) { throw new URLCreationException(String.format("Invalid URL [%s]", url), e); } this.uri = internalURI; String rawPath = getURI().getRawPath(); if (!StringUtils.isEmpty(ignorePrefix)) { // Allow the passed ignore prefix to not contain the leading "/" String normalizedIgnorePrefix = ignorePrefix; if (!ignorePrefix.startsWith(URL_SEPARATOR)) { normalizedIgnorePrefix = URL_SEPARATOR + ignorePrefix; } if (!getURI().getPath().startsWith(normalizedIgnorePrefix)) { throw new URLCreationException( String.format("URL Path [%s] doesn't start with [%s]", getURI().getPath(), ignorePrefix)); } // Note: We also remove the leading "/" after the context path. rawPath = rawPath.substring(ignorePrefix.length() + 1); } // Remove leading "/" if any rawPath = StringUtils.removeStart(rawPath, URL_SEPARATOR); this.segments = extractPathSegments(rawPath); }
From source file:org.xwiki.wiki.internal.descriptor.builder.DefaultWikiDescriptorBuilder.java
private String extractWikiId(XWikiDocument document) { String wikiId = null;/*from ww w .j a va 2s . c o m*/ String pageName = document.getDocumentReference().getName(); if (pageName.startsWith(VALID_PAGE_PREFIX)) { wikiId = StringUtils.removeStart(pageName, VALID_PAGE_PREFIX).toLowerCase(); } return wikiId; }
From source file:org.xwiki.wiki.internal.descriptor.document.DefaultWikiDescriptorDocumentHelper.java
@Override public String getWikiIdFromDocumentReference(DocumentReference descriptorDocumentReference) { String docName = descriptorDocumentReference.getName(); return StringUtils.removeStart(docName, "XWikiServer").toLowerCase(); }
From source file:org.xwiki.wiki.internal.descriptor.document.DefaultWikiDescriptorDocumentHelper.java
@Override public String getWikiIdFromDocumentFullname(String descriptorDocumentFullname) { return StringUtils.removeStart(descriptorDocumentFullname, "XWiki.XWikiServer").toLowerCase(); }
From source file:org.xwiki.wikistream.instance.internal.input.AbstractInstanceInputWikiStreamTest.java
protected void assertXML(String resource, InstanceInputProperties instanceProperties) throws WikiStreamException, IOException { if (instanceProperties == null) { instanceProperties = new InstanceInputProperties(); instanceProperties.setVerbose(false); }//from w ww . j a v a2 s. c om URL url = getClass().getResource("/" + resource + ".xml"); String expected = IOUtils.toString(url, "UTF-8"); expected = StringUtils.removeStart(expected, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"); InputWikiStream inputWikiStream = this.inputWikiStreamFactory.createInputWikiStream(instanceProperties); StringWriterOutputTarget writer = new StringWriterOutputTarget(); WikiXMLOutputProperties properties = new WikiXMLOutputProperties(); properties.setTarget(writer); OutputWikiStream outputWikiStream = this.xmlOutputWikiStreamFactory.createOutputWikiStream(properties); inputWikiStream.read(outputWikiStream.getFilter()); inputWikiStream.close(); outputWikiStream.close(); Assert.assertEquals(expected, writer.getBuffer().toString()); }
From source file:playRepository.GitBranch.java
public GitBranch(String name, GitCommit headCommit) { this.name = name; this.shortName = StringUtils.removeStart(name, Constants.R_HEADS); this.headCommit = headCommit; this.user = User.findByEmail(headCommit.getCommitterEmail()); }
From source file:spdxedit.license.LicenseExtractControl.java
@FXML void initialize() { assert txtLicenseName != null : "fx:id=\"txtLicenseName\" was not injected: check your FXML file 'extractLicenseDialog.fxml'."; assert txtLicenseText != null : "fx:id=\"txtLicenseText\" was not injected: check your FXML file 'extractLicenseDialog.fxml'."; assert initialLicenseId != null : "fx:id=\"initialLicenseId\" was not injected: check your FXML file 'extractLicenseDialog.fxml'."; txtLicenseName.setText(initialNameValue); txtLicenseText.setText(initialTextValue); txtLicenseId.setText(StringUtils.removeStart(initialLicenseId, "LicenseRef-")); }
From source file:spdxedit.SpdxLogic.java
private static SpdxFile newSpdxFile(Path file, String baseUri) throws IOException, InvalidSPDXAnalysisException { String checksum = getChecksumForFile(file); FileType[] fileTypes = SpdxLogic.getTypesForFile(file); String relativeFileUrl = StringUtils.removeStart(file.toUri().toString(), baseUri); return new SpdxFile(relativeFileUrl, fileTypes, checksum, new SpdxNoAssertionLicense(), new AnyLicenseInfo[] { new SpdxNoAssertionLicense() }, null, "NOASSERTION", null, null); }
From source file:syncthing.android.ui.sessionsettings.EditDevicePresenter.java
boolean validateAddress(String addr) { return StringUtils.startsWith(addr.trim(), "tcp://") && (SyncthingUtils.isIpAddressWithPort(StringUtils.removeStart(addr.trim(), "tcp://")) || SyncthingUtils.isDomainNameWithPort(StringUtils.removeStart(addr.trim(), "tcp://"))); }