You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ShapeTextVisitor.java 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package org.apache.poi.xdgf.usermodel.shape;
  2. import java.awt.geom.AffineTransform;
  3. import org.apache.poi.xdgf.usermodel.XDGFShape;
  4. /**
  5. * Only visits text nodes, accumulates text content into a string
  6. *
  7. * The text is returned in arbitrary order, with no regards to
  8. * the location of the text on the page. This may change in the
  9. * future.
  10. */
  11. public class ShapeTextVisitor extends ShapeVisitor {
  12. protected StringBuilder text = new StringBuilder();
  13. public static class TextAcceptor implements ShapeVisitorAcceptor {
  14. public boolean accept(XDGFShape shape) {
  15. return shape.hasText();
  16. }
  17. }
  18. protected ShapeVisitorAcceptor getAcceptor() {
  19. return new TextAcceptor();
  20. }
  21. public void visit(XDGFShape shape, AffineTransform globalTransform,
  22. int level) {
  23. text.append(shape.getText().getTextContent().trim());
  24. text.append('\n');
  25. }
  26. /**
  27. * Call this after visitation has completed
  28. */
  29. public String getText() {
  30. return text.toString();
  31. }
  32. }