Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

PDFEmbeddedFiles.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. /* $Id$ */
  18. package org.apache.fop.pdf;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import java.io.Writer;
  22. import java.util.Iterator;
  23. import java.util.Map;
  24. import java.util.SortedMap;
  25. /**
  26. * Class representing an /EmbeddedFiles dictionary object (name tree).
  27. */
  28. public class PDFEmbeddedFiles extends PDFNameTreeNode {
  29. /**
  30. * Create a /EmbeddedFiles dictionary.
  31. */
  32. public PDFEmbeddedFiles() {
  33. super();
  34. }
  35. /** {@inheritDoc} */
  36. protected void writeDictionary(OutputStream out, Writer writer) throws IOException {
  37. sortNames(); //Sort the names before writing them out
  38. super.writeDictionary(out, writer);
  39. }
  40. private void sortNames() {
  41. PDFArray names = getNames();
  42. SortedMap map = new java.util.TreeMap();
  43. int i = 0;
  44. int c = names.length();
  45. while (i < c) {
  46. Comparable key = (Comparable)names.get(i++); //Key must be a Comparable for sorting
  47. Object value = names.get(i++);
  48. map.put(key, value);
  49. }
  50. names.clear();
  51. Iterator iter = map.entrySet().iterator();
  52. while (iter.hasNext()) {
  53. Map.Entry entry = (Map.Entry)iter.next();
  54. names.add(entry.getKey());
  55. names.add(entry.getValue());
  56. }
  57. }
  58. }