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.

ConserveMemoryTestCase.java 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.apache.fop.render;
  18. import java.io.ByteArrayInputStream;
  19. import java.io.ByteArrayOutputStream;
  20. import java.io.File;
  21. import javax.xml.transform.Result;
  22. import javax.xml.transform.Source;
  23. import javax.xml.transform.Transformer;
  24. import javax.xml.transform.TransformerException;
  25. import javax.xml.transform.TransformerFactory;
  26. import javax.xml.transform.sax.SAXResult;
  27. import javax.xml.transform.stream.StreamSource;
  28. import org.junit.Test;
  29. import org.xml.sax.SAXException;
  30. import org.apache.fop.apps.FOUserAgent;
  31. import org.apache.fop.apps.Fop;
  32. import org.apache.fop.apps.FopFactory;
  33. public class ConserveMemoryTestCase {
  34. @Test
  35. public void testLink() throws TransformerException, SAXException {
  36. String fo = "<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">\n"
  37. + " <fo:layout-master-set>\n"
  38. + " <fo:simple-page-master master-name=\"simple\" page-height=\"27.9cm\" page-width=\"21.6cm\">\n"
  39. + " <fo:region-body />\n"
  40. + " </fo:simple-page-master>\n"
  41. + " </fo:layout-master-set>\n"
  42. + " <fo:page-sequence master-reference=\"simple\">\n"
  43. + " <fo:flow flow-name=\"xsl-region-body\">\n"
  44. + " <fo:block><fo:basic-link internal-destination=\"a\">a</fo:basic-link></fo:block>\n"
  45. + " </fo:flow>\n"
  46. + " </fo:page-sequence>\n"
  47. + "</fo:root>";
  48. foToOutput(fo);
  49. }
  50. private void foToOutput(String fo) throws SAXException, TransformerException {
  51. FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
  52. FOUserAgent userAgent = fopFactory.newFOUserAgent();
  53. userAgent.setConserveMemoryPolicy(true);
  54. Fop fop = fopFactory.newFop("application/pdf", userAgent, new ByteArrayOutputStream());
  55. Transformer transformer = TransformerFactory.newInstance().newTransformer();
  56. Source src = new StreamSource(new ByteArrayInputStream(fo.getBytes()));
  57. Result res = new SAXResult(fop.getDefaultHandler());
  58. transformer.transform(src, res);
  59. }
  60. }