Java 类com.lowagie.text.pdf.PRTokeniser 实例源码

项目:itext2    文件:Utilities.java   
/**
 * Unescapes an URL. All the "%xx" are replaced by the 'xx' hex char value.
 * @param src the url to unescape
 * @return the unescaped value
 */    
public static String unEscapeURL(String src) {
    StringBuffer bf = new StringBuffer();
    char[] s = src.toCharArray();
    for (int k = 0; k < s.length; ++k) {
        char c = s[k];
        if (c == '%') {
            if (k + 2 >= s.length) {
                bf.append(c);
                continue;
            }
            int a0 = PRTokeniser.getHex(s[k + 1]);
            int a1 = PRTokeniser.getHex(s[k + 2]);
            if (a0 < 0 || a1 < 0) {
                bf.append(c);
                continue;
            }
            bf.append((char)(a0 * 16 + a1));
            k += 2;
        }
        else
            bf.append(c);
    }
    return bf.toString();
}
项目:DroidText    文件:PdfContentStreamProcessor.java   
/**
 * Processes PDF syntax
 * @param contentBytes  the bytes of a content stream
 * @param resources     the resources that come with the content stream
 */
public void processContent(byte[] contentBytes, PdfDictionary resources){

    reset();
    this.resources = resources;
    try {
        PdfContentParser ps = new PdfContentParser(new PRTokeniser(contentBytes));
        ArrayList operands = new ArrayList();
        while (ps.parse(operands).size() > 0){
            PdfLiteral operator = (PdfLiteral)operands.get(operands.size()-1);
            invokeOperator(operator, operands);
        }

    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }    

}
项目:DroidText    文件:Utilities.java   
/**
 * Unescapes an URL. All the "%xx" are replaced by the 'xx' hex char value.
 * @param src the url to unescape
 * @return the unescaped value
 */    
public static String unEscapeURL(String src) {
    StringBuffer bf = new StringBuffer();
    char[] s = src.toCharArray();
    for (int k = 0; k < s.length; ++k) {
        char c = s[k];
        if (c == '%') {
            if (k + 2 >= s.length) {
                bf.append(c);
                continue;
            }
            int a0 = PRTokeniser.getHex(s[k + 1]);
            int a1 = PRTokeniser.getHex(s[k + 2]);
            if (a0 < 0 || a1 < 0) {
                bf.append(c);
                continue;
            }
            bf.append((char)(a0 * 16 + a1));
            k += 2;
        }
        else
            bf.append(c);
    }
    return bf.toString();
}
项目:itext2    文件:PdfContentStreamProcessor.java   
/**
    * Processes PDF syntax
    * @param contentBytes   the bytes of a content stream
    * @param resources      the resources that come with the content stream
    */
public void processContent(byte[] contentBytes, PdfDictionary resources) {
    this.resources.push(resources);
    try {
        PdfContentParser ps = new PdfContentParser(new PRTokeniser(contentBytes));
        ArrayList operands = new ArrayList();
        while (ps.parse(operands).size() > 0) {
            PdfLiteral operator = (PdfLiteral) operands.get(operands.size() - 1);
            invokeOperator(operator, operands);
        }
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
    this.resources.pop();
}
项目:openeos    文件:OsgiTestCase.java   
public boolean findPdfString(PdfReader reader, String string) throws Exception {
    byte[] streamBytes = reader.getPageContent(1);
    LOG.debug("Finding string {} in pdf", string);
    PRTokeniser tokenizer = new PRTokeniser(new RandomAccessFileOrArray(streamBytes));
    while (tokenizer.nextToken()) {
        if (tokenizer.getTokenType() == PRTokeniser.TK_STRING) {
            LOG.debug("Found String in pdf: " + tokenizer.getStringValue());
            if (tokenizer.getStringValue().equals(string)) {
                return true;
            }
        }
    }
    return false;

}