Examples of TextPiece


Examples of org.apache.poi.hdf.model.hdftypes.TextPiece

                filePos /= 2;
            }
            int totLength = LittleEndian.getInt(_tableBuffer, pos + (x + 1) * 4) -
                    LittleEndian.getInt(_tableBuffer, pos + (x * 4));

            TextPiece piece = new TextPiece(filePos, totLength, unicode);
            _listener.text(piece);
        }
    }
View Full Code Here

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

  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.usesUnicode()) {
          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

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

  initText();

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

  return false;
  }
View Full Code Here

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

    StringBuffer sb = new StringBuffer();

    for (int x = _textStart; x < _textEnd; x++)
    {
      TextPiece piece = (TextPiece)_text.get(x);
      int start = _start > piece.getStart() ? _start - piece.getStart() : 0;
      int end = _end <= piece.getEnd() ? _end - piece.getStart() : piece.getEnd() - piece.getStart();

      if(piece.usesUnicode()) // convert the byte pointers to char pointers
      {
        start/=2;
        end/=2;
      }
      sb.append(piece.getStringBuffer().substring(start, end));
    }
    return sb.toString();
  }
View Full Code Here

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

  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();
  if (tp.usesUnicode())
    insertIndex /= 2;
    sb.insert(insertIndex, text);

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

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

  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

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

      sepx.adjustForDelete(_start, _end - _start);
    }
   
    for (int x = _textStart; x < numTextPieces; x++)
    {
      TextPiece piece = (TextPiece)_text.get(x);
      piece.adjustForDelete(_start, _end - _start);
    }

  // update the FIB.CCPText field
  if (usesUnicode())
    adjustFIB(-((_end - _start) / 2));
View Full Code Here

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

    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.usesUnicode()) {
          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

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

        List textRuns = cbt.getTextRuns();
        Iterator runIt = textRuns.iterator();
        Iterator textIt = textPieces.iterator();

        TextPiece currentPiece = (TextPiece)textIt.next();
        int currentTextStart = currentPiece.getStart();
        int currentTextEnd = currentPiece.getEnd();

        WordTextBuffer finalTextBuf = new WordTextBuffer(appendable);

        // iterate through all text runs extract the text only if they haven't been
        // deleted
        while (runIt.hasNext()) {
            CHPX chpx = (CHPX)runIt.next();
            boolean deleted = isDeleted(chpx.getGrpprl());
            if (deleted) {
                continue;
            }

            int runStart = chpx.getStart();
            int runEnd = chpx.getEnd();

            while (runStart >= currentTextEnd) {
                currentPiece = (TextPiece) textIt.next ();
                currentTextStart = currentPiece.getStart ();
                currentTextEnd = currentPiece.getEnd ();
            }

            if (runEnd < currentTextEnd) {
                String str = currentPiece.substring(runStart - currentTextStart, runEnd - currentTextStart);
                finalTextBuf.append(str);
            } else if (runEnd > currentTextEnd) {
                while (runEnd > currentTextEnd) {
                    String str = currentPiece.substring(runStart - currentTextStart,
                            currentTextEnd - currentTextStart);
                    finalTextBuf.append(str);
                    if (textIt.hasNext()) {
                        currentPiece = (TextPiece) textIt.next ();
                        currentTextStart = currentPiece.getStart ();
                        runStart = currentTextStart;
                        currentTextEnd = currentPiece.getEnd ();
                    } else {
                        return;
                    }
                }
                String str = currentPiece.substring(0, runEnd - currentTextStart);
                finalTextBuf.append(str);
            } else {
                String str = currentPiece.substring(runStart - currentTextStart, runEnd - currentTextStart);
                if (textIt.hasNext()) {
                    currentPiece = (TextPiece) textIt.next();
                    currentTextStart = currentPiece.getStart();
                    currentTextEnd = currentPiece.getEnd();
                }
                finalTextBuf.append(str);
            }
        }
    }
View Full Code Here

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

    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
TOP
Copyright © 2018 www.massapi.com. 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.