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.

SLCommonUtils.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.sl;
  20. import java.io.IOException;
  21. import java.io.InputStream;
  22. import org.apache.poi.POIDataSamples;
  23. import org.apache.poi.sl.usermodel.SlideShow;
  24. import org.apache.poi.sl.usermodel.SlideShowFactory;
  25. public class SLCommonUtils {
  26. private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
  27. /** a generic way to open a sample slideshow document **/
  28. public static SlideShow<?,?> openSampleSlideshow(String sampleName) throws IOException {
  29. InputStream is = _slTests.openResourceAsStream(sampleName);
  30. try {
  31. return SlideShowFactory.create(is);
  32. } catch (Exception e) {
  33. throw new RuntimeException(e);
  34. } finally {
  35. is.close();
  36. }
  37. }
  38. /**
  39. * Tests, if the scratchpad classes are on the classpath
  40. *
  41. * @return true, if only xslf is on the classpath, and false, if both classpaths
  42. * (XSLF and HSLF) can be used/referenced
  43. */
  44. public static boolean xslfOnly() {
  45. try {
  46. Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow");
  47. return false;
  48. } catch (Exception e) {
  49. return true;
  50. }
  51. }
  52. }