Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.util;
  19. import java.io.IOException;
  20. import java.io.StringWriter;
  21. import java.io.Writer;
  22. /**
  23. * Write the Apache license text in various forms
  24. */
  25. public final class License {
  26. /**
  27. * The Apache license text as a string array
  28. */
  29. public static final String[] license
  30. = {"Licensed to the Apache Software Foundation (ASF) under one or more",
  31. "contributor license agreements. See the NOTICE file distributed with",
  32. "this work for additional information regarding copyright ownership.",
  33. "The ASF licenses this file to You under the Apache License, Version 2.0",
  34. "(the \"License\"); you may not use this file except in compliance with",
  35. "the License. You may obtain a copy of the License at",
  36. "",
  37. " http://www.apache.org/licenses/LICENSE-2.0",
  38. "",
  39. "Unless required by applicable law or agreed to in writing, software",
  40. "distributed under the License is distributed on an \"AS IS\" BASIS,",
  41. "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.",
  42. "See the License for the specific language governing permissions and",
  43. "limitations under the License."
  44. };
  45. /**
  46. * The subversion Id keyword line
  47. */
  48. public static final String id = "$Id$";
  49. /**
  50. * Calculate the maximum line length in the Apache license text
  51. * for use in formatting
  52. */
  53. private static int MAX_LENGTH;
  54. static {
  55. int j = 0;
  56. for (int i = 0; i < license.length; ++i) {
  57. if (j < license[i].length()) {
  58. j = license[i].length();
  59. }
  60. }
  61. MAX_LENGTH = j;
  62. }
  63. /**
  64. * Write the Apache license text as commented lines for a Java file
  65. * @param w the writer which writes the comment
  66. * @throws IOException if the write operation fails
  67. */
  68. public static void writeJavaLicenseId(Writer w) throws IOException {
  69. w.write("/*\n");
  70. for (int i = 0; i < license.length; ++i) {
  71. if (license[i].equals("")) {
  72. w.write(" *\n");
  73. } else {
  74. w.write(" * " + license[i] + "\n");
  75. }
  76. }
  77. w.write(" */\n");
  78. w.write("\n");
  79. w.write("/* " + id + " */\n");
  80. }
  81. /**
  82. * Write the Apache license text as commented lines for an XML file
  83. * @param w the writer which writes the comment
  84. * @throws IOException if the write operation fails
  85. */
  86. public static void writeXMLLicenseId(Writer w) throws IOException {
  87. for (int i = 0; i < license.length; ++i) {
  88. w.write(String.format("<!-- %-" + MAX_LENGTH + "s -->\n", new Object[] {license[i]}));
  89. }
  90. w.write("\n");
  91. w.write("<!-- " + id + " -->\n");
  92. }
  93. /**
  94. * For testing purposes
  95. * @param args optional, --java or --xml
  96. * @throws IOException if the write operation fails
  97. */
  98. public static void main(String[] args) throws IOException {
  99. StringWriter w = new StringWriter();
  100. if (args.length == 0 || args[0].equals("--java")) {
  101. writeJavaLicenseId(w);
  102. } else if (args[0].equals("--xml")) {
  103. writeXMLLicenseId(w);
  104. }
  105. System.out.println(w.toString());
  106. }
  107. }