コード例 #1
0
ファイル: Router.java プロジェクト: heaphy/playframework
 /**
  * Parse the routes file. This is called at startup.
  *
  * @param prefix The prefix that the path of all routes in this route file start with. This prefix
  *     should not end with a '/' character.
  */
 public static void load(String prefix) {
   routes.clear();
   parse(Play.routes, prefix);
   lastLoading = System.currentTimeMillis();
   // Plugins
   Play.pluginCollection.onRoutesLoaded();
 }
コード例 #2
0
ファイル: Router.java プロジェクト: heaphy/playframework
 /**
  * Parse a route file. If an action starts with <i>"plugin:name"</i>, replace that route by the
  * ones declared in the plugin route file denoted by that <i>name</i>, if found.
  *
  * @param routeFile
  * @param prefix The prefix that the path of all routes in this route file start with. This prefix
  *     should not end with a '/' character.
  */
 static void parse(VirtualFile routeFile, String prefix) {
   String fileAbsolutePath = routeFile.getRealFile().getAbsolutePath();
   String content = routeFile.contentAsString();
   if (content.indexOf("${") > -1 || content.indexOf("#{") > -1 || content.indexOf("%{") > -1) {
     // Mutable map needs to be passed in.
     content = TemplateLoader.load(routeFile).render(new HashMap<String, Object>(16));
   }
   parse(content, prefix, fileAbsolutePath);
 }
コード例 #3
0
ファイル: Router.java プロジェクト: heaphy/playframework
 static void parse(String content, String prefix, String fileAbsolutePath) {
   int lineNumber = 0;
   for (String line : content.split("\n")) {
     lineNumber++;
     line = line.trim().replaceAll("\\s+", " ");
     if (line.length() == 0 || line.startsWith("#")) {
       continue;
     }
     Matcher matcher = routePattern.matcher(line);
     if (matcher.matches()) {
       String action = matcher.group("action");
       // module:
       if (action.startsWith("module:")) {
         String moduleName = action.substring("module:".length());
         String newPrefix = prefix + matcher.group("path");
         if (newPrefix.length() > 1 && newPrefix.endsWith("/")) {
           newPrefix = newPrefix.substring(0, newPrefix.length() - 1);
         }
         if (moduleName.equals("*")) {
           for (String p : Play.modulesRoutes.keySet()) {
             parse(Play.modulesRoutes.get(p), newPrefix + p);
           }
         } else if (Play.modulesRoutes.containsKey(moduleName)) {
           parse(Play.modulesRoutes.get(moduleName), newPrefix);
         } else {
           Logger.error("Cannot include routes for module %s (not found)", moduleName);
         }
       } else {
         String method = matcher.group("method");
         String path = prefix + matcher.group("path");
         String params = matcher.group("params");
         String headers = matcher.group("headers");
         appendRoute(method, path, action, params, headers, fileAbsolutePath, lineNumber);
       }
     } else {
       Logger.error("Invalid route definition : %s", line);
     }
   }
 }