
org.eclipse.dirigible.repository.api.ResourceUtil Maven / Gradle / Ivy
/**
* Copyright (c) 2010-2018 SAP and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* SAP - initial API and implementation
*/
package org.eclipse.dirigible.repository.api;
/**
* Utility class for handling Resource objects.
*/
public final class ResourceUtil {
/**
* Returns the extension of the resource name if there is such, otherwise
* returns null
. If there is a dot but there is no extension,
* then this method returns the empty string.
*
* For example:
*
* - request.xml yields "xml"
* - page.html yields "html"
* - sample. yields
""
* - sample yields
null
*
*
* @param resource
* resource who's name extension will be returned.
* @return the extension of a resource name
*/
public static String getResourceExtension(IResource resource) {
final String name = resource.getName();
final int lastDotIndex = name.lastIndexOf('.');
if (lastDotIndex == -1) {
return null;
}
return name.substring(lastDotIndex + 1);
}
/**
* Returns the name of a resource without the extension.
*
* For example:
*
* - request.xml yields "request"
* - page.html yields "page"
* - sample. yields
"sample"
* - sample yields
"sample"
*
*
* @param resource
* resource who's pure name will be returned.
* @return the name of a resource without the extension at the end.
*/
public static String getResourcePureName(IResource resource) {
final String name = resource.getName();
final int lastDotIndex = name.lastIndexOf('.');
if (lastDotIndex == -1) {
return name;
}
return name.substring(0, lastDotIndex);
}
/**
* Instantiates a new resource util.
*/
/*
* Disable instantiation
*/
private ResourceUtil() {
super();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy