16 package net.squiz.matrix.core;
19 import javax.xml.parsers.DocumentBuilder;
21 import org.xml.sax.SAXException;
23 import java.security.*;
25 import java.text.MessageFormat;
45 private static Properties properties =
new Properties();
46 private static Properties translations =
new Properties();
56 if (!translations.containsKey(key))
57 System.out.println(
"Translation " + key +
" not found");
58 return translations.getProperty(key, key);
66 public static final String
translate(String key, Object[] arguments) {
67 if (!translations.containsKey(key))
68 System.out.println(
"Translation " + key +
" not found");
69 String rawTranslation = translations.getProperty(key, key);
70 return MessageFormat.format(rawTranslation, arguments);
80 translations.load(
new ByteArrayInputStream(propertiesFile.getBytes()));
81 }
catch (IOException ioe) {
82 ioe.printStackTrace();
91 return properties.getProperty(key);
100 public static final String
getProperty(String key, String defaultValue) {
101 return properties.getProperty(key, defaultValue);
110 properties.setProperty(key, value);
120 public static Document
doRequest(String xml)
throws IOException {
122 final String myxml = xml;
124 URLConnection conn = AccessController.doPrivileged(
125 new PrivilegedAction<URLConnection>() {
126 public URLConnection run() {
128 URLConnection conn = null;
130 String basePath =
getProperty(
"parameter.url.baseurl");
131 String execPath = basePath +
getProperty(
"parameter.backendsuffix")
132 +
"/?SQ_ACTION=asset_map_request&SESSION_ID="
134 execURL =
new URL(execPath);
135 }
catch (MalformedURLException mue) {
136 mue.printStackTrace();
140 conn = execURL.openConnection();
141 conn.setUseCaches(
false);
142 conn.setDoOutput(
true);
144 ByteArrayOutputStream byteStream =
new ByteArrayOutputStream(512);
145 PrintWriter out =
new PrintWriter(byteStream,
true);
149 conn.setRequestProperty(
"Content-Length", String.valueOf(byteStream.size()));
150 conn.setRequestProperty(
"Content-Type",
"application/x-www-form-urlencoded");
151 conn.setRequestProperty(
"Cache-Control",
"no-store, no-cache, " +
152 "must-revalidate, post-check=0, pre-check=0");
154 byteStream.writeTo(conn.getOutputStream());
156 }
catch (IOException ioe) {
158 ioe.printStackTrace();
165 Document document = null;
166 DocumentBuilder builder = null;
170 }
catch (SAXException se) {
171 throw new IOException(
"Could not do the mysource request: " + se.getMessage());
175 document = builder.parse(conn.getInputStream());
176 }
catch (SAXException se) {
179 throw new IOException(
"error while parsing : " + se.getMessage());
182 if (document.getDocumentElement().getTagName().equals(
"error")) {
183 Element errorElement = (Element) document.getDocumentElement();
184 throw new IOException(
"error while getting response: "
185 + errorElement.getFirstChild().getNodeValue());