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 */ 017package org.apache.camel.util; 018 019public final class LocationHelper { 020 021 private LocationHelper() { 022 } 023 024 /** 025 * The location as human-readable with the given key from the properties 026 * 027 * @param properties the properties 028 * @param key the key 029 * @return the location or empty if not possible to resolve a location. 030 */ 031 public static String locationSummary(OrderedLocationProperties properties, String key) { 032 String loc = properties.getLocation(key); 033 if (loc == null) { 034 loc = ""; 035 } 036 // remove scheme to make it shorter 037 if (loc.contains(":")) { 038 loc = StringHelper.after(loc, ":"); 039 } 040 // strip paths so location is only the name 041 loc = FileUtil.stripPath(loc); 042 // clip long name 043 if (loc.length() > 28) { 044 int pos = loc.length() - 28; 045 loc = loc.substring(pos); 046 } 047 // let us have human friendly locations 048 if ("initial".equals(loc) || "override".equals(loc)) { 049 loc = "camel-main"; 050 } else if ("SYS".equals(loc)) { 051 loc = "JVM System Property"; 052 } else if ("ENV".equals(loc)) { 053 loc = "OS Environment Variable"; 054 } else if ("arguments".equals(loc) || "CLI".equals(loc)) { 055 loc = "Command Line"; 056 } 057 loc = "[" + loc + "]"; 058 loc = String.format("%-30s", loc); 059 return loc; 060 } 061 062}