public List<Object> parse(String content) throws GadgetException { List<Object> parsedCss = null; boolean shouldCache = shouldCache(); String key = null; if (shouldCache) { // TODO - Consider using the source if its under a certain size key = HashUtil.checksum(content.getBytes()); parsedCss = parsedCssCache.getElement(key); } if (parsedCss == null) { parsedCss = parseImpl(content); if (shouldCache) { parsedCssCache.addElement(key, parsedCss); } } if (shouldCache) { List<Object> cloned = Lists.newArrayListWithCapacity(parsedCss.size()); for (Object o : parsedCss) { if (o instanceof ImportDecl) { cloned.add(new ImportDecl(((ImportDecl) o).getUri())); } else if (o instanceof UriDecl) { cloned.add(new UriDecl(((UriDecl) o).getUri())); } else { cloned.add(o); } } return cloned; } return parsedCss; }
public List<Object> parse(String content) throws GadgetException { List<Object> parsedCss = null; boolean shouldCache = shouldCache(); String key = null; if (shouldCache) { // TODO - Consider using the source if its under a certain size key = HashUtil.checksum(content.getBytes()); parsedCss = parsedCssCache.getElement(key); } if (parsedCss == null) { parsedCss = parseImpl(content); if (shouldCache) { parsedCssCache.addElement(key, parsedCss); } } if (shouldCache) { List<Object> cloned = Lists.newArrayListWithCapacity(parsedCss.size()); for (Object o : parsedCss) { if (o instanceof ImportDecl) { cloned.add(new ImportDecl(((ImportDecl) o).getUri())); } else if (o instanceof UriDecl) { cloned.add(new UriDecl(((UriDecl) o).getUri())); } else { cloned.add(o); } } return cloned; } return parsedCss; }
public List<Object> parse(String content) throws GadgetException { List<Object> parsedCss = null; boolean shouldCache = shouldCache(); String key = null; if (shouldCache) { // TODO - Consider using the source if its under a certain size key = HashUtil.checksum(content.getBytes()); parsedCss = parsedCssCache.getElement(key); } if (parsedCss == null) { parsedCss = parseImpl(content); if (shouldCache) { parsedCssCache.addElement(key, parsedCss); } } if (shouldCache) { List<Object> cloned = Lists.newArrayListWithCapacity(parsedCss.size()); for (Object o : parsedCss) { if (o instanceof ImportDecl) { cloned.add(new ImportDecl(((ImportDecl) o).getUri())); } else if (o instanceof UriDecl) { cloned.add(new UriDecl(((UriDecl) o).getUri())); } else { cloned.add(o); } } return cloned; } return parsedCss; }
@Test public void testClone() throws Exception { // Set the cache so we force cloning cajaCssParser.setCacheProvider(new LruCacheProvider(100)); // Compare the raw parsed structure to a cloned one List<Object> styleSheet = cajaCssParser.parseImpl(CSS); List<Object> styleSheet2 = cajaCssParser.parse(CSS); assertEquals(cajaCssParser.serialize(styleSheet), cajaCssParser.serialize(styleSheet2)); }
@Test public void testClone() throws Exception { // Set the cache so we force cloning cajaCssParser.setCacheProvider(new LruCacheProvider(100)); // Compare the raw parsed structure to a cloned one List<Object> styleSheet = cajaCssParser.parseImpl(CSS); List<Object> styleSheet2 = cajaCssParser.parse(CSS); assertEquals(cajaCssParser.serialize(styleSheet), cajaCssParser.serialize(styleSheet2)); }
@Test public void testClone() throws Exception { // Set the cache so we force cloning cajaCssParser.setCacheProvider(new LruCacheProvider(100)); // Compare the raw parsed structure to a cloned one List<Object> styleSheet = cajaCssParser.parseImpl(CSS); List<Object> styleSheet2 = cajaCssParser.parse(CSS); assertEquals(cajaCssParser.serialize(styleSheet), cajaCssParser.serialize(styleSheet2)); }