Package cambridge.model

Examples of cambridge.model.Attribute


         context.put("b", "BBB");
         TemplateDocument t = parser.parse();

         assertNotNull(t);

         Attribute a = t.locateTag("/div").getAttribute("id");
         assertTrue(a instanceof ComplexAttribute);

         ComplexAttribute c = (ComplexAttribute) a;

         assertEquals(4, c.getFragments().size());
View Full Code Here


         TemplateDocument t = parser.parse();

         assertNotNull(t);

         Attribute a = t.locateTag("/div").getAttribute("style");
         assertTrue(a instanceof ComplexAttribute);

         ComplexAttribute c = (ComplexAttribute) a;

         assertEquals(1, c.getFragments().size());
View Full Code Here

                    if (dynamicTag && tok.getNameSpace() == null) {
                        tok.setNameSpace(node.getNameSpace());
                    }

                    Attribute element = null;
                    StringBuilder textContent = new StringBuilder();
                    textContent.append(tok.getActualValue());
                    boolean dynamic = false;
                    boolean staticAttribute = false;

                    String namespaceUri = getNamespaceUri(tok.getNameSpace());
                    if (namespaceUri != null && bindings.isRegisteredNamespace(namespaceUri)) {

                        dynamic = true;
                        if (bindings.isStaticAttribute(namespaceUri, tok.getAttributeName())) {
                            staticAttribute = true;
                            element = new StaticAttribute(namespaceUri, tok.getLineNo(), tok.getColumn());
                        } else {
                            element = new DynamicAttribute(namespaceUri, tok.getLineNo(), tok.getColumn());
                        }
                    }

                    while (true) {
                        if (peek(1).getType() == TokenType.EOF
                            || peek(1).getType() == TokenType.TAG_END
                            || peek(1).getType() == TokenType.EXPRESSION
                            || peek(1).getType() == TokenType.EXTENSION
                            || peek(1).getType() == TokenType.ATTRIBUTE_NAME
                            ) {
                            break;
                        }
                        nextToken();

                        boolean exitLoop = false;
                        switch (currentToken.getType()) {
                            case WS:
                            case EOL:
                            case ASSIGN:
                                textContent.append(currentToken.getActualValue());
                                break;
                            case ATTRIBUTE_VALUE:
                                textContent.append(currentToken.getActualValue());

                                if (dynamic) {
                                    if (staticAttribute) {
                                        ((StaticAttribute) element).setValue(currentToken.value);
                                    } else {
                                        ((DynamicAttribute) element).setValue(currentToken.value, expressionLanguage.parse(currentToken.value, currentToken.getLineNo(), currentToken.getColumn()));
                                    }

                                    exitLoop = true;
                                    break;
                                }

                                TemplateTokenizer at = new TemplateTokenizer(new StringReader(currentToken.getValue()));

                                ArrayList<AttributeFragment> fragments = new ArrayList<AttributeFragment>();
                                while (at.hasMoreTokens()) {
                                    Token attrToken = at.nextToken();
                                    switch (attrToken.getType()) {
                                        case EXPRESSION:
                                            ExpressionToken expTok = (ExpressionToken) attrToken;
                                            try {
                                                ExpressionNode expNode = new ExpressionNode(attrToken.value, expressionLanguage.parse(attrToken.value, attrToken.getLineNo(), attrToken.getColumn()), expTok.isRawExpression());

                                                if (expTok.getFilters() != null) {
                                                    expNode.setFilters(expTok.getFilters());
                                                }
                                                fragments.add(expNode);
                                            } catch (ExpressionParsingException e1) {
                                                throw new TemplateParsingException("Error parsing expression", e1, currentToken.getLineNo(), currentToken.getColumn());
                                            }

                                            break;
                                        case EXTENSION:
                                            ExtensionToken extensionToken = (ExtensionToken) attrToken;
                                            ExtensionNode extensionNode = extensionToken.createNode(expressionLanguage);
                                            fragments.add(extensionNode);
                                            break;
                                        case WS:
                                        case STRING:
                                            StaticFragment st = new StaticFragment(attrToken.value);
                                            fragments.add(st);
                                            break;
                                    }
                                }

                                if (fragments.size() == 0 || fragments.size() == 1 && fragments.get(0) instanceof StaticFragment) {
                                    element = new SimpleAttribute(currentToken.getLineNo(), currentToken.getColumn());
                                    ((SimpleAttribute) element).setValue(currentToken.value);
                                } else {
                                    element = new ComplexAttribute(currentToken.getLineNo(), currentToken.getColumn());
                                    ((ComplexAttribute) element).setFragments(fragments);
                                    AttributeValueToken aTok = (AttributeValueToken) currentToken;
                                    if (aTok.getQuotes() == -2) {
                                        ((ComplexAttribute) element).setQuote('"');
                                    } else if (aTok.getQuotes() == -3) {
                                        ((ComplexAttribute) element).setQuote('\'');
                                    }
                                }

                                exitLoop = true;
                                break;
                        }

                        if (exitLoop) break;
                    }

                    if (element == null) {
                        if (tok != null) {
                            element = new SimpleAttribute(tok.getAttributeName(), tok.getNameSpace(), tok.getLineNo(), tok.getLineNo());
                        } else {
                            throw new TemplateParsingException("Error parsing template file. Unterminated tag?", currentToken.getLineNo(), currentToken.getColumn());
                        }
                    }

                    element.setAttributeName(tok.getAttributeName());
                    element.setAttributeNameSpace(tok.getNameSpace());
                    element.setTextContent(textContent.toString());

                    int s = node.getTagParts().size();
                    if (s > 0) {
                        TagPart te = node.getTagParts().get(s - 1);
                        if (te instanceof TextTagPart) {
                            if (te.isWhiteSpace()) {
                                node.getTagParts().remove(s - 1);
                            }
                        }
                    }

                    if (firstTag && "xmlns".equalsIgnoreCase(element.getAttributeNameSpace())) {
                        putNamespaceMapping(element.getAttributeName(), element.getValue());
                    }

                    node.addAttribute(element);
                    break;
                case EXPRESSION:
