Change-Id: Iac0f5c96d827e2078ace0be76bc14aa34f379d57tags/7.7.0.alpha3
@@ -27,7 +27,6 @@ import java.util.Map; | |||
import java.util.Map.Entry; | |||
import java.util.Set; | |||
import com.google.gwt.thirdparty.guava.common.collect.Sets; | |||
import com.vaadin.data.Container; | |||
import com.vaadin.data.Item; | |||
import com.vaadin.data.Property; | |||
@@ -146,10 +145,11 @@ public class GeneratedPropertyContainer extends AbstractContainer implements | |||
@Override | |||
public Collection<?> getItemPropertyIds() { | |||
Set<?> wrappedProperties = asSet(wrappedItem.getItemPropertyIds()); | |||
return Sets.union( | |||
Sets.difference(wrappedProperties, removedProperties), | |||
propertyGenerators.keySet()); | |||
Set<Object> wrappedProperties = new LinkedHashSet<Object>( | |||
wrappedItem.getItemPropertyIds()); | |||
wrappedProperties.removeAll(removedProperties); | |||
wrappedProperties.addAll(propertyGenerators.keySet()); | |||
return wrappedProperties; | |||
} | |||
@Override | |||
@@ -366,14 +366,6 @@ public class GeneratedPropertyContainer extends AbstractContainer implements | |||
return new GeneratedProperty<T>(item, propertyId, itemId, generator); | |||
} | |||
private static <T> LinkedHashSet<T> asSet(Collection<T> collection) { | |||
if (collection instanceof LinkedHashSet) { | |||
return (LinkedHashSet<T>) collection; | |||
} else { | |||
return new LinkedHashSet<T>(collection); | |||
} | |||
} | |||
/* Listener functionality */ | |||
@Override | |||
@@ -618,11 +610,11 @@ public class GeneratedPropertyContainer extends AbstractContainer implements | |||
*/ | |||
@Override | |||
public Collection<?> getContainerPropertyIds() { | |||
Set<?> wrappedProperties = asSet(wrappedContainer | |||
.getContainerPropertyIds()); | |||
return Sets.union( | |||
Sets.difference(wrappedProperties, removedProperties), | |||
propertyGenerators.keySet()); | |||
Set<Object> wrappedProperties = new LinkedHashSet<Object>( | |||
wrappedContainer.getContainerPropertyIds()); | |||
wrappedProperties.removeAll(removedProperties); | |||
wrappedProperties.addAll(propertyGenerators.keySet()); | |||
return wrappedProperties; | |||
} | |||
/** |
@@ -22,8 +22,6 @@ import java.util.EventObject; | |||
import java.util.LinkedHashSet; | |||
import java.util.Set; | |||
import com.google.gwt.thirdparty.guava.common.collect.Sets; | |||
/** | |||
* An event that specifies what in a selection has changed, and where the | |||
* selection took place. | |||
@@ -52,7 +50,7 @@ public class SelectionEvent extends EventObject { | |||
* @return a Collection of the itemIds that became selected | |||
*/ | |||
public Set<Object> getAdded() { | |||
return Sets.difference(newSelection, oldSelection); | |||
return setDifference(newSelection, oldSelection); | |||
} | |||
/** | |||
@@ -64,7 +62,27 @@ public class SelectionEvent extends EventObject { | |||
* @return a Collection of the itemIds that became deselected | |||
*/ | |||
public Set<Object> getRemoved() { | |||
return Sets.difference(oldSelection, newSelection); | |||
return setDifference(oldSelection, newSelection); | |||
} | |||
/** | |||
* Slightly optimized set difference that can return the original set or a | |||
* modified one. | |||
* | |||
* @param set1 | |||
* original set | |||
* @param set2 | |||
* the set to subtract | |||
* @return the difference set | |||
*/ | |||
private static <T> Set<T> setDifference(Set<T> set1, Set<T> set2) { | |||
if (set2.isEmpty()) { | |||
return set1; | |||
} else { | |||
LinkedHashSet<T> set = new LinkedHashSet<T>(set1); | |||
set.removeAll(set2); | |||
return set; | |||
} | |||
} | |||
/** |
@@ -30,8 +30,6 @@ import javax.portlet.PortletResponse; | |||
import javax.portlet.ResourceResponse; | |||
import javax.servlet.http.Cookie; | |||
import com.google.gwt.thirdparty.guava.common.html.HtmlEscapers; | |||
/** | |||
* Wrapper for {@link PortletResponse} and its subclasses. | |||
* | |||
@@ -139,11 +137,45 @@ public class VaadinPortletResponse implements VaadinResponse { | |||
public void sendError(int errorCode, String message) throws IOException { | |||
setStatus(errorCode); | |||
if (message != null) { | |||
message = HtmlEscapers.htmlEscaper().escape(message); | |||
message = escapeHtml(message); | |||
} | |||
getWriter().write(message); | |||
} | |||
/** | |||
* Perform minimal HTML escaping similar to Guava HtmlEscapers. | |||
* | |||
* @param input | |||
* string to escape | |||
* @return minimally escaped HTML safe string | |||
*/ | |||
private static String escapeHtml(String input) { | |||
StringBuilder sb = new StringBuilder(); | |||
for (int i = 0; i < input.length(); i++) { | |||
char c = input.charAt(i); | |||
switch (c) { | |||
case '"': | |||
sb.append("""); | |||
break; | |||
case '\'': | |||
sb.append("'"); | |||
break; | |||
case '&': | |||
sb.append("&"); | |||
break; | |||
case '<': | |||
sb.append("<"); | |||
break; | |||
case '>': | |||
sb.append(">"); | |||
break; | |||
default: | |||
sb.append(c); | |||
} | |||
} | |||
return sb.toString(); | |||
} | |||
@Override | |||
public VaadinPortletService getService() { | |||
return vaadinService; |
@@ -17,7 +17,9 @@ package com.vaadin.server; | |||
import java.io.BufferedWriter; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.io.FileNotFoundException; | |||
import java.io.FileOutputStream; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.OutputStream; | |||
@@ -26,10 +28,11 @@ import java.io.PrintWriter; | |||
import java.io.Serializable; | |||
import java.lang.reflect.Method; | |||
import java.net.MalformedURLException; | |||
import java.net.URISyntaxException; | |||
import java.net.URL; | |||
import java.net.URLConnection; | |||
import java.net.URLDecoder; | |||
import java.net.URISyntaxException; | |||
import java.nio.charset.Charset; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.Collection; | |||
@@ -48,8 +51,6 @@ import javax.servlet.http.HttpServlet; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
import com.google.gwt.thirdparty.guava.common.base.Charsets; | |||
import com.google.gwt.thirdparty.guava.common.io.Files; | |||
import com.vaadin.annotations.VaadinServletConfiguration; | |||
import com.vaadin.annotations.VaadinServletConfiguration.InitParameterName; | |||
import com.vaadin.sass.internal.ScssStylesheet; | |||
@@ -1069,7 +1070,7 @@ public class VaadinServlet extends HttpServlet implements Constants { | |||
return null; | |||
} | |||
String jsonString = Files.toString(scssCacheFile, Charsets.UTF_8); | |||
String jsonString = readFile(scssCacheFile, Charset.forName("UTF-8")); | |||
JsonObject entryJson = Json.parse(jsonString); | |||
@@ -1379,13 +1380,45 @@ public class VaadinServlet extends HttpServlet implements Constants { | |||
String cacheEntryJsonString = cacheEntry.asJson(); | |||
try { | |||
Files.write(cacheEntryJsonString, cacheFile, Charsets.UTF_8); | |||
writeFile(cacheEntryJsonString, cacheFile, Charset.forName("UTF-8")); | |||
} catch (IOException e) { | |||
getLogger().log(Level.WARNING, | |||
"Error persisting scss cache " + cacheFile, e); | |||
} | |||
} | |||
private static String readFile(File file, Charset charset) | |||
throws IOException { | |||
InputStream in = new FileInputStream(file); | |||
try { | |||
// no point in reading files over 2GB to a String | |||
byte[] b = new byte[(int) file.length()]; | |||
int len = b.length; | |||
int total = 0; | |||
while (total < len) { | |||
int result = in.read(b, total, len - total); | |||
if (result == -1) { | |||
break; | |||
} | |||
total += result; | |||
} | |||
return new String(b, charset); | |||
} finally { | |||
in.close(); | |||
} | |||
} | |||
private static void writeFile(String content, File file, Charset charset) | |||
throws IOException { | |||
FileOutputStream fos = new FileOutputStream(file); | |||
try { | |||
fos.write(content.getBytes(charset)); | |||
} finally { | |||
fos.close(); | |||
} | |||
} | |||
private static File getScssCacheFile(File scssFile) { | |||
return new File(scssFile.getParentFile(), scssFile.getName() + ".cache"); | |||
} |