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.

License.java 4.0KB

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