Java tutorial
/* Copyright c 2005-2012. * Licensed under GNU LESSER General Public License, Version 3. * http://www.gnu.org/licenses */ package org.beangle.struts2.convention.route.impl; import org.apache.commons.lang.StringUtils; import org.beangle.commons.lang.StrUtils; import org.beangle.struts2.convention.Constants; import org.beangle.struts2.convention.route.Action; import org.beangle.struts2.convention.route.ActionBuilder; import org.beangle.struts2.convention.route.Profile; import org.beangle.struts2.convention.route.ProfileService; import com.opensymphony.xwork2.inject.Inject; public class DefaultActionBuilder implements ActionBuilder { private ProfileService profileService; /** * ?classprofilectl/action????<br> * profileuriStyle,????????<br> * ???.?URI?????<br> * ??URL,/ * * @param clazz * @return */ public Action build(String className) { Profile profile = profileService.getProfile(className); Action action = new Action(); StringBuilder sb = new StringBuilder(); // namespace sb.append(profile.getUriPath()); if (Constants.SHORT_URI.equals(profile.getUriPathStyle())) { String simpleName = className.substring(className.lastIndexOf('.') + 1); sb.append(StringUtils.uncapitalize( simpleName.substring(0, simpleName.length() - profile.getActionSuffix().length()))); } else if (Constants.SIMPLE_URI.equals(profile.getUriPathStyle())) { sb.append(profile.getInfix(className)); } else if (Constants.SEO_URI.equals(profile.getUriPathStyle())) { sb.append(StrUtils.unCamel(profile.getInfix(className))); } else { throw new RuntimeException("unsupported uri style " + profile.getUriPathStyle()); } action.path(sb.toString()).method(profile.getDefaultMethod()).extention(profile.getUriExtension()); return action; } @Inject public void setProfileService(ProfileService profileService) { this.profileService = profileService; } public ProfileService getProfileService() { return profileService; } }