Package com.granule.parser

Examples of com.granule.parser.Element


    }

    public void testAttributes() {
        String text = "<p style=\"aa aaa\" align=righT class='tt'>";
        TagReader s = new TagReader(text);
        Element el = s.getAllElements().get(0);
        assertEquals(el.getAttributes().getValue("StYle"), "aa aaa");
        assertEquals(el.getAttributes().getValue("ALIGN"), "righT");
        assertNotSame(el.getAttributes().getValue("ALIGN"), "right");
        assertEquals(el.getAttributes().getValue("class"), "tt");
        assertEquals(el.getAttributes().getValue("id"), null);

        text = "<LINK title=style href=\"style.css\" type=text/css rel=stylesheet> ";
        s = new TagReader(text);
        assertEquals(s.getAllElements().get(0).getAttributes().getValue("type"), "text/css");
View Full Code Here


        testInclude("<%--<%@include file='ff.inc'%>--%><%@include file='ff.inc'%>",1);
    }

  private void testInclude(String text,int tagPosition) {
    TagReader s;
    Element includeTag;
    Attributes includeAttributes;
    s = new TagReader(text);
        includeTag = s.getAllElements().get(tagPosition);
        includeAttributes = s.parseAttributes(includeTag);
        assertEquals(includeAttributes.isValueExists("include"), true);
View Full Code Here

                "            width: 125px;\n" +
                "          }\n" +
                "        </style>";
        TagReader s = new TagReader(text);
        assertEquals(s.getAllElements(Tags.SCRIPT).size(), 2);
        Element firstScript = s.getAllElements(Tags.SCRIPT).get(0);
        Element secondScript = s.getAllElements(Tags.SCRIPT).get(1);
        assertEquals(firstScript.isContentExists(), true);
        assertEquals(secondScript.isContentExists(), true);
        assertEquals(firstScript.getContentAsString(), "");
        assertEquals(secondScript.getContentAsString(), "\n" +
                "          goog.require('goog.events');\n" +
                "          goog.require('goog.fx');\n" +
                "          goog.require('goog.fx.dom');\n" + "        ");
        assertEquals(firstScript.getAttributes().isValueExists("src"), true);
        assertEquals(secondScript.getAttributes().isValueExists("src"), false);
        assertEquals(firstScript.getAttributes().getValue("src"), "js/closure/goog/base.js");

        Element link = s.getAllElements(Tags.LINK).get(0);
        assertEquals(link.getAttributes().getValue("REL"), "stylesheet");
        assertEquals(link.getAttributes().get("ReL").getBegin(), text.indexOf("rel="));
        assertEquals(link.getAttributes().get("ReL").getEnd(), text.indexOf("stylesheet") + "stylesheet\"".length());

        Element style = s.getAllElements(Tags.STYLE).get(0);
        assertEquals(style.getBegin(), text.indexOf("<style>"));
        assertEquals(style.getEnd(), text.indexOf("</style>") + "</style>".length());
        assertEquals(style.getContentBegin(), text.indexOf("<style>") + "<style>".length());
        assertEquals(style.getContentEnd(), text.indexOf("</style>"));
    }
View Full Code Here

        for (Element e : all)
            if (e.getName() != null && e.getName().equalsIgnoreCase("%"))
                jspTags++;
            else if (e.getName() != null && e.getName().equals("g:compress")) gCompressPos = all.indexOf(e);
        assertEquals(jspTags, 3);
        Element pageTag = all.get(1);
        Attributes pageAttributes = s.parseAttributes(pageTag);
        assertEquals(pageAttributes.isValueExists("include"), false);
        assertEquals(pageAttributes.isValueExists("file"), false);

        Element includeTag = all.get(2);
        Attributes includeAttributes = s.parseAttributes(includeTag);
        assertEquals(includeAttributes.isValueExists("include"), true);
        assertEquals(includeAttributes.isValueExists("file"), true);
        assertEquals(includeTag.getBegin(), text.indexOf("<%@ include"));
        assertEquals(includeTag.getEnd(), text.indexOf("<%@ include") + "<%@ include file=\"includes/test1.inc\"%>".length());

        Element gCompress = all.get(gCompressPos);
        Attributes gCompressAttrs = s.parseAttributes(gCompress);
        assertEquals(gCompressAttrs.isValueExists("dsdsd"), false);
        assertEquals(gCompressAttrs.isValueExists("method"), true);
        assertEquals(gCompressAttrs.get("method").getBegin(), text.indexOf("method="));
        assertEquals(gCompressAttrs.get("method").getEnd(), text.indexOf("method=") + "method=\"closure-compiler\"".length());
        assertEquals(gCompress.getBegin(), text.indexOf("<g:compress"));
        assertEquals(gCompress.getEnd(), text.indexOf("</g:compress>") + "</g:compress>".length());
    }
View Full Code Here

                        TagCache tagCache = TagCacheFactory.getInstance();
                        bundleId = tagCache.compressAndStore(requestProxy, settings, fragmentDescriptors, true, opts);
                    }
                    if (runtimRequest!=null) //generate output only in runtime
                      for (int i = 0; i < scripts.size(); i++) {
                          Element e = scripts.get(i);
                          if (i != scripts.size() - 1) {
                              newBody = newBody.substring(0, e.getBegin() + correction)
                                      + newBody.substring(e.getEnd() + correction);
                              correction -= e.getEnd() - e.getBegin();
                          } else {
                              if (fragmentDescriptors.size() > 0) {
                                  String newText = "<script src=\"" + PathUtils.getContextURL(runtimRequest.getContextPath(),"/combined.js?id="
                                          + bundleId) + "\"></script>";
                                  newBody = newBody.substring(0, e.getBegin() + correction) + newText
                                          + newBody.substring(e.getEnd() + correction);
                                  correction -= e.getEnd() - e.getBegin();
                                  correction += newBody.length();
                              } else {
                                  newBody = newBody.substring(0, e.getBegin() + correction)
                                          + newBody.substring(e.getEnd() + correction);
                                  correction -= e.getEnd() - e.getBegin();
                              }
                          }
                      }
                }
            } else
View Full Code Here

                    requestProxy.setAttribute(CSS_DUPLICATES, cssDuplicates);
                }
            }
            HashMap<String, MediaInfo> mediae = new HashMap<String, MediaInfo>();
            for (int i = 0; i < links.size(); i++) {
                Element link = links.get(i);
                Attributes attrs = link.getAttributes();
                if (attrs.isValueExists("rel") && attrs.getValue("rel").equalsIgnoreCase("stylesheet")
                        && attrs.isValueExists("href")) {
                    String media = "";
                    if (attrs.isValueExists("media"))
                        media = attrs.getValue("media");
View Full Code Here

TOP

Related Classes of com.granule.parser.Element

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.