Changeset 5341 for branches/release-0.13.x/pfixcore/src/org/pustefixframework/config/contextxmlservice/parser/ConditionParsingHandler.java
- Timestamp:
- 09/04/10 22:05:44 (21 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/release-0.13.x/pfixcore/src/org/pustefixframework/config/contextxmlservice/parser/ConditionParsingHandler.java
r3822 r5341 38 38 import de.schlund.pfixcore.auth.conditions.ConditionGroup; 39 39 import de.schlund.pfixcore.auth.conditions.HasRole; 40 import de.schlund.pfixcore.auth.conditions.NavigationCase; 40 41 import de.schlund.pfixcore.auth.conditions.Not; 41 42 import de.schlund.pfixcore.auth.conditions.Or; … … 47 48 */ 48 49 public class ConditionParsingHandler implements ParsingHandler { 49 50 public void handleNode(HandlerContext context) throws ParserException { 51 52 Element element = (Element)context.getNode(); 53 ParsingUtils.checkAttributes(element, null, new String[] {"name", "class", "ref", "id"}); 54 55 ContextXMLServletConfigImpl config = ParsingUtils.getSingleTopObject(ContextXMLServletConfigImpl.class, context); 56 50 51 private Condition findParentCondition(HandlerContext context) { 57 52 Iterator<Condition> parentConditions = context.getObjectTreeElement().getObjectsOfTypeFromTopTree(Condition.class).iterator(); 58 53 Condition parentCondition = null; 59 54 if(parentConditions.hasNext()) parentCondition = parentConditions.next(); 60 boolean inCondition = ( parentCondition != null); 61 boolean inPageRequest = isInPageRequest(element); 62 63 String name = element.getNodeName(); 64 Condition condition = null; 55 return parentCondition; 56 } 57 58 public void handleNode(HandlerContext context) throws ParserException { 59 Condition condition = parseCondition(context); 60 61 //assemble the parent element by setting or adding the parsed condition 62 Condition parentCondition = findParentCondition(context); 63 if(parentCondition != null) { 64 if (parentCondition instanceof NavigationCase) { 65 ((NavigationCase) parentCondition).setCondition(condition); 66 } else if (parentCondition instanceof AuthConstraint) { 67 AuthConstraintImpl authConstraint = (AuthConstraintImpl) parentCondition; 68 if (condition instanceof NavigationCase) { 69 authConstraint.addNavigationCase(((NavigationCase) condition)); 70 } else { 71 authConstraint.setCondition(condition); 72 } 73 } else if (parentCondition instanceof ConditionGroup) { 74 ((ConditionGroup) parentCondition).add(condition); 75 } else if (parentCondition instanceof Not) { 76 ((Not) parentCondition).set(condition); 77 } else throw new ParserException("Illegal object: " + parentCondition.getClass().getName()); 78 } 79 80 context.getObjectTreeElement().addObject(condition); 81 } 82 83 private ContextXMLServletConfigImpl getConfig(HandlerContext context) throws ParserException { 84 return ParsingUtils.getSingleTopObject(ContextXMLServletConfigImpl.class, context); 85 } 86 87 private Condition parseCondition(HandlerContext context) throws ParserException { 88 89 Element element = (Element)context.getNode(); 90 ParsingUtils.checkAttributes(element, null, new String[] {"page", "name", "class", "ref", "id"}); 91 92 String name = element.getTagName(); 93 94 Condition condition; 65 95 if (name.equals("or")) { 66 96 condition = new Or(); … … 70 100 condition = new Not(); 71 101 } else if (name.equals("hasrole")) { 102 ContextXMLServletConfigImpl config = getConfig(context); 72 103 String roleName = element.getAttribute("name").trim(); 73 104 if(roleName.equals("")) throw new ParserException("Element 'hasrole' requires 'name' attribute value."); … … 76 107 if (role == null) throw new ParserException("Condition hasrole references unknown role: " + roleName); 77 108 } else if (name.equals("condition")) { 78 if ( !inCondition) {109 if (findParentCondition(context) == null) { 79 110 String id = element.getAttribute("id").trim(); 80 111 condition = createCondition(element); 112 ContextXMLServletConfigImpl config = getConfig(context); 81 113 config.getContextConfig().addCondition(id, condition); 82 114 } else { 83 115 String ref = element.getAttribute("ref").trim(); 84 116 if (ref != null) { 117 ContextXMLServletConfigImpl config = ParsingUtils.getSingleTopObject(ContextXMLServletConfigImpl.class, context); 85 118 condition = config.getContextConfig().getCondition(ref); 86 119 if (condition == null) throw new ParserException("Condition reference not found: " + ref); … … 92 125 String ref = element.getAttribute("ref").trim(); 93 126 if(ref.equals("")) throw new ParserException("Nested authconstraint requires 'ref' attribute."); 94 if(inPageRequest) { 127 if(isInPageRequest(element)) { 128 ContextXMLServletConfigImpl config = getConfig(context); 95 129 AuthConstraint constraint = config.getContextConfig().getAuthConstraint(ref); 96 130 if(constraint == null) throw new ParserException("Referenced authconstraint not found: "+ref); … … 99 133 condition = new AuthConstraintRef(ref); 100 134 } 101 } else throw new ParserException("Unsupported condition: " + name); 102 103 if(inCondition) { 104 if (parentCondition instanceof AuthConstraint) { 105 ((AuthConstraintImpl) parentCondition).setCondition(condition); 106 } else if (parentCondition instanceof ConditionGroup) { 107 ((ConditionGroup) parentCondition).add(condition); 108 } else if (parentCondition instanceof Not) { 109 ((Not) parentCondition).set(condition); 110 } else throw new ParserException("Illegal object: " + parentCondition.getClass().getName()); 135 } else if (name.equals("navigateTo")) { 136 String page = element.getAttribute("page").trim(); 137 if (page.equals("")) { 138 throw new ParserException("Element navigation requires 'page' attribute."); 139 } 140 NavigationCase navigationCase = new NavigationCase(page); 141 condition = navigationCase; 142 } else { 143 throw new ParserException("Unsupported condition: " + name); 111 144 } 112 145 113 146 PropertyParsingUtils.setProperties(condition, element); 114 115 context.getObjectTreeElement().addObject(condition);147 148 return condition; 116 149 } 117 150 118 151 private Condition createCondition(Element element) throws ParserException { 119 152 String className = element.getAttribute("class").trim(); … … 128 161 } 129 162 } 130 163 131 164 private boolean isInPageRequest(Element element) { 132 165 Node parent = element.getParentNode();
