Package org.apache.poi.hwpf.model

Examples of org.apache.poi.hwpf.model.TextPiece


    Iterator<TextPiece> textIt = textPieces.iterator();

    int length = 0;
    while(textIt.hasNext())
    {
      TextPiece tp = textIt.next();
      length += tp.characterLength();
    }
    return length;
  }
View Full Code Here


  public String getTextFromPieces() {
      StringBuffer textBuf = new StringBuffer();
     
      Iterator textPieces = doc.getTextTable().getTextPieces().iterator();
      while (textPieces.hasNext()) {
        TextPiece piece = (TextPiece) textPieces.next();

        String encoding = "Cp1252";
        if (piece.isUnicode()) {
          encoding = "UTF-16LE";
        }
        try {
          String text = new String(piece.getRawBytes(), encoding);
          textBuf.append(text);
        } catch(UnsupportedEncodingException e) {
          throw new InternalError("Standard Encoding " + encoding + " not found, JVM broken");
        }
      }
View Full Code Here

  initText();

  for (int i = _textStart; i < _textEnd; i++)
  {
    TextPiece piece = (TextPiece)_text.get(i);
    if (piece.isUnicode())
      return true;
  }

  return false;
  }
View Full Code Here

    StringBuffer sb = new StringBuffer();

    for (int x = _textStart; x < _textEnd; x++)
    {
      TextPiece piece = (TextPiece)_text.get(x);
     
      // Figure out where in this piece the text
      //  we're after lives
      int rStart = 0;
      int rEnd = piece.characterLength();
      if(_start > piece.getStart()) {
        rStart = _start - piece.getStart();
      }
      if(_end < piece.getEnd()) {
        rEnd -= (piece.getEnd() - _end);
      }
     
      // Luckily TextPieces work in characters, so we don't
      //  need to worry about unicode here
      sb.append(piece.substring(rStart, rEnd));
    }
    return sb.toString();
  }
View Full Code Here

  public CharacterRun insertBefore(String text)
    //throws UnsupportedEncodingException
  {
    initAll();

    TextPiece tp = (TextPiece)_text.get(_textStart);
    StringBuffer sb = (StringBuffer)tp.getStringBuffer();

    // Since this is the first item in our list, it is safe to assume that
    // _start >= tp.getStart()
    int insertIndex = _start - tp.getStart();
    sb.insert(insertIndex, text);

    int adjustedLength = _doc.getTextTable().adjustForInsert(_textStart, text.length());
    _doc.getCharacterTable().adjustForInsert(_charStart, adjustedLength);
    _doc.getParagraphTable().adjustForInsert(_parStart, adjustedLength);
View Full Code Here

  public CharacterRun insertAfter(String text)
  {
    initAll();

    int listIndex = _textEnd - 1;
    TextPiece tp = (TextPiece)_text.get(listIndex);
    StringBuffer sb = (StringBuffer)tp.getStringBuffer();

    int insertIndex = _end - tp.getStart();

    if (tp.getStringBuffer().charAt(_end - 1) == '\r' && text.charAt(0) != '\u0007')
    {
      insertIndex--;
    }
    sb.insert(insertIndex, text);
    int adjustedLength = _doc.getTextTable().adjustForInsert(listIndex, text.length());
View Full Code Here

      //System.err.println("Section " + x + " is now " + sepx.getStart() + " -> " + sepx.getEnd());
    }
   
    for (int x = _textStart; x < numTextPieces; x++)
    {
      TextPiece piece = (TextPiece)_text.get(x);
      piece.adjustForDelete(_start, _end - _start);
    }

  // update the FIB.CCPText + friends field
  adjustFIB(-(_end - _start));
  }
View Full Code Here

    public void testExtractFromTextPieces() throws Exception {
      StringBuffer textBuf = new StringBuffer();
     
      Iterator textPieces = doc.getTextTable().getTextPieces().iterator();
      while (textPieces.hasNext()) {
        TextPiece piece = (TextPiece) textPieces.next();

        String encoding = "Cp1252";
        if (piece.isUnicode()) {
          encoding = "UTF-16LE";
        }
        String text = new String(piece.getRawBytes(), encoding);
        textBuf.append(text);
      }
     
      StringBuffer exp = new StringBuffer();
      for(int i=0; i<p_text.length; i++) {
View Full Code Here

  public boolean usesUnicode() {

    initText();

    for (int i = _textStart; i < _textEnd; i++) {
      TextPiece piece = _text.get(i);
      if (piece.isUnicode())
        return true;
    }

    return false;
  }
View Full Code Here

    initText();

    StringBuffer sb = new StringBuffer();

    for (int x = _textStart; x < _textEnd; x++) {
      TextPiece piece = _text.get(x);

      // Figure out where in this piece the text
      // we're after lives
      int rStart = 0;
      int rEnd = piece.characterLength();
      if (_start > piece.getStart()) {
        rStart = _start - piece.getStart();
      }
      if (_end < piece.getEnd()) {
        rEnd -= (piece.getEnd() - _end);
      }

      // Luckily TextPieces work in characters, so we don't
      // need to worry about unicode here
      sb.append(piece.substring(rStart, rEnd));
    }
    return sb.toString();
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.hwpf.model.TextPiece

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.