001 /**
002 * Copyright 2010-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.common.util.service;
017
018 import org.apache.commons.lang3.StringUtils;
019 import org.kuali.common.util.LocationUtils;
020 import org.kuali.common.util.spring.ToStringContext;
021 import org.slf4j.Logger;
022 import org.slf4j.LoggerFactory;
023 import org.springframework.util.Assert;
024
025 public class LocationService {
026 private static final Logger logger = LoggerFactory.getLogger(LocationService.class);
027
028 public String toString(ToStringContext context) {
029 Assert.notNull(context.getLocation());
030 String s = LocationUtils.toString(context.getLocation(), context.getEncoding());
031 if (context.isDelete()) {
032 boolean deleted = LocationUtils.deleteFileQuietly(context.getLocation());
033 if (!deleted) {
034 logger.warn("{} was not deleted", context.getLocation());
035 }
036 }
037 return context.isTrim() ? StringUtils.trim(s) : s;
038 }
039
040 }