/** * Process the tag attributes and children. * @param tag the tag * @param context the parse context * @param filter the attribute filter */ public static void processElement(ITag tag, IParserContext context, IAttributeFilter filter) { final OMElement ele = context.getElement(); String text = ele.getText(); if (StringUtils.isBlank(text)) { text = null; } pushAttributeToSubConst(ele, filter); } /**
/** * Process the tag attributes and children. * @param tag the tag * @param context the parse context * @param filter the attribute filter */ public static void processElement(ITag tag, IParserContext context, IAttributeFilter filter) { final OMElement ele = context.getElement(); String text = ele.getText(); if (StringUtils.isBlank(text)) { text = null; } pushAttributeToSubConst(ele, filter); } /**
/** * Construct a tag object from a tag impl class. * * @param impl * the tag impl class * @param context * the parse context * @return the tag object, never null. */ protected T constructObject(Class<? extends T> impl, IParserContext context) { try { return impl.newInstance(); } catch (Exception e) { throw new PaxmlRuntimeException("Cannot parse tag <" + context.getElement().getLocalName() + ">", e); } }
/** * {@inheritDoc} */ @Override protected boolean populate(final IfTag tag, IParserContext context) { super.populate(tag, context); final OMElement ele = context.getElement(); assertExactAttributes(ele, IfTag.TEST_ATTR); return false; } }
/** * {@inheritDoc} */ @Override protected boolean populate(final IfTag tag, IParserContext context) { super.populate(tag, context); final OMElement ele = context.getElement(); assertExactAttributes(ele, IfTag.TEST_ATTR); return false; } }
/** * Construct a tag object from a tag impl class. * * @param impl * the tag impl class * @param context * the parse context * @return the tag object, never null. */ protected T constructObject(Class<? extends T> impl, IParserContext context) { try { return impl.newInstance(); } catch (Exception e) { throw new PaxmlRuntimeException("Cannot parse tag <" + context.getElement().getLocalName() + ">", e); } }
/** * {@inheritDoc} * */ @Override protected boolean populate(final ExpressionTag tag, IParserContext context) { super.populate(tag, context); String text = context.getElement().getText(); if (StringUtils.isEmpty(text)) { throw new PaxmlRuntimeException("<" + ExpressionTag.TAG_NAME + ">'s value cannot be blank!"); } tag.setExpression(ExpressionFactory.create(text)); return false; } }
/** * Get target resource from context. * * @param tag * the tag * @param context * the context * @return the resource, null if not found. */ protected PaxmlResource getTargetResource(FileInvokerTag tag, IParserContext context) { return context.getLocator().getResource(context.getElement().getLocalName()); }
/** * {@inheritDoc} * */ @Override protected boolean populate(final ExpressionTag tag, IParserContext context) { super.populate(tag, context); String text = context.getElement().getText(); if (StringUtils.isEmpty(text)) { throw new PaxmlRuntimeException("<" + ExpressionTag.TAG_NAME + ">'s value cannot be blank!"); } tag.setExpression(ExpressionFactory.create(text)); return false; } }
/** * Get target resource from context. * * @param tag * the tag * @param context * the context * @return the resource, null if not found. */ protected PaxmlResource getTargetResource(FileInvokerTag tag, IParserContext context) { return context.getLocator().getResource(context.getElement().getLocalName()); }
/** * {@inheritDoc} */ @Override protected boolean populate(final LiteralTag tag, IParserContext context) { processIdExpression(tag, context); // parse all inner content to make it expression String xml = getInnerXml(context.getElement()); tag.setExp(ExpressionFactory.create(xml)); // do not do further processing return true; } private String getInnerXml(OMElement ele) {
/** * {@inheritDoc} */ @Override protected boolean populate(final LiteralTag tag, IParserContext context) { processIdExpression(tag, context); // parse all inner content to make it expression String xml = getInnerXml(context.getElement()); tag.setExp(ExpressionFactory.create(xml)); // do not do further processing return true; } private String getInnerXml(OMElement ele) {
protected void processConditional(T tag, IParserContext context) { Conditional a = ReflectUtils.getAnnotation(tag.getClass(), Conditional.class); if (a != null) { tag.setResourceLocator(context.getLocator()); tag.setFactory(this); tag.setCondition(parseConditions(context.getElement(), a.ifAttribute(), a.unlessAttribute())); } }
/** * {@inheritDoc} */ @Override protected boolean populate(T tag, IParserContext context) { OMElement ele = context.getElement(); assertNoAttributes(ele, NAME, TIMEOUT); String timeout = AxiomUtils.getAttribute(ele, TIMEOUT); if (StringUtils.isNotBlank(timeout)) { tag.setTimeout(ExpressionFactory.create(timeout)); } String name = AxiomUtils.getAttribute(ele, NAME); if (StringUtils.isNotBlank(name)) { tag.setName(ExpressionFactory.create(name)); } return super.populate(tag, context); }
/** * {@inheritDoc} */ @Override protected boolean populate(T tag, IParserContext context) { OMElement ele = context.getElement(); assertNoAttributes(ele, NAME, TIMEOUT); String timeout = AxiomUtils.getAttribute(ele, TIMEOUT); if (StringUtils.isNotBlank(timeout)) { tag.setTimeout(ExpressionFactory.create(timeout)); } String name = AxiomUtils.getAttribute(ele, NAME); if (StringUtils.isNotBlank(name)) { tag.setName(ExpressionFactory.create(name)); } return super.populate(tag, context); }
protected void processConditional(T tag, IParserContext context) { Conditional a = ReflectUtils.getAnnotation(tag.getClass(), Conditional.class); if (a != null) { tag.setResourceLocator(context.getLocator()); tag.setFactory(this); tag.setCondition(parseConditions(context.getElement(), a.ifAttribute(), a.unlessAttribute())); } }
static void processExpressions(ITag tag, IParserContext context) { if (!(tag instanceof ExpressionTag)) { // make sure all text nodes are converted to <expression> tags OMElement ele = context.getElement(); for (OMNode child : AxiomUtils.getNodes(ele)) { if (child.getType() == OMNode.TEXT_NODE) { OMText textNode = (OMText) child; String text = textNode.getText(); if (StringUtils.isNotBlank(text)) { OMElement expTag = createExpressionTag(text, ele.getLineNumber()); child.insertSiblingAfter(expTag); child.detach(); } } } } }
static void processExpressions(ITag tag, IParserContext context) { if (!(tag instanceof ExpressionTag)) { // make sure all text nodes are converted to <expression> tags OMElement ele = context.getElement(); for (OMNode child : AxiomUtils.getNodes(ele)) { if (child.getType() == OMNode.TEXT_NODE) { OMText textNode = (OMText) child; String text = textNode.getText(); if (StringUtils.isNotBlank(text)) { OMElement expTag = createExpressionTag(text, ele.getLineNumber()); child.insertSiblingAfter(expTag); child.detach(); } } } } }
/** * {@inheritDoc} */ public TagCreationResult<T> create(Class<? extends T> impl, IParserContext context) { T tag = constructObject(impl, context); tag.setTagName(context.getElement().getLocalName()); tag.setLineNumber(context.getElement().getLineNumber()); tag.setResource(context.getResource()); tag.setEntity(context.getEntity()); tag.setParent(context.getParentTag()); context.getParentTag().addChild(tag); if (tag instanceof AbstractTag) { ((AbstractTag) tag).setFactory(this); ((AbstractTag) tag).setXmlElement(context.getElement()); } final boolean childrenParsed = populate(tag, context); return new TagCreationResult<T>(tag, childrenParsed); }
/** * {@inheritDoc} */ @Override protected boolean populate(T tag, IParserContext context) { super.populate(tag, context); final OMElement ele = context.getElement(); final Set<String> ignore = getIgnoredAttributes(tag, context); processElement(tag, context, new IAttributeFilter() { public boolean accept(OMElement ele, String attrName, String attrValue) { return ignore == null || !ignore.contains(attrName); } }); for (OMElement child : AxiomUtils.getElements(ele, null)) { if (isInvokerTag(child, context)) { encloseWithValueTag(ele, child, null); } } return false; } /**