Skip to content

Commit

Permalink
Merge branch 'development' into participant
Browse files Browse the repository at this point in the history
Conflicts:
	.gitignore
	plugins/com.aptana.theme/src/com/aptana/theme/ThemeExporter.java
  • Loading branch information
sgtcoolguy committed Jan 31, 2012
2 parents 20b8a20 + c3457fd commit 83cda68
Show file tree
Hide file tree
Showing 13 changed files with 960 additions and 168 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ native/**/Debug/
native/**/Release/
native/**/UpgradeLog*.XML
native/**/_UpgradeReport_Files/
tests/com.aptana.scripting.tests/application-bundles/**/cache.yml
tests/com.aptana.scripting.tests/user-bundles/**/cache.yml
tests/com.aptana.scripting.tests/project-bundles/**/cache.yml
tests/com.aptana.scripting.tests/application-bundles/**/cache*.yml
tests/com.aptana.scripting.tests/user-bundles/**/cache*.yml
tests/com.aptana.scripting.tests/project-bundles/**/cache*.yml
tests/com.aptana.studio.tests.all/wintest
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -368,6 +369,62 @@ public static final <T> Set<T> newSet(T... items)
return result;
}

/**
* Convert a list of items into a Set. An empty set is returned if items is null
*
* @param <T>
* Any type of object
* @param items
* A variable length list of items of type T
* @return Returns a new HashSet<T> or an empty set
*/
public static final <T> Map<T, T> newMap(T... items)
{
Map<T, T> result;

if (items != null)
{
result = new HashMap<T, T>();
addToMap(result, items);
}
else
{
result = Collections.emptyMap();
}

return result;
}

/**
* Add a varargs list of items into a map. It is expected that items be in "key, value, key2, value2, etc.."
* ordering. If the map or items are null then no action is performed. Note that the destination map has no
* requirements other than it must be a Map of the source item's type. This allows the destination to be used, for
* example, as an accumulator.<br>
* <br>
* Note that this method is not thread safe. Users of this method will need to maintain type safety against the map.
*
* @param map
* A map to which items will be added
* @param items
* A list of items to add
*/
public static final <T, U extends T> Map<T, T> addToMap(Map<T, T> map, U... items)
{
if (map != null && items != null)
{
if (items.length % 2 != 0)
{
throw new IllegalArgumentException("Length of list of items must be multiple of 2"); //$NON-NLS-1$
}
for (int i = 0; i < items.length; i += 2)
{
map.put(items[i], items[i + 1]);
}
}

return map;
}

/**
* Given a list of elements of type <T>, remove the duplicates from the list in place
*
Expand Down
19 changes: 17 additions & 2 deletions plugins/com.aptana.core/src/com/aptana/core/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.core.runtime.IStatus;
Expand All @@ -35,6 +36,13 @@ public class StringUtil
*/
public static final Pattern LINE_SPLITTER = Pattern.compile("\r?\n|\r"); //$NON-NLS-1$

/**
* Map to sanitize html/xml to entities.
*/
private static final Map<String, String> SANITIZE_MAP = CollectionsUtil.newMap(
"&", "&amp;", "<", "&lt;", ">", "&gt;"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
private static final Pattern SANITIZE_PATTERN = Pattern.compile("[&<>]"); //$NON-NLS-1$

private StringUtil()
{
}
Expand Down Expand Up @@ -286,15 +294,22 @@ public static String md5(String lowerCase)
return null;
}

/**
/**
* Sanitizes raw HTML to escape '&', '<' and '>' so that it is suitable for embedding into HTML.
*
* @param raw
* @return
*/
public static String sanitizeHTML(String raw)
{
return raw.replaceAll("&", "&amp;").replaceAll("<", "&lt;"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
StringBuffer sb = new StringBuffer();
Matcher m = SANITIZE_PATTERN.matcher(raw);
while (m.find())
{
m.appendReplacement(sb, SANITIZE_MAP.get(m.group()));
}
m.appendTail(sb);
return sb.toString();
}

/**
Expand Down
Loading

0 comments on commit 83cda68

Please sign in to comment.