001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.config.sys;
018:
019: import java.io.PrintWriter;
020: import java.util.Map;
021: import java.util.ArrayList;
022:
023: import org.apache.openejb.OpenEJBException;
024: import org.apache.openejb.util.SuperProperties;
025:
026: public class WikiGenerator {
027: public static void main(String[] args) throws Exception {
028: System.out.println();
029: System.out.println();
030: System.out.println();
031:
032: new WikiGenerator("org.apache.openejb")
033: .generate(new PrintWriter(System.out));
034:
035: System.out.println();
036: System.out.println();
037: System.out.println();
038: }
039:
040: protected ServicesJar servicesJar;
041:
042: public WikiGenerator(String providerName) throws OpenEJBException {
043: servicesJar = JaxbOpenejb.readServicesJar(providerName);
044: }
045:
046: public WikiGenerator(ServicesJar servicesJar) {
047: this .servicesJar = servicesJar;
048: }
049:
050: public void generate(PrintWriter out) throws Exception {
051:
052: // generate containers
053: out.println("{anchor: containers}");
054: out.println("h1. Containers");
055: for (ServiceProvider provider : servicesJar
056: .getServiceProvider()) {
057: if ("Container".equals(provider.getService())) {
058: generateService(out, provider, "container");
059: }
060: }
061: out.println();
062:
063: out.println("{anchor: resources}");
064: out.println("h1. Resources");
065: ArrayList<String> seen = new ArrayList<String>();
066: for (ServiceProvider provider : servicesJar
067: .getServiceProvider()) {
068: if ("Resource".equals(provider.getService())) {
069:
070: if (seen.containsAll(provider.getTypes()))
071: continue;
072:
073: generateService(out, provider, "resource");
074:
075: seen.addAll(provider.getTypes());
076: }
077: }
078: out.println();
079: out.flush();
080: }
081:
082: private void generateService(PrintWriter out,
083: ServiceProvider provider, String serviceType) {
084: out.println("{anchor:" + provider.getId() + "-" + serviceType
085: + "}");
086: String type = provider.getTypes().get(0);
087: out.println("h2. " + type);
088: out.println("Declarable in openejb.xml via");
089: out.println("{code:xml}");
090: out.println("<" + provider.getService() + " id=\"Foo\" type=\""
091: + type + "\">");
092: out.println("</" + provider.getService() + ">");
093: out.println("{code}");
094:
095: out.println("Declarable in properties via");
096: out.println("{panel}");
097: out.println("Foo = new://" + provider.getService() + "?type="
098: + type + "");
099: out.println("{panel}");
100:
101: // out.println(" class: " + provider.getClassName());
102: //
103: // if (provider.getFactoryName() != null) {
104: // out.println(" factory-method: " + provider.getFactoryName());
105: // }
106:
107: SuperProperties properties = (SuperProperties) provider
108: .getProperties();
109: if (properties.size() > 0) {
110: out.println("Supports the following properties");
111: out.println(" || Property Name || Description ||");
112:
113: for (Object key : properties.keySet()) {
114: if (key instanceof String) {
115: String name = (String) key;
116:
117: Map<String, String> attributes = properties
118: .getAttributes(name);
119: if (!attributes.containsKey("hidden")) {
120: String value = properties.getProperty(name);
121: String comment = properties.getComment(name);
122:
123: comment = scrubText(comment);
124:
125: if (value != null && value.length() > 0) {
126: if (comment.length() > 0) {
127: comment += "\\\\ \\\\ ";
128: }
129: comment += "Default value is _"
130: + scrubText(value) + "_.|";
131: }
132:
133: if (comment.length() == 0)
134: comment = "No description.";
135:
136: out.println(" | " + name + " | " + comment
137: + "|");
138: }
139: }
140: }
141: } else {
142: out.println("No properties.");
143: }
144: out.println();
145: }
146:
147: private String scrubText(String text) {
148: if (text == null)
149: text = "";
150: text = text.replaceAll("\r?\n", "\\\\\\\\ ");
151: text = text.replaceAll("\\*", "\\\\*");
152: text = text.replaceAll("\\_", "\\\\_");
153: text = text.replaceAll("\\?", "\\\\?");
154: text = text.replaceAll("\\-", "\\\\-");
155: text = text.replaceAll("\\^", "\\\\^");
156: text = text.replaceAll("\\~", "\\\\~");
157: text = text.replaceAll("\\#", "\\\\#");
158: text = text.replaceAll("\\[", "\\\\[");
159: text = text.replaceAll("\\]", "\\\\]");
160: text = text.replaceAll("\\{", "\\\\{");
161: text = text.replaceAll("\\}", "\\\\}");
162: text = text.replaceAll("\\(", "\\\\(");
163: text = text.replaceAll("\\)", "\\\\)");
164: text = text.replaceAll("http:", "{html}http:{html}");
165: text = text.replaceAll("file:", "{html}file:{html}");
166: text = text.replaceAll(" ",
167: "{html} {html}");
168: text = text.replaceAll(" ", "{html} {html}");
169: text = text.replaceAll(" ", "{html} {html}");
170: return text;
171: }
172: }
|