Methods Summary |
---|
protected void | closeOutputStream()
if ( writer != null ){
writer.flush();
writer.close();
writer = null;
}
|
protected java.lang.String | encodeBytes(byte[] bytes)
String data = ByteFormatter.nicePrint( bytes, true );
return( data );
/*
try{
return( URLEncoder.encode(new String( bytes, Constants.DEFAULT_ENCODING ), Constants.DEFAULT_ENCODING));
}catch( UnsupportedEncodingException e ){
throw( new TOTorrentException( "TOTorrentXMLSerialiser: unsupported encoding for '" + new String(bytes) + "'",
TOTorrentException.RT_UNSUPPORTED_ENCODING));
}
*/
|
public static java.lang.String | escapeXML(java.lang.String str)
if ( str == null ){
return( "" );
}
str = str.replaceAll( "&", "&" );
str = str.replaceAll( ">", ">" );
str = str.replaceAll( "<", "<" );
str = str.replaceAll( "\"", """ );
str = str.replaceAll( "--", "--" );
return( str );
|
protected void | exdent()
if ( current_indent_string.length() >= INDENT_AMOUNT ){
current_indent_string = current_indent_string.substring(0,current_indent_string.length()-INDENT_AMOUNT);
}else{
current_indent_string = "";
}
|
protected void | flushOutputStream()
if ( writer != null ){
writer.flush();
}
|
protected java.lang.String | getUTF(byte[] bytes)
try{
return( new String(bytes,Constants.DEFAULT_ENCODING));
}catch( UnsupportedEncodingException e ){
Debug.printStackTrace( e );
return( "" );
}
|
protected void | indent()
for (int i=0;i<INDENT_AMOUNT;i++){
current_indent_string += " ";
}
|
protected void | resetIndent()
current_indent_string = "";
|
protected void | setGenericSimple(boolean simple)
generic_simple = simple;
|
protected void | setOutputStream(java.io.OutputStream _output_stream)
try{
writer = new PrintWriter( new OutputStreamWriter(_output_stream , Constants.DEFAULT_ENCODING ));
}catch( UnsupportedEncodingException e ){
Debug.printStackTrace( e );
writer = new PrintWriter( _output_stream );
}
|
protected void | setOutputWriter(java.io.Writer _writer)
if ( _writer instanceof PrintWriter ){
writer = (PrintWriter)_writer;
}else{
writer = new PrintWriter( _writer );
}
|
public static java.lang.String | unescapeXML(java.lang.String str)
if ( str == null ){
return( "" );
}
str = str.replaceAll( ">", ">" );
str = str.replaceAll( "<", "<" );
str = str.replaceAll( """, "\"" );
str = str.replaceAll( "--", "--" );
str = str.replaceAll( "&", "&" );
return( str );
|
protected void | writeGeneric(java.lang.Object obj)
if ( obj instanceof Map ){
writeGeneric((Map)obj);
}else if( obj instanceof List ){
writeGeneric((List)obj);
}else if ( obj instanceof byte[] ){
writeGeneric((byte[])obj);
}else{
writeGeneric((Long)obj);
}
|
protected void | writeGeneric(java.util.Map map)
writeLineRaw( "<MAP>" );
try{
indent();
Iterator it = map.keySet().iterator();
while(it.hasNext()){
String key = (String)it.next();
writeGenericMapEntry( key, map.get( key ));
}
}finally{
exdent();
}
writeLineRaw( "</MAP>" );
|
protected void | writeGeneric(java.util.List list)
writeLineRaw( "<LIST>" );
try{
indent();
for (int i=0;i<list.size();i++){
writeGeneric( list.get(i));
}
}finally{
exdent();
}
writeLineRaw( "</LIST>" );
|
protected void | writeGeneric(byte[] bytes)
if ( generic_simple ){
try{
writeLineRaw( escapeXML( new String(bytes, "UTF-8" )));
}catch( Throwable e ){
e.printStackTrace();
}
}else{
writeTag( "BYTES", encodeBytes( bytes ));
}
|
protected void | writeGeneric(java.lang.Long l)
if ( generic_simple ){
writeLineRaw( l.toString());
}else{
writeTag( "LONG", ""+l );
}
|
protected void | writeGenericMapEntry(java.lang.String name, java.lang.Object value)
if ( generic_simple ){
name = name.replace(' ", '_" ).toUpperCase();
writeLineRaw( "<" + name + ">" );
try{
indent();
writeGeneric( value );
}finally{
exdent();
}
writeLineRaw( "</" + name + ">" );
}else{
writeLineRaw( "<KEY name=\"" + escapeXML( name ) + "\">");
try{
indent();
writeGeneric( value );
}finally{
exdent();
}
writeLineRaw( "</KEY>");
}
|
protected void | writeLineEscaped(java.lang.String str)
writer.println( current_indent_string + escapeXML(str));
|
protected void | writeLineRaw(java.lang.String str)
writer.println( current_indent_string + str );
|
protected void | writeLocalisableTag(java.lang.String tag, byte[] content)
boolean use_bytes = true;
String utf_string = null;
try{
utf_string = new String(content,Constants.DEFAULT_ENCODING);
if ( Arrays.equals(
content,
utf_string.getBytes( Constants.DEFAULT_ENCODING))){
use_bytes = false;
}
}catch( UnsupportedEncodingException e ){
}
writeLineRaw( "<" + tag + " encoding=\""+(use_bytes?"bytes":"utf8") + "\">" +
(use_bytes?encodeBytes( content ):escapeXML(utf_string)) + "</" + tag + ">" );
|
protected void | writeTag(java.lang.String tag, byte[] content)
writeLineRaw( "<" + tag + ">" + encodeBytes( content ) + "</" + tag + ">" );
|
protected void | writeTag(java.lang.String tag, java.lang.String content)
writeLineRaw( "<" + tag + ">" + escapeXML( content ) + "</" + tag + ">" );
|
protected void | writeTag(java.lang.String tag, long content)
writeLineRaw( "<" + tag + ">" + content + "</" + tag + ">" );
|
protected void | writeTag(java.lang.String tag, boolean content)
writeLineRaw( "<" + tag + ">" + (content?"YES":"NO") + "</" + tag + ">" );
|