View Full Code Here

    public static BehaviorProvider<ForeachBehavior> getProvider() {
        return new BehaviorProvider<ForeachBehavior>() {
            public ForeachBehavior get(DynamicAttribute keyAttribute, Map<AttributeKey, Attribute> attributes, int line, int col) throws ExpressionParsingException, BehaviorInstantiationException {

                AttributeKey asKey = new AttributeKey(keyAttribute.getAttributeNameSpace(), "as");
                Attribute asAttribute = attributes.get(asKey);

                AttributeKey iterKey = new AttributeKey(keyAttribute.getAttributeNameSpace(), "iter");
                Attribute iterAttribute = attributes.get(iterKey);

                Expression e = keyAttribute.getExpression();
                return new ForeachBehavior(e, asAttribute == null ? null : asAttribute.getValue(), iterAttribute == null ? null : iterAttribute.getValue(), line, col);
            }
        };
    }
View Full Code Here

   Expression formExpression;

   //action="${self.action}" name="${self.name}" method="${self.method}" enctype="${self.encType}"
   @Override
   public void init() throws TemplateParsingException {
      Attribute a = getAttribute(nameSpace, "form");
      if (!(a instanceof DynamicAttribute)) {
         throw new TemplateParsingException("The required attribute form for form element is not specified", getBeginLine(), getBeginColumn());
      }

      DynamicAttribute form = (DynamicAttribute) a;
View Full Code Here

                if (t == attribute) {
                    next = true;
                } else {
                    if (next) {
                        if (t instanceof Attribute) {
                            Attribute a = (Attribute) t;
                            if (!a.isDynamic()) {
                                remove = i;
                            }
                        }
                    }
                }
View Full Code Here

        return new BehaviorProvider<FromBehavior>() {
            public FromBehavior get(DynamicAttribute keyAttribute, Map<AttributeKey, Attribute> attributes, int line, int col) throws ExpressionParsingException, BehaviorInstantiationException {
                Expression from = keyAttribute.getExpression();
                AttributeKey toKey = new AttributeKey(keyAttribute.getAttributeNameSpace(), "to");

                Attribute toAttribute = attributes.get(toKey);

                if (toAttribute == null || !(toAttribute instanceof DynamicAttribute)) {
                    throw new BehaviorInstantiationException("Required parameters to is not set", line, col);
                }
View Full Code Here

    public static BehaviorProvider<WithBehavior> getProvider() {
        return new BehaviorProvider<WithBehavior>() {
            public WithBehavior get(DynamicAttribute keyAttribute, Map<AttributeKey, Attribute> attributes, int line, int col) throws ExpressionParsingException, BehaviorInstantiationException {

                AttributeKey asKey = new AttributeKey(keyAttribute.getAttributeNameSpace(), "as");
                Attribute asAttribute = attributes.get(asKey);

                return new WithBehavior(keyAttribute.getExpression(), asAttribute == null ? null : asAttribute.getValue(), line, col);
            }
        };
    }
View Full Code Here

TOP

Related Classes of cambridge.model.Attribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.