Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implimenting namespace.

  • Loading branch information...
commit 97567df05bdf081d91ed7820c35a64d83b1fdbcb 1 parent d72ef19
@kawasima authored
View
1  README.ja.md
@@ -34,6 +34,5 @@ controllerタグでコントローラごとの設定をまとめることがで
## TODO
-* HotDeploy環境で動かない
* マッチングの最適化を実装する
View
14 src/main/java/net/unit8/sastruts/routing/RouteBuilder.java
@@ -132,6 +132,7 @@ public Options assignRouteOptions(LinkedList<Segment> segments, Options defaults
}
assignDefaultRouteOptions(segments);
+ ensureRequiredSegments(segments);
return routeRequirements;
}
@@ -148,6 +149,19 @@ private void assignDefaultRouteOptions(List<Segment> segments) {
}
}
}
+
+ private void ensureRequiredSegments(List<Segment> segments) {
+ boolean allowOptional = true;
+ for (int i=segments.size() - 1; i >= 0; i--) {
+ Segment segment = segments.get(i);
+ allowOptional = allowOptional && segment.isOptional();
+ if (!allowOptional && segment.isOptional()) {
+ segment.setOptional(false);
+ } else {
+ segment.setOptional(true);
+ }
+ }
+ }
public Route build(String path, Options options) {
if (path.charAt(0) != '/')
View
8 src/main/java/net/unit8/sastruts/routing/RouteLoader.java
@@ -20,6 +20,7 @@
public class RouteLoader extends DefaultHandler {
private String controller = null;
+ private String namespace = null;
private Locator locator;
private RouteSet routeSet;
@@ -58,6 +59,11 @@ public void startElement(String uri, String localName, String qName, Attributes
} else if (qName.equalsIgnoreCase("root")) {
Options options = processAttributes(attributes);
routeSet.addRoute("/", options);
+ } else if (qName.equalsIgnoreCase("namespace")) {
+ namespace = attributes.getValue("name");
+ if (StringUtil.isEmpty(namespace)) {
+ throw new SAXParseException("Can't find namespace's name.", locator);
+ }
}
}
@@ -65,6 +71,8 @@ public void startElement(String uri, String localName, String qName, Attributes
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("controller")) {
controller = null;
+ } else if (qName.equalsIgnoreCase("namespace")) {
+ namespace = null;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.