Java tutorial
/* * This file is part of Dorado 7.x (http://dorado7.bsdn.org). * * Copyright (c) 2002-2012 BSTEK Corp. All rights reserved. * * This file is dual-licensed under the AGPLv3 (http://www.gnu.org/licenses/agpl-3.0.html) * and BSDN commercial (http://www.bsdn.org/licenses) licenses. * * If you are unsure which license is appropriate for your use, please contact the sales department * at http://www.bstek.com/contact. */ package com.bstek.dorado.core.io; import java.io.IOException; import java.util.LinkedHashSet; import java.util.Set; import org.apache.commons.lang.StringUtils; import com.bstek.dorado.core.Context; /** * Resource * * @author Benny Bao (mailto:benny.bao@bstek.com) * @since Feb 19, 2007 */ public abstract class ResourceUtils { private ResourceUtils() { } /** * ???? '/' */ public static String concatPath(String path1, String path2) { String result; if (StringUtils.isEmpty(path1)) { result = path2; } else { result = path1; if (StringUtils.isNotEmpty(path2)) { char c1 = path1.charAt(path1.length() - 1), c2 = path2.charAt(0); boolean b1 = (c1 == '\\' || c1 == '/'), b2 = (c2 == '\\' || c2 == '/'); if (!b1 && !b2) { result += '/'; } else if (b1 && b2) { path2 = path2.substring(1); } result += path2; } } return result; } /** * ?????? * * @param resourceLocations * ? * @return ???? * @throws IOException */ public static Set<Resource> getResourceSet(String[] resourceLocations) throws IOException { Context context = Context.getCurrent(); Set<Resource> resourceSet = new LinkedHashSet<Resource>(); for (String resourceLocation : resourceLocations) { Resource[] resourceArray = context.getResources(resourceLocation); for (Resource resource : resourceArray) { if (!resourceSet.contains(resource)) { resourceSet.add(resource); } } } return resourceSet; } /** * ?????? * * @param resourceLocation * ? * @return ???? * @throws IOException */ public static Set<Resource> getResourceSet(String resourceLocation) throws IOException { return getResourceSet(new String[] { resourceLocation }); } /** * ?????? * * @param resourceLocation * ? * @return ??? * @throws IOException */ public static Resource[] getResources(String resourceLocation) throws IOException { return getResources(new String[] { resourceLocation }); } /** * ?????? * * @param resourceLocations * ? * @return ??? * @throws IOException */ public static Resource[] getResources(String[] resourceLocations) throws IOException { Set<Resource> resourceSet = getResourceSet(resourceLocations); Resource[] resources = new Resource[resourceSet.size()]; resourceSet.toArray(resources); return resources; } /** * ?????? * * @param resourceLocation * ? * @return ??? * @throws IOException */ public static Resource getResource(String resourceLocation) throws IOException { Resource resource = null; Resource[] resources = getResources(resourceLocation); if (resources.length > 0) { resource = resources[0]; } return resource; } }