List of usage examples for org.dom4j Element attributeIterator
Iterator<Attribute> attributeIterator();
From source file:org.codehaus.aspectwerkz.xmldef.definition.DocumentParser.java
License:Open Source License
/** * Parses the <tt>aspect</tt> elements. * * @param root the root element//from w w w . ja v a 2 s. c o m * @param definition the definition object * @param packageName the package name * @return flag that says if we have a definition of this kind or not */ private static boolean parseAspectElements(final Element root, final AspectWerkzDefinitionImpl definition, final String packageName) { // register the pointcuts before parsing the rest of the aspect // to be able to resolve all dependencies correctly for (Iterator it1 = root.elementIterator("aspect"); it1.hasNext();) { final Element aspect = (Element) it1.next(); String aspectName = null; for (Iterator it2 = aspect.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); final String name = attribute.getName().trim(); final String value = attribute.getValue().trim(); if (name.equals("name")) { aspectName = value; continue; } else if (name.equals("extends")) { aspectName = value; break; } } // if the aspect has an abstract aspect register the pointcuts under the abstract aspects name registerPointcuts(aspect, aspectName, packageName); } for (Iterator it1 = root.elementIterator("abstract-aspect"); it1.hasNext();) { final Element aspect = (Element) it1.next(); String aspectName = null; for (Iterator it2 = aspect.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); final String name = attribute.getName().trim(); final String value = attribute.getValue().trim(); if (name.equals("name")) { aspectName = value; break; } } registerPointcuts(aspect, aspectName, packageName); } // parse the aspect with its pointcut-def, bind-advice and bind-introduction rules boolean hasDef = false; for (Iterator it1 = root.elementIterator("aspect"); it1.hasNext();) { final AspectDefinition aspectDef = new AspectDefinition(); final Element aspect = (Element) it1.next(); for (Iterator it2 = aspect.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); final String name = attribute.getName().trim(); final String value = attribute.getValue().trim(); if (name.equals("name")) { aspectDef.setName(value); } else if (name.equals("extends")) { aspectDef.setExtends(value); continue; } } parsePointcutElements(aspect, aspectDef, packageName); parseControllerElements(aspect, aspectDef); parseBindIntroductionElements(aspect, aspectDef, packageName); parseBindAdviceElements(aspect, aspectDef, packageName); definition.addAspect(aspectDef); hasDef = true; } for (Iterator it1 = root.elementIterator("abstract-aspect"); it1.hasNext();) { final AspectDefinition aspectDef = new AspectDefinition(); aspectDef.setAbstract(true); final Element aspect = (Element) it1.next(); for (Iterator it2 = aspect.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); final String name = attribute.getName().trim(); final String value = attribute.getValue().trim(); if (name.equals("name")) { aspectDef.setName(value); } } parsePointcutElements(aspect, aspectDef, packageName); parseControllerElements(aspect, aspectDef); parseBindIntroductionElements(aspect, aspectDef, packageName); parseBindAdviceElements(aspect, aspectDef, packageName); definition.addAbstractAspect(aspectDef); hasDef = true; } for (Iterator it = definition.getAspectDefinitions().iterator(); it.hasNext();) { AspectDefinition aspectDef = (AspectDefinition) it.next(); handleAbstractAspectDependencies(aspectDef, definition); } return hasDef; }
From source file:org.codehaus.aspectwerkz.xmldef.definition.DocumentParser.java
License:Open Source License
/** * Parses and registers the pointcut elements. * * @param aspect the aspect element/*from w w w . j a v a 2 s . c o m*/ * @param aspectName the name of the aspect * @param packageName the name of the package */ private static void registerPointcuts(final Element aspect, final String aspectName, final String packageName) { for (Iterator it2 = aspect.elementIterator(); it2.hasNext();) { final Element nestedAdviceElement = (Element) it2.next(); if (nestedAdviceElement.getName().trim().equals("pointcut-def")) { String pointcutName = null; String expression = null; PointcutType pointcutType = null; try { for (Iterator it3 = nestedAdviceElement.attributeIterator(); it3.hasNext();) { Attribute attribute = (Attribute) it3.next(); final String name = attribute.getName().trim(); final String value = attribute.getValue().trim(); if (name.equals("name")) { pointcutName = value; } else if (name.equals("type")) { if (value.equalsIgnoreCase(METHOD)) { pointcutType = PointcutType.EXECUTION; expression = PatternFactory.createMethodPattern( nestedAdviceElement.attributeValue("pattern"), packageName); } else if (value.equalsIgnoreCase(CFLOW)) { pointcutType = PointcutType.CFLOW; expression = PatternFactory.createCallPattern( nestedAdviceElement.attributeValue("pattern"), packageName); } else if (value.equalsIgnoreCase(SET_FIELD)) { pointcutType = PointcutType.SET; expression = PatternFactory.createMethodPattern( nestedAdviceElement.attributeValue("pattern"), packageName); } else if (value.equalsIgnoreCase(GET_FIELD)) { pointcutType = PointcutType.GET; expression = PatternFactory.createFieldPattern( nestedAdviceElement.attributeValue("pattern"), packageName); } else if (value.equalsIgnoreCase(THROWS)) { pointcutType = PointcutType.THROWS; expression = PatternFactory.createThrowsPattern( nestedAdviceElement.attributeValue("pattern"), packageName); } else if (value.equalsIgnoreCase(CALLER_SIDE)) { pointcutType = PointcutType.CALL; expression = PatternFactory.createCallPattern( nestedAdviceElement.attributeValue("pattern"), packageName); } else if (value.equalsIgnoreCase(CLASS)) { pointcutType = PointcutType.CLASS; expression = PatternFactory.createClassPattern( nestedAdviceElement.attributeValue("pattern"), packageName); } } } // create and register the expression // ExpressionTemplate expressionTemplate = // Expression.createExpressionTemplate( // aspectName, // expression, // packageName, // pointcutName, // pointcutType // ); // Expression.registerExpressionTemplate(expressionTemplate); ExpressionNamespace space = ExpressionNamespace.getExpressionNamespace(aspectName); space.registerExpression(expression, packageName, pointcutName, pointcutType); } catch (Exception e) { throw new WrappedRuntimeException(e); } } } }
From source file:org.codehaus.aspectwerkz.xmldef.definition.DocumentParser.java
License:Open Source License
/** * Parses the pointcut elements./*from w ww . j av a 2 s . c o m*/ * * @TODO does not handle packages correctly * * @param aspect the aspect element * @param aspectDef the aspect definition * @param packageName the name of the package */ private static void parsePointcutElements(final Element aspect, final AspectDefinition aspectDef, final String packageName) { for (Iterator it2 = aspect.elementIterator(); it2.hasNext();) { final Element nestedAdviceElement = (Element) it2.next(); if (nestedAdviceElement.getName().trim().equals("pointcut-def")) { try { final PointcutDefinition pointcutDef = new PointcutDefinition(); for (Iterator it3 = nestedAdviceElement.attributeIterator(); it3.hasNext();) { Attribute attribute = (Attribute) it3.next(); final String name = attribute.getName().trim(); final String value = attribute.getValue().trim(); if (name.equals("name")) { pointcutDef.setName(value); } else if (name.equals("type")) { PointcutType type = null; String expression = nestedAdviceElement.attributeValue("pattern"); if (expression == null || expression.length() == 0) expression = nestedAdviceElement.attributeValue("expression"); if (value.equalsIgnoreCase(METHOD)) { type = PointcutType.EXECUTION; pointcutDef .setExpression(PatternFactory.createMethodPattern(expression, packageName)); } else if (value.equalsIgnoreCase(CFLOW)) { //needed during AttributeC merge type = PointcutType.CFLOW; pointcutDef .setExpression(PatternFactory.createMethodPattern(expression, packageName)); } else if (value.equalsIgnoreCase(SET_FIELD)) { type = PointcutType.SET; pointcutDef .setExpression(PatternFactory.createFieldPattern(expression, packageName)); } else if (value.equalsIgnoreCase(GET_FIELD)) { type = PointcutType.GET; pointcutDef .setExpression(PatternFactory.createFieldPattern(expression, packageName)); } else if (value.equalsIgnoreCase(THROWS)) { type = PointcutType.THROWS; pointcutDef .setExpression(PatternFactory.createThrowsPattern(expression, packageName)); } else if (value.equalsIgnoreCase(CALLER_SIDE)) { type = PointcutType.CALL; pointcutDef .setExpression(PatternFactory.createCallPattern(expression, packageName)); } else if (value.equalsIgnoreCase(CLASS)) { type = PointcutType.CLASS; pointcutDef .setExpression(PatternFactory.createClassPattern(expression, packageName)); } pointcutDef.setType(type); } else if (name.equals("non-reentrant")) { pointcutDef.setNonReentrant(value); } } aspectDef.addPointcutDef(pointcutDef); } catch (Exception e) { throw new WrappedRuntimeException(e); } } } }
From source file:org.codehaus.aspectwerkz.xmldef.definition.DocumentParser.java
License:Open Source License
/** * Parses the introduce elements./* w w w .jav a 2 s. c o m*/ * * @param aspect the aspect element * @param aspectDef the aspect definition * @param packageName the name of the package */ private static void parseBindIntroductionElements(final Element aspect, final AspectDefinition aspectDef, final String packageName) { for (Iterator it2 = aspect.elementIterator(); it2.hasNext();) { final Element nestedAdviceElement = (Element) it2.next(); if (nestedAdviceElement.getName().trim().equals("bind-introduction")) { try { final BindIntroductionRule bindIntroductionRule = new BindIntroductionRule(); for (Iterator it3 = nestedAdviceElement.attributeIterator(); it3.hasNext();) { Attribute attribute = (Attribute) it3.next(); final String name = attribute.getName().trim(); final String value = attribute.getValue().trim(); if (name.equals("class")) { bindIntroductionRule.setExpression( // Expression.createRootExpression( // aspectDef.getName(), // packageName + value, // PointcutType.CLASS // needed for anonymous expressions // )); ExpressionNamespace.getExpressionNamespace(aspectDef.getName()) .createExpression(packageName + value, PointcutType.CLASS)); } else if (name.equals("introduction-ref")) { bindIntroductionRule.addIntroductionRef(value); } } parseIntroductionWeavingRuleNestedElements(nestedAdviceElement, bindIntroductionRule); aspectDef.addBindIntroductionRule(bindIntroductionRule); } catch (Exception e) { throw new DefinitionException("introduction definition in aspect " + aspectDef.getName() + " is not well-formed: " + e.toString()); } } } }
From source file:org.codehaus.aspectwerkz.xmldef.definition.DocumentParser.java
License:Open Source License
/** * Parses the advise elements.//from w w w . j a va 2 s . c o m * * @TODO: how to handle cflow? * * @param aspect the aspect element * @param aspectDef the aspect definition * @param packageName the name of the package */ private static void parseBindAdviceElements(final Element aspect, final AspectDefinition aspectDef, final String packageName) { for (Iterator it2 = aspect.elementIterator(); it2.hasNext();) { final Element nestedAdviceElement = (Element) it2.next(); if (nestedAdviceElement.getName().trim().equals("bind-advice")) { try { final BindAdviceRule bindAdviceRule = new BindAdviceRule(); String pointcutExpression = ""; for (Iterator it3 = nestedAdviceElement.attributeIterator(); it3.hasNext();) { Attribute attribute = (Attribute) it3.next(); final String name = attribute.getName().trim(); final String value = attribute.getValue().trim(); if (name.equals("cflow")) { // support for old system cflow=.. pc=.. pointcutExpression += " IN (" + value + ")"; // bindAdviceRule.setCflowExpression( // Expression.createCflowExpression( // aspectDef.getName(), // aspectDef.getPointcutDef(value).getExpression(), // packageName, // value) // ); } else if (name.equals("pointcut") || name.equals("expression")) { pointcutExpression = value + pointcutExpression; // bindAdviceRule.setExpression( // Expression.createRootExpression( // aspectDef.getName(), // value // )); } else if (name.equals("advice-ref")) { bindAdviceRule.addAdviceRef(value); } } // add binding here once cflow expr has been assembled (@since jjtree) ExpressionNamespace space = ExpressionNamespace.getExpressionNamespace(aspectDef.getName()); bindAdviceRule.setExpression(space.createExpression(pointcutExpression)); parseAdviceWeavingRuleNestedElements(nestedAdviceElement, bindAdviceRule); aspectDef.addBindAdviceRule(bindAdviceRule); } catch (Exception e) { e.printStackTrace(); throw new DefinitionException("advice definition in aspect " + aspectDef.getName() + " is not well-formed: " + e.toString()); } } } }
From source file:org.codehaus.aspectwerkz.xmldef.definition.DocumentParser.java
License:Open Source License
/** * Parses the <tt>advices</tt> elements. * * @param root the root element/*w ww. j av a 2 s. co m*/ * @param definition the definition object * @return flag that says if we have a definition of this kind or not */ private static boolean parseAdviceStackElements(final Element root, final AspectWerkzDefinitionImpl definition) { boolean hasDef = false; for (Iterator it1 = root.elementIterator("advices-def"); it1.hasNext();) { final AdviceStackDefinition adviceStackDef = new AdviceStackDefinition(); Element adviceStack = (Element) it1.next(); for (Iterator it2 = adviceStack.attributeIterator(); it2.hasNext();) { Attribute attribute = (Attribute) it2.next(); final String name = attribute.getName().trim(); final String value = attribute.getValue().trim(); if (name.equals("name")) { adviceStackDef.setName(value); } } for (Iterator it2 = adviceStack.elementIterator(); it2.hasNext();) { Element nestedElement = (Element) it2.next(); if (nestedElement.getName().trim().equals("advice-ref")) { adviceStackDef.addAdvice(nestedElement.attributeValue("name")); } } definition.addAdviceStack(adviceStackDef); hasDef = true; } return hasDef; }
From source file:org.infoglue.deliver.controllers.kernel.impl.simple.PageEditorHelper.java
License:Open Source License
/** * This method returns a value for a property if it's set. The value is collected in the * properties for the page.//w w w . jav a 2s. co m */ private String getComponentPropertyValue(Integer componentId, String name, Integer siteNodeId, Integer languageId, Integer contentId, Locale locale, Database db, InfoGluePrincipal principal, ComponentProperty componentProperty) throws Exception { String value = componentProperty.getDefaultValue(); Timer timer = new Timer(); timer.setActive(false); Document document = getPageComponentsDOM4JDocument(db, siteNodeId, languageId, contentId, principal); String componentXPath = "//component[@id=" + componentId + "]/properties/property[@name='" + name + "']"; List anl = document.selectNodes(componentXPath); Iterator anlIterator = anl.iterator(); while (anlIterator.hasNext()) { Element property = (Element) anlIterator.next(); String id = property.attributeValue("type"); String path = property.attributeValue("path"); if (property.attribute("path_" + locale.getLanguage()) != null) path = property.attributeValue("path_" + locale.getLanguage()); else if (!componentProperty.getAllowLanguageVariations()) { Iterator attributesIterator = property.attributeIterator(); while (attributesIterator.hasNext()) { DefaultAttribute attribute = (DefaultAttribute) attributesIterator.next(); if (attribute.getName().startsWith("path_")) { path = attribute.getValue(); } } } value = path; if (value != null) value = value.replaceAll("igbr", separator); } return value; }
From source file:org.infoglue.deliver.invokers.AjaxDecoratedComponentBasedHTMLPageInvoker.java
License:Open Source License
/** * This method returns a value for a property if it's set. The value is collected in the * properties for the page.// w ww .j ava 2s.co m */ private String getComponentPropertyValue(Integer componentId, String name, boolean allowLanguageVariations) throws Exception { String value = "Undefined"; Timer timer = new Timer(); timer.setActive(false); Integer siteNodeId = null; Integer languageId = null; if (this.getRequest().getParameter("siteNodeId") != null && this.getRequest().getParameter("siteNodeId").length() > 0) siteNodeId = new Integer(this.getRequest().getParameter("siteNodeId")); else { siteNodeId = this.getTemplateController().getDeliveryContext().getSiteNodeId(); } NodeDeliveryController nodeDeliveryController = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, null); if (this.getRequest().getParameter("languageId") != null && this.getRequest().getParameter("languageId").length() > 0) { languageId = new Integer(this.getRequest().getParameter("languageId")); if (!languageId.equals(this.getTemplateController().getDeliveryContext().getLanguageId())) { languageId = LanguageDeliveryController.getLanguageDeliveryController() .getMasterLanguageForSiteNodeWithValityCheck(getDatabase(), nodeDeliveryController, siteNodeId) .getId(); } } else { languageId = LanguageDeliveryController.getLanguageDeliveryController() .getMasterLanguageForSiteNodeWithValityCheck(getDatabase(), nodeDeliveryController, siteNodeId) .getId(); } Locale locale = LanguageDeliveryController.getLanguageDeliveryController().getLocaleWithId(getDatabase(), languageId); Integer contentId = new Integer(-1); if (this.getRequest().getParameter("contentId") != null && this.getRequest().getParameter("contentId").length() > 0) contentId = new Integer(this.getRequest().getParameter("contentId")); Document document = getPageComponentsDOM4JDocument(getDatabase(), this.getTemplateController(), siteNodeId, languageId, contentId); String componentXPath = "//component[@id=" + componentId + "]/properties/property[@name='" + name + "']"; //logger.info("componentXPath:" + componentXPath); List anl = document.selectNodes(componentXPath); Iterator anlIterator = anl.iterator(); while (anlIterator.hasNext()) { Element property = (Element) anlIterator.next(); String id = property.attributeValue("type"); String path = property.attributeValue("path"); if (property.attribute("path_" + locale.getLanguage()) != null) path = property.attributeValue("path_" + locale.getLanguage()); else if (!allowLanguageVariations) { Iterator attributesIterator = property.attributeIterator(); while (attributesIterator.hasNext()) { DefaultAttribute attribute = (DefaultAttribute) attributesIterator.next(); if (attribute.getName().startsWith("path_")) { path = attribute.getValue(); } } } value = path; } return value; }
From source file:org.infoglue.deliver.invokers.AjaxDecoratedComponentBasedHTMLPageInvoker.java
License:Open Source License
/** * This method returns a value for a property if it's set. The value is collected in the * properties for the page.// www .ja v a 2s. co m */ private String getComponentPropertyValue(Integer componentId, String name, TemplateController templateController, boolean allowLanguageVariations) throws Exception { String value = "Undefined"; Timer timer = new Timer(); timer.setActive(false); Integer languageId = null; if (this.getRequest() != null && this.getRequest().getParameter("languageId") != null && this.getRequest().getParameter("languageId").length() > 0) languageId = new Integer(this.getRequest().getParameter("languageId")); else languageId = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForSiteNode( templateController.getDatabase(), templateController.getSiteNodeId()).getId(); Locale locale = LanguageDeliveryController.getLanguageDeliveryController() .getLocaleWithId(templateController.getDatabase(), languageId); Integer contentId = new Integer(-1); if (this.getRequest() != null && this.getRequest().getParameter("contentId") != null && this.getRequest().getParameter("contentId").length() > 0) contentId = new Integer(this.getRequest().getParameter("contentId")); NodeDeliveryController nodeDeliveryController = NodeDeliveryController .getNodeDeliveryController(templateController.getSiteNodeId(), languageId, contentId); Document document = getPageComponentsDOM4JDocument(templateController.getDatabase(), templateController, templateController.getSiteNodeId(), languageId, contentId); String componentXPath = "//component[@id=" + componentId + "]/properties/property[@name='" + name + "']"; //logger.info("componentXPath:" + componentXPath); List anl = document.selectNodes(componentXPath); Iterator anlIterator = anl.iterator(); while (anlIterator.hasNext()) { Element property = (Element) anlIterator.next(); String id = property.attributeValue("type"); String path = property.attributeValue("path"); if (property.attribute("path_" + locale.getLanguage()) != null) path = property.attributeValue("path_" + locale.getLanguage()); else if (!allowLanguageVariations) { Iterator attributesIterator = property.attributeIterator(); while (attributesIterator.hasNext()) { DefaultAttribute attribute = (DefaultAttribute) attributesIterator.next(); if (attribute.getName().startsWith("path_")) { path = attribute.getValue(); } } } value = path; } return value; }
From source file:org.infoglue.deliver.invokers.DecoratedComponentBasedHTMLPageInvoker.java
License:Open Source License
/** * This method returns a value for a property if it's set. The value is collected in the * properties for the page./*from ww w. j av a 2 s. c om*/ */ private String getComponentPropertyValue(Integer componentId, String name, boolean allowLanguageVariations) throws Exception { String value = "Undefined"; Timer timer = new Timer(); timer.setActive(false); Integer siteNodeId = null; Integer languageId = null; if (this.getRequest() != null && this.getRequest().getParameter("siteNodeId") != null && this.getRequest().getParameter("siteNodeId").length() > 0) siteNodeId = new Integer(this.getRequest().getParameter("siteNodeId")); else { siteNodeId = this.getTemplateController().getDeliveryContext().getSiteNodeId(); } NodeDeliveryController nodeDeliveryController = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, null); if (this.getRequest().getParameter("languageId") != null && this.getRequest().getParameter("languageId").length() > 0) { languageId = new Integer(this.getRequest().getParameter("languageId")); //logger.info("" + languageId + "=" + this.getTemplateController().getDeliveryContext().getLanguageId()); if (!languageId.equals(this.getTemplateController().getDeliveryContext().getLanguageId())) { //logger.info("Getting 2"); languageId = LanguageDeliveryController.getLanguageDeliveryController() .getMasterLanguageForSiteNodeWithValityCheck(getDatabase(), nodeDeliveryController, siteNodeId) .getId(); } } else { languageId = LanguageDeliveryController.getLanguageDeliveryController() .getMasterLanguageForSiteNodeWithValityCheck(getDatabase(), nodeDeliveryController, siteNodeId) .getId(); } //logger.info("languageId:" + languageId); Locale locale = LanguageDeliveryController.getLanguageDeliveryController().getLocaleWithId(getDatabase(), languageId); Integer contentId = new Integer(-1); if (this.getRequest().getParameter("contentId") != null && this.getRequest().getParameter("contentId").length() > 0) contentId = new Integer(this.getRequest().getParameter("contentId")); Document document = getPageComponentsDOM4JDocument(getDatabase(), this.getTemplateController(), siteNodeId, languageId, contentId); String componentXPath = "//component[@id=" + componentId + "]/properties/property[@name='" + name + "']"; //logger.info("componentXPath:" + componentXPath); List anl = document.selectNodes(componentXPath); Iterator anlIterator = anl.iterator(); while (anlIterator.hasNext()) { Element property = (Element) anlIterator.next(); String id = property.attributeValue("type"); String path = property.attributeValue("path"); if (property.attribute("path_" + locale.getLanguage()) != null) path = property.attributeValue("path_" + locale.getLanguage()); else if (!allowLanguageVariations) { Iterator attributesIterator = property.attributeIterator(); while (attributesIterator.hasNext()) { DefaultAttribute attribute = (DefaultAttribute) attributesIterator.next(); if (attribute.getName().startsWith("path_")) { path = attribute.getValue(); } } } value = path; } /* org.w3c.dom.Document document = getPageComponentsDocument(getDatabase(), this.getTemplateController(), siteNodeId, languageId, contentId); String componentXPath = "//component[@id=" + componentId + "]/properties/property[@name='" + name + "']"; //logger.info("componentXPath:" + componentXPath); NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), componentXPath); for(int i=0; i < anl.getLength(); i++) { org.w3c.dom.Element property = (org.w3c.dom.Element)anl.item(i); String id = property.getAttribute("type"); String path = property.getAttribute("path"); if(property.hasAttribute("path_" + locale.getLanguage())) path = property.getAttribute("path_" + locale.getLanguage()); value = path; } */ return value; }