List of usage examples for org.apache.commons.codec.net QuotedPrintableCodec QuotedPrintableCodec
public QuotedPrintableCodec(String charset)
From source file:hd3gtv.mydmam.db.BackupDbElasticsearch.java
BackupDbElasticsearch(File outfile, String index_name,
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mapping,
ImmutableOpenMap<String, Settings> settings) throws Exception {
quotedprintablecodec = new QuotedPrintableCodec("UTF-8");
GsonBuilder g_builder = new GsonBuilder();
g_builder.disableHtmlEscaping();//www.j av a 2 s.com
if (BackupDb.mode_debug) {
g_builder.setPrettyPrinting();
}
gson = g_builder.create();
/**
* Preparation
*/
fileoutputstream = new FileOutputStream(outfile);
OutputFormat of = new OutputFormat();
of.setMethod("xml");
of.setEncoding("UTF-8");
of.setVersion("1.0");
of.setIndenting(BackupDb.mode_debug);
if (BackupDb.mode_debug) {
of.setIndent(2);
}
serializer = new XMLSerializer(fileoutputstream, of);
content = serializer.asContentHandler();
content.startDocument();
/**
* Headers
*/
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "name", "CDATA", index_name);
atts.addAttribute("", "", "created", "CDATA", String.valueOf(System.currentTimeMillis()));
if (BackupDb.mode_debug) {
atts.addAttribute("", "", "created_date", "CDATA", (new Date()).toString());
}
content.startElement("", "", "index", atts);
/**
* Import configuration
* ES Mapping
*/
String jo_mapping;
ImmutableOpenMap<String, MappingMetaData> mapping_value;
for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> mapping_cursor : mapping) {
mapping_value = mapping_cursor.value;
for (ObjectObjectCursor<String, MappingMetaData> mapping_value_cursor : mapping_value) {
atts.clear();
atts.addAttribute("", "", "name", "CDATA", mapping_value_cursor.key);
content.startElement("", "", "mapping", atts);
jo_mapping = gson.toJson(mapping_value_cursor.value.getSourceAsMap());
if (BackupDb.mode_debug) {
serializer.comment(jo_mapping);
}
jo_mapping = new String(quotedprintablecodec.encode(jo_mapping));
content.characters(jo_mapping.toCharArray(), 0, jo_mapping.length());
content.endElement("", "", "mapping");
}
}
/**
* ES settings
*/
for (ObjectObjectCursor<String, Settings> settings_cursor : settings) {
atts.clear();
content.startElement("", "", "settings", atts);
jo_mapping = gson.toJson(settings_cursor.value.getAsMap());
if (BackupDb.mode_debug) {
serializer.comment(jo_mapping);
}
jo_mapping = new String(quotedprintablecodec.encode(jo_mapping));
content.characters(jo_mapping.toCharArray(), 0, jo_mapping.length());
content.endElement("", "", "settings");
}
}
From source file:mitm.common.template.QuotedPrintableEncodeMethod.java
@Override public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException { if (arguments.size() != 1 && arguments.size() != 2) { throw new TemplateModelException(METHOD_NAME + " needs 1 or two arguments."); }// ww w. ja v a2s .c o m try { String input = (String) arguments.get(0); String charset = arguments.size() == 2 ? (String) arguments.get(1) : CharacterEncoding.UTF_8; QuotedPrintableCodec codec = new QuotedPrintableCodec(charset); return new SimpleScalar(codec.encode(input)); } catch (EncoderException e) { throw new TemplateModelException("Quoted Printable encoding failed", e); } }
From source file:hd3gtv.mydmam.db.BackupDbCassandra.java
BackupDbCassandra(String keyspacename, boolean purgebefore) throws Exception { quotedprintablecodec = new QuotedPrintableCodec("UTF-8"); this.purgebefore = purgebefore; if (CassandraDb.isKeyspaceExists(keyspacename) == false) { CassandraDb.createKeyspace(keyspacename); }/*from w w w . j a v a2 s . c om*/ keyspace = CassandraDb.getkeyspace(keyspacename); }
From source file:hd3gtv.mydmam.db.BackupDbCassandra.java
BackupDbCassandra(Keyspace keyspace, ColumnFamilyDefinition cfd, File outfile) throws Exception { quotedprintablecodec = new QuotedPrintableCodec("UTF-8"); String cfname = cfd.getName(); /**//from w w w .j ava 2 s . c o m * Preparation */ fileoutputstream = new FileOutputStream(outfile); OutputFormat of = new OutputFormat(); of.setMethod("xml"); of.setEncoding("UTF-8"); of.setVersion("1.0"); of.setIndenting(BackupDb.mode_debug); if (BackupDb.mode_debug) { of.setIndent(2); } XMLSerializer serializer = new XMLSerializer(fileoutputstream, of); content = serializer.asContentHandler(); content.startDocument(); /** * Headers */ AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "keyspace", "CDATA", CassandraDb.default_keyspacename); atts.addAttribute("", "", "name", "CDATA", cfname); atts.addAttribute("", "", "created", "CDATA", String.valueOf(System.currentTimeMillis())); if (BackupDb.mode_debug) { atts.addAttribute("", "", "created_date", "CDATA", (new Date()).toString()); } content.startElement("", "", "columnfamily", atts); /** * Import description */ List<ColumnDefinition> l_cd = cfd.getColumnDefinitionList(); for (int pos = 0; pos < l_cd.size(); pos++) { atts.clear(); atts.addAttribute("", "", "name", "CDATA", l_cd.get(pos).getName()); atts.addAttribute("", "", "indexname", "CDATA", l_cd.get(pos).getIndexName()); atts.addAttribute("", "", "validationclass", "CDATA", l_cd.get(pos).getValidationClass()); content.startElement("", "", "coldef", atts); content.endElement("", "", "coldef"); } }
From source file:hd3gtv.mydmam.db.BackupDbElasticsearch.java
BackupDbElasticsearch(boolean purgebefore, long ttl) throws Exception { this.purgebefore = purgebefore; this.ttl = ttl; quotedprintablecodec = new QuotedPrintableCodec("UTF-8"); }
From source file:com.flexive.shared.FxMailUtils.java
private static String encodeQuotedPrintable(String textBody) throws EncoderException { return new QuotedPrintableCodec("UTF-8").encode(textBody); }
From source file:com.android.bluetooth.map.BluetoothMapContent.java
public static String decodeEncodedWord(String checkEncoded) { if (checkEncoded == null) { if (V)/*from w w w. j av a 2s.c o m*/ Log.v(TAG, " Decode Invalid Input"); return null; } if (checkEncoded != null && (checkEncoded.contains("=?") == false)) { if (V) Log.v(TAG, " Decode NotRequired" + checkEncoded); return checkEncoded; } int begin = checkEncoded.indexOf("=?", 0); int endScan = begin + 2; if (begin != -1) { int qm1 = checkEncoded.indexOf('?', endScan + 2); int qm2 = checkEncoded.indexOf('?', qm1 + 1); if (qm2 != -1) { endScan = qm2 + 1; } } int end = begin == -1 ? -1 : checkEncoded.indexOf("?=", endScan); if (end == -1) return checkEncoded; checkEncoded = checkEncoded.substring((endScan - 1), (end + 1)); // TODO: Handle encoded words as defined by MIME standard RFC 2047 // Encoded words will have the form =?charset?enc?Encoded word?= where // enc is either 'Q' or 'q' for quoted-printable and 'B' or 'b' for Base64 QuotedPrintableCodec qpDecode = new QuotedPrintableCodec("UTF-8"); String decoded = null; try { decoded = qpDecode.decode(checkEncoded); } catch (DecoderException e) { if (V) Log.v(TAG, "decode exception"); return checkEncoded; } if (decoded == null) { return checkEncoded; } return decoded; }
From source file:org.callimachusproject.xproc.DecodeTextStep.java
private String decodeText(XdmNode source_read) throws UnsupportedEncodingException, DecoderException { String text = extractText(source_read); if ("base64".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); }//w w w . j a v a2s.co m byte[] decoded = Base64.decodeBase64(text); return new String(decoded, charset); } else if ("base32".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } byte[] decoded = new Base32().decode(text); return new String(decoded, charset); } else if ("hex".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } byte[] decoded = Hex.decodeHex(text.toCharArray()); return new String(decoded, charset); } else if ("binary".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } byte[] decoded = BinaryCodec.fromAscii(text.toCharArray()); return new String(decoded, charset); } else if ("quoted-printable".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } return new QuotedPrintableCodec(charset).decode(text); } else if ("www-form-urlencoded".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } return new URLCodec(charset).decode(text); } else if (encoding != null && encoding.length() != 0) { throw new XProcException(step.getNode(), "Unexpected encoding: " + encoding); } else { return text; } }
From source file:org.callimachusproject.xproc.DeserializeCascadingStyleSheetStep.java
private String decodeText(XdmNode doc) throws UnsupportedEncodingException, DecoderException { String text = extractText(doc); if ("base64".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); }/*from w w w . jav a 2 s . c om*/ byte[] decoded = Base64.decodeBase64(text); return new String(decoded, charset); } else if ("base32".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } byte[] decoded = new Base32().decode(text); return new String(decoded, charset); } else if ("hex".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } byte[] decoded = Hex.decodeHex(text.toCharArray()); return new String(decoded, charset); } else if ("binary".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } byte[] decoded = BinaryCodec.fromAscii(text.toCharArray()); return new String(decoded, charset); } else if ("quoted-printable".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } return new QuotedPrintableCodec(charset).decode(text); } else if ("www-form-urlencoded".equals(encoding)) { if (charset == null) { throw XProcException.stepError(10); } return new URLCodec(charset).decode(text); } else if (encoding != null && encoding.length() != 0) { throw new XProcException(step.getNode(), "Unexpected encoding: " + encoding); } else { return text; } }