Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
MatrixToolkit.java
1 
16 package net.squiz.matrix.core;
17 
18 import java.util.*;
19 import java.net.*;
20 import javax.swing.*;
21 import java.awt.Component;
22 import java.io.UnsupportedEncodingException;
23 
32 public class MatrixToolkit {
33 
34  // cannot instantiate
35  private MatrixToolkit() {}
36 
46  public static String rawUrlEncode(String url, boolean encodeSpaces) {
47  try {
48  url = URLEncoder.encode(url, "UTF-8");
49  } catch (UnsupportedEncodingException uee) {
50  System.err.println("Could not encode url");
51  uee.printStackTrace();
52  }
53  if (!encodeSpaces)
54  url = url.replace('+', ' ');
55  return url;
56  }
57 
64  public static String rawUrlDecode(String url) {
65  try {
66  url = URLDecoder.decode(url, "UTF-8");
67  } catch (UnsupportedEncodingException uee) {
68  System.err.println("Could not decode url");
69  uee.printStackTrace();
70  }
71  return url;
72  }
73 
83  public static String implode(String delimiter, List elements) {
84  StringBuffer buff = new StringBuffer();
85  Iterator iterator = elements.iterator();
86  while (iterator.hasNext()) {
87  Object element = iterator.next();
88  if (element instanceof Integer)
89  buff.append(((Integer) element).toString());
90  else
91  buff.append((String) element);
92  buff.append(delimiter);
93  }
94  return buff.toString();
95  }
96 
97  public static void addAssetToXML(StringBuffer xml, Asset asset, int start, int limit) {
98  addAssetToXML(xml, asset.getId(), "0", start, limit);
99  }
100 
107  public static void addAssetToXML(StringBuffer xml, String assetid, String linkid, int start, int limit) {
108  if (assetid.equals("1")) {
109  start = 0;
110  limit = 0;
111  linkid = "0";
112  }
113  String limitstr = "start=\""+start+"\" limit=\""+limit+"\"";
114 
115  xml.append("<asset assetid=\"").append(
116  rawUrlEncode(assetid, false)).append("\" "+limitstr).append(" linkid=\"").append(rawUrlEncode(linkid, false)).append("\" />");
117  }
118 }