001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.jci.utils;
019:
020: import java.io.File;
021:
022: /**
023: * Mainly common path manipultation helper methods
024: * NOT FOR USE OUTSIDE OF JCI
025: *
026: * @author tcurdt
027: */
028: public final class ConversionUtils {
029:
030: /**
031: * Please do not use - internal
032: * org/my/Class.xxx -> org.my.Class
033: */
034: public static String convertResourceToClassName(
035: final String pResourceName) {
036: return ConversionUtils.stripExtension(pResourceName).replace(
037: '/', '.');
038: }
039:
040: /**
041: * Please do not use - internal
042: * org.my.Class -> org/my/Class.class
043: */
044: public static String convertClassToResourcePath(final String pName) {
045: return pName.replace('.', '/') + ".class";
046: }
047:
048: /**
049: * Please do not use - internal
050: * org/my/Class.xxx -> org/my/Class
051: */
052: public static String stripExtension(final String pResourceName) {
053: final int i = pResourceName.lastIndexOf('.');
054: if (i < 0) {
055: return pResourceName;
056: }
057: final String withoutExtension = pResourceName.substring(0, i);
058: return withoutExtension;
059: }
060:
061: public static String toJavaCasing(final String pName) {
062: final char[] name = pName.toLowerCase().toCharArray();
063: name[0] = Character.toUpperCase(name[0]);
064: return new String(name);
065: }
066:
067: /*
068: public static String clazzName( final File base, final File file ) {
069: final int rootLength = base.getAbsolutePath().length();
070: final String absFileName = file.getAbsolutePath();
071: final int p = absFileName.lastIndexOf('.');
072: final String relFileName = absFileName.substring(rootLength + 1, p);
073: final String clazzName = relFileName.replace(File.separatorChar, '.');
074: return clazzName;
075: }
076: */
077: public static String relative(final File base, final File file) {
078: final int rootLength = base.getAbsolutePath().length();
079: final String absFileName = file.getAbsolutePath();
080: final String relFileName = absFileName
081: .substring(rootLength + 1);
082: return relFileName;
083: }
084:
085: /**
086: * a/b/c.java -> a/b/c.java
087: * a\b\c.java -> a/b/c.java
088: * @param pFileName
089: * @return
090: */
091: public static String getResourceNameFromFileName(
092: final String pFileName) {
093: if ('/' == File.separatorChar) {
094: return pFileName;
095: }
096:
097: return pFileName.replace(File.separatorChar, '/');
098: }
099:
100: }
|