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.

TextBodyPropertyFetcher.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.xslf.model;
  20. import static org.apache.poi.ooxml.util.XPathHelper.selectProperty;
  21. import static org.apache.poi.xslf.model.ParagraphPropertyFetcher.DML_NS;
  22. import static org.apache.poi.xslf.model.ParagraphPropertyFetcher.PML_NS;
  23. import javax.xml.namespace.QName;
  24. import javax.xml.stream.XMLStreamReader;
  25. import org.apache.poi.xslf.usermodel.XSLFShape;
  26. import org.apache.xmlbeans.XmlException;
  27. import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
  28. import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties;
  29. public abstract class TextBodyPropertyFetcher<T> extends PropertyFetcher<T> {
  30. private static final QName[] TX_BODY = { new QName(PML_NS, "txBody") };
  31. private static final QName[] BODY_PR = { new QName(DML_NS, "bodyPr") };
  32. public boolean fetch(XSLFShape shape) {
  33. CTTextBodyProperties props = null;
  34. try {
  35. props = selectProperty(shape.getXmlObject(),
  36. CTTextBodyProperties.class, TextBodyPropertyFetcher::parse, TX_BODY, BODY_PR);
  37. return (props != null) && fetch(props);
  38. } catch (XmlException e) {
  39. return false;
  40. }
  41. }
  42. private static CTTextBodyProperties parse(XMLStreamReader reader) throws XmlException {
  43. CTTextBody body = CTTextBody.Factory.parse(reader);
  44. return (body != null) ? body.getBodyPr() : null;
  45. }
  46. public abstract boolean fetch(CTTextBodyProperties props);
  47. }