org.jenkinsci.plugins.darcs
Class DarcsXmlSanitizer

java.lang.Object
  extended by org.jenkinsci.plugins.darcs.DarcsXmlSanitizer

 class DarcsXmlSanitizer
extends Object

Darcs XML Sanitizer. The output of "darcs changes --xml-output" might be invalid XML. Darcs treats the patch comments as binary blobs, and the changes command returns them as-is inside the XML structure, without ensuring that the encoding is consistent. If some of the patches in your repository were recorded on UTF-8 machines and others on e.g. ISO-8859 machines, the XML output will contain characters in both encodings. Some parsers (e.g. xerxes) choke on invalid characters in the XML input, so this sanitizer is designed to ensure that the encoding is consistent.

Author:
Ralph Lange

Nested Class Summary
private static class DarcsXmlSanitizer.State
          States which indicates where in the comment string we are.
 
Field Summary
private static List<String> ADDL_CHARSETS
           
private  List<CharsetDecoder> decoders
           
 
Constructor Summary
DarcsXmlSanitizer()
          Dedicated constructor.
 
Method Summary
 String cleanse(byte[] input)
          Cleanse the mixed encoding in the input byte array.
 String cleanse(File file)
           
private static int[] computeFailure(byte[] pattern)
          Computes the failure function using a bootstrapping process, where the pattern is matched against itself.
private static int positionAfterNext(byte[] data, int start, byte[] pattern)
           
private static int positionBeforeNext(byte[] data, int start, byte[] pattern)
          Knuth-Morris-Pratt pattern matching algorithm.
private  byte[] readFile(File file)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ADDL_CHARSETS

private static final List<String> ADDL_CHARSETS

decoders

private final List<CharsetDecoder> decoders
Constructor Detail

DarcsXmlSanitizer

public DarcsXmlSanitizer()
Dedicated constructor.

Method Detail

positionBeforeNext

private static int positionBeforeNext(byte[] data,
                                      int start,
                                      byte[] pattern)
Knuth-Morris-Pratt pattern matching algorithm.

Parameters:
data -
start -
pattern -
Returns:

positionAfterNext

private static int positionAfterNext(byte[] data,
                                     int start,
                                     byte[] pattern)
Parameters:
data -
start -
pattern -
Returns:

computeFailure

private static int[] computeFailure(byte[] pattern)
Computes the failure function using a bootstrapping process, where the pattern is matched against itself.

Parameters:
pattern -
Returns:

cleanse

public String cleanse(byte[] input)
Cleanse the mixed encoding in the input byte array.

Parameters:
input -
Returns:

cleanse

public String cleanse(File file)
               throws IOException
Parameters:
file -
Returns:
Throws:
IOException
See Also:
cleanse(byte[])

readFile

private byte[] readFile(File file)
                 throws IOException
Throws:
IOException


Copyright © 2004-2013 weltraumschaf.de. All Rights Reserved.