示例#1
0
 /**
  * Creates a resource from a given resourceElement. It can be css, js. If resource tag name is
  * group-ref, the method will start a recursive computation.
  *
  * @param resourceElement
  * @param resources list of parsed resources where the parsed resource is added.
  */
 private void parseResource(
     final Element resourceElement,
     final Collection<Resource> resources,
     final Collection<Group> groups) {
   ResourceType type = null;
   final String tagName = resourceElement.getTagName();
   final String uri = resourceElement.getTextContent();
   if (TAG_JS.equals(tagName)) {
     type = ResourceType.JS;
   } else if (TAG_CSS.equals(tagName)) {
     type = ResourceType.CSS;
   } else if (TAG_GROUP_REF.equals(tagName)) {
     // uri in this case is the group name
     final Element groupElement = allGroupElements.get(uri);
     resources.addAll(parseGroup(groupElement, groups));
   }
   if (type != null) {
     final String minimizeAsString = resourceElement.getAttribute(ATTR_MINIMIZE);
     final boolean minimize =
         StringUtils.isEmpty(minimizeAsString)
             ? true
             : Boolean.valueOf(resourceElement.getAttribute(ATTR_MINIMIZE));
     final Resource resource = Resource.create(uri, type);
     resource.setMinimize(minimize);
     resources.add(resource);
   }
 }
示例#2
0
 @Test
 public void testReplaceWithFewResources() {
   final Group group = new Group("group");
   final Resource resource = Resource.create("/static/*", ResourceType.JS);
   resource.setMinimize(false);
   group.addResource(resource);
   group.replace(
       resource,
       Arrays.asList(
           Resource.create("/static/one.js", ResourceType.JS),
           Resource.create("/static/two.js", ResourceType.JS)));
   Assert.assertEquals(2, group.getResources().size());
   Assert.assertEquals(resource.isMinimize(), group.getResources().get(0).isMinimize());
 }