diff --git a/src/main/java/org/jaxws/stub2html/model/JavaLanguageVariable.java b/src/main/java/org/jaxws/stub2html/model/JavaLanguageVariable.java index 501b5d2..c075830 100644 --- a/src/main/java/org/jaxws/stub2html/model/JavaLanguageVariable.java +++ b/src/main/java/org/jaxws/stub2html/model/JavaLanguageVariable.java @@ -34,6 +34,8 @@ public class JavaLanguageVariable { */ private boolean header; + private String description; + public boolean isHeader() { return header; } @@ -80,4 +82,11 @@ public void setMultiOccurs(boolean multiOccurs) { this.multiOccurs = multiOccurs; } + public void setDescription(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } } diff --git a/src/main/java/org/jaxws/stub2html/model/Stub.java b/src/main/java/org/jaxws/stub2html/model/Stub.java index 6dbced6..c02361e 100644 --- a/src/main/java/org/jaxws/stub2html/model/Stub.java +++ b/src/main/java/org/jaxws/stub2html/model/Stub.java @@ -41,6 +41,7 @@ public class Stub { * if parent stub's type = Product, is it FunProduct or NotFunProduct? */ private Class subTypeOfParentStub; + private String description = "TODO"; public Stub getParentStub() { return parentStub; @@ -142,7 +143,7 @@ public String getDescription() { if (this.header) { return "In header"; } - return null; + return description; } @Override @@ -151,4 +152,7 @@ public String toString() { return "[Stub: " + type.getSimpleName() + "," + path + "]"; } + public void setStubDescription(String stubDescription) { + this.description = stubDescription; + } } diff --git a/src/main/java/org/jaxws/stub2html/model/WebMethodStubSet.java b/src/main/java/org/jaxws/stub2html/model/WebMethodStubSet.java index 8171f8b..67050f9 100644 --- a/src/main/java/org/jaxws/stub2html/model/WebMethodStubSet.java +++ b/src/main/java/org/jaxws/stub2html/model/WebMethodStubSet.java @@ -17,6 +17,7 @@ public class WebMethodStubSet { private List requestStubs = new ArrayList(); private Stub responseStub; private StubTypeTreeRepository stubTypeTreeRepository = new StubTypeTreeRepository(); + private String methodDescription; public String getMethodName() { return methodName; @@ -50,4 +51,11 @@ public boolean isInheritanceInvolved() { return !stubTypeTreeRepository.isEmpty(); } + public String getMethodDescription() { + return methodDescription; + } + + public void setMethodDescription(String methodDescription) { + this.methodDescription = methodDescription; + } } diff --git a/src/main/java/org/jaxws/stub2html/service/DescriptionLocatorRepository.java b/src/main/java/org/jaxws/stub2html/service/DescriptionLocatorRepository.java new file mode 100644 index 0000000..b4cc561 --- /dev/null +++ b/src/main/java/org/jaxws/stub2html/service/DescriptionLocatorRepository.java @@ -0,0 +1,121 @@ +package org.jaxws.stub2html.service; + +import org.jaxws.wsdl2html.ui.Wsdl2HtmlMain; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; + +public class DescriptionLocatorRepository { + private static DescriptionLocatorRepository instance = null; + private DescriptionLocatorRepository() {} + private List contents = new ArrayList(); + + public static synchronized DescriptionLocatorRepository getInstance() { + if (instance == null) instance = new DescriptionLocatorRepository(); + return instance; + } + + public String findDescriptionByMethod(Method method) { + if (contents.isEmpty()) { + loadContents(); + } + String descriptionFound = ""; + for (Description description : contents) { + if (description.getSymbol().contains(method.getName())) { + descriptionFound = description.getContent(); + break; + } + } + if (descriptionFound.isEmpty()) { + System.out.println("No doc found for: " + method.getName()); + } + return descriptionFound; + } + + public String findDescriptionByVariable(Method method, String name) { + if (contents.isEmpty()) { + loadContents(); + } + + String descriptionFound = ""; + for (Description description : contents) { + if (description.getSymbol().contains(method.getName() + "." + name)) { + descriptionFound = description.getContent(); + break; + } + } + if (descriptionFound.isEmpty()) { + System.out.println("No doc found for: " + method.getName() + "." + name); + } + return descriptionFound; + } + + public String getDescriptionByField(Field field) { + if (contents.isEmpty()) { + loadContents(); + } + + String descriptionFound = ""; + for (Description description : contents) { + if (description.getSymbol().contains(field.getDeclaringClass().getSimpleName() + "." + field.getName())) { + descriptionFound = description.getContent(); + break; + } + } + if (descriptionFound.isEmpty()) { + System.out.println("No doc found for: " + field.getDeclaringClass().getSimpleName() + ":" + field.getName()); + } + return descriptionFound; + } + + private void loadContents() { + File dir = new File(Wsdl2HtmlMain.getDescriptionsPath()); + File[] files = dir.listFiles(new FilenameFilter() { + public boolean accept(File dir, String filename) { + return filename.endsWith(".txt"); + } + }); + if (files == null) { + return; + } + for (File file : files) { + try { + String content = ""; + for (String allLines : Files.readAllLines(file.toPath(), Charset.defaultCharset())) { + content += allLines; + } + contents.add(new Description(file.getName(), content)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } + + + static class Description { + private final String symbol; + private final String content; + + public Description(String symbol, String content) { + this.symbol = symbol; + this.content = content; + } + + public String getSymbol() { + return symbol; + } + + public String getContent() { + return content; + } + } + +} diff --git a/src/main/java/org/jaxws/stub2html/service/JavaLanguageVariableFactory.java b/src/main/java/org/jaxws/stub2html/service/JavaLanguageVariableFactory.java index 8456f34..ddabf69 100644 --- a/src/main/java/org/jaxws/stub2html/service/JavaLanguageVariableFactory.java +++ b/src/main/java/org/jaxws/stub2html/service/JavaLanguageVariableFactory.java @@ -31,9 +31,11 @@ public static JavaLanguageVariable createVariableFromField(Field field) { XmlElement annotation = field.getAnnotation(XmlElement.class); if (annotation == null) { variable.setVariableName(getElementName(field)); + variable.setDescription(DescriptionLocatorRepository.getInstance().getDescriptionByField(field)); variable.setRequired(true); } else { variable.setVariableName(getVariableName(field, annotation)); + variable.setDescription(DescriptionLocatorRepository.getInstance().getDescriptionByField(field)); variable.setRequired(isVariableRequired(annotation)); } variable.setType(GenericsUtils.getFieldGenericType(field)); @@ -84,6 +86,7 @@ public static JavaLanguageVariable createVariableFromMethodReturn(Method method) } JavaLanguageVariable variable = new JavaLanguageVariable(); variable.setType(GenericsUtils.getMethodGenericReturnType(method)); + variable.setDescription(DescriptionLocatorRepository.getInstance().findDescriptionByVariable(method, webResultAnnotation.name())); variable.setVariableName(webResultAnnotation.name()); variable.setRequired(true); variable.setHeader(webResultAnnotation.header()); @@ -97,6 +100,7 @@ private static JavaLanguageVariable buildJavaVariableFromMethodParam(Method meth JavaLanguageVariable variable = new JavaLanguageVariable(); variable.setType(GenericsUtils.getMethodGenericParameterTypes(method, paramIndex)); variable.setVariableName(xmlAnnotation.name()); + variable.setDescription(DescriptionLocatorRepository.getInstance().findDescriptionByVariable(method, xmlAnnotation.name())); variable.setRequired(true); variable.setHeader(xmlAnnotation.header()); Class paramClass = method.getParameterTypes()[paramIndex]; diff --git a/src/main/java/org/jaxws/stub2html/service/Variable2Stub.java b/src/main/java/org/jaxws/stub2html/service/Variable2Stub.java index 4456c45..35a9a6a 100644 --- a/src/main/java/org/jaxws/stub2html/service/Variable2Stub.java +++ b/src/main/java/org/jaxws/stub2html/service/Variable2Stub.java @@ -28,6 +28,7 @@ public static Stub convertToStub(JavaLanguageVariable variable, Stub parentStub, Stub stub = new Stub(); stub.setParentStubRelation(parentStub); stub.setStubName(variable.getVariableName()); + stub.setStubDescription(variable.getDescription()); stub.setRequired(variable.isRequired()); stub.setHeader(variable.isHeader()); stub.setMultiOccurs(variable.isMultiOccurs()); diff --git a/src/main/java/org/jaxws/stub2html/service/WebMethodStubSetFactory.java b/src/main/java/org/jaxws/stub2html/service/WebMethodStubSetFactory.java index c26221f..1fa9923 100644 --- a/src/main/java/org/jaxws/stub2html/service/WebMethodStubSetFactory.java +++ b/src/main/java/org/jaxws/stub2html/service/WebMethodStubSetFactory.java @@ -20,6 +20,8 @@ public class WebMethodStubSetFactory { public static WebMethodStubSet createWebMethodStubSet(Method method) { WebMethodStubSet stubSet = new WebMethodStubSet(); stubSet.setMethodName(method.getName()); + stubSet.setMethodDescription(DescriptionLocatorRepository.getInstance().findDescriptionByMethod(method)); + addRequestStubs(method, stubSet); if (!Void.TYPE.equals(method.getReturnType())) { addResponseStub(method, stubSet); diff --git a/src/main/java/org/jaxws/stub2html/service/WebServiceStubSetFactory.java b/src/main/java/org/jaxws/stub2html/service/WebServiceStubSetFactory.java index 5c81b3b..94ee981 100644 --- a/src/main/java/org/jaxws/stub2html/service/WebServiceStubSetFactory.java +++ b/src/main/java/org/jaxws/stub2html/service/WebServiceStubSetFactory.java @@ -4,6 +4,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import javax.jws.WebMethod; @@ -21,6 +22,12 @@ public static WebServiceStubSet createWebServiceStubSet(Class webServiceClass List methods = getWebMethods(webServiceClass); WebServiceStubSet serviceStubs = new WebServiceStubSet(); serviceStubs.setWebServiceClass(webServiceClass); + methods.sort(new Comparator() { + @Override + public int compare(Method o1, Method o2) { + return o1.getName().compareTo(o2.getName()); + } + }); for (Method method : methods) { serviceStubs.addMethodStub(createWebMethodStubSet(method)); } diff --git a/src/main/java/org/jaxws/stub2html/view/freemarker/FreemarkerWebServiceDisplayer.java b/src/main/java/org/jaxws/stub2html/view/freemarker/FreemarkerWebServiceDisplayer.java index 1d1fbee..e5e562f 100644 --- a/src/main/java/org/jaxws/stub2html/view/freemarker/FreemarkerWebServiceDisplayer.java +++ b/src/main/java/org/jaxws/stub2html/view/freemarker/FreemarkerWebServiceDisplayer.java @@ -44,6 +44,7 @@ public String displayWebSerivce() { rootMap.put("stubOgnl", new DisplayStubOgnlPathMethodModel()); rootMap.put("stubType", new DisplayStubTypeMethodModel()); rootMap.put("className", new DisplayClassNameMethodModel()); + rootMap.put("description", new DisplayStubDescriptionMethodModel()); StringWriter out = new StringWriter(); template.process(rootMap, out); @@ -81,6 +82,16 @@ public Object exec(List arguments) throws TemplateModelException { } } + private final class DisplayStubDescriptionMethodModel implements TemplateMethodModelEx { + + @SuppressWarnings("rawtypes") + @Override + public Object exec(List arguments) throws TemplateModelException { + Stub stub = (Stub) DeepUnwrap.unwrap((TemplateModel) arguments.get(0)); + return stub.getDescription(); + } + } + private final class DisplayClassNameMethodModel implements TemplateMethodModelEx { @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/jaxws/wsdl2html/ui/Wsdl2HtmlMain.java b/src/main/java/org/jaxws/wsdl2html/ui/Wsdl2HtmlMain.java index a9c77bb..23d3df1 100644 --- a/src/main/java/org/jaxws/wsdl2html/ui/Wsdl2HtmlMain.java +++ b/src/main/java/org/jaxws/wsdl2html/ui/Wsdl2HtmlMain.java @@ -19,6 +19,8 @@ * */ public class Wsdl2HtmlMain { + private static final String TARGET_APIDOCS_LOCATION = "/target/classes/META-INF/apidocs/"; + private static String descriptionsPath = ""; public static void main(String[] args) throws IOException, WsdlImportException { @@ -41,6 +43,7 @@ public static void main(String[] args) throws IOException, WsdlImportException { File htmlDir = getHtmlDir(outputRootDir); System.out.println("Generating from " + wsdlUrl); + Wsdl2HtmlMain.descriptionsPath = wsdlUrl; FreemarkerWebServiceDisplayEngine displayEngine = createDisplayEngine(argList); String html = Wsdl2Html.generateHtml(byteCodeDir.getAbsolutePath(), wsdlUrl, displayEngine); @@ -69,4 +72,7 @@ private static File getByteCodeDir(File outputRootDir) { return byteCodeDir; } + public static String getDescriptionsPath() { + return (new File(descriptionsPath)).getParent() + TARGET_APIDOCS_LOCATION; + } } diff --git a/src/main/resources/include/macros.ftl b/src/main/resources/include/macros.ftl index 7004d81..6195c8f 100644 --- a/src/main/resources/include/macros.ftl +++ b/src/main/resources/include/macros.ftl @@ -4,7 +4,6 @@ Property Type - Required Description <#list stub.childStubs as childStub> @@ -24,12 +23,10 @@ ${stubType(stub)} - ${stub.required?string("Y","N")} - - - - + ${stub.description!} + + <#list stub.childStubs as childStub> <@stubRow stub=childStub parentPath=stubOgnl(stub, parentPath)/> - \ No newline at end of file + diff --git a/src/main/resources/include/methodParams.ftl b/src/main/resources/include/methodParams.ftl index 5878a22..2cec6f7 100644 --- a/src/main/resources/include/methodParams.ftl +++ b/src/main/resources/include/methodParams.ftl @@ -7,7 +7,6 @@ Name Type - Required Description diff --git a/src/main/resources/include/methodResponse.ftl b/src/main/resources/include/methodResponse.ftl index af6318f..cd49d14 100644 --- a/src/main/resources/include/methodResponse.ftl +++ b/src/main/resources/include/methodResponse.ftl @@ -7,11 +7,8 @@ Name Type - Required - Description - - <#include "rootStubRow.ftl"/> + <#include "responseRootStubRow.ftl"/> diff --git a/src/main/resources/include/methodsSummary.ftl b/src/main/resources/include/methodsSummary.ftl index e8c9e4c..20e7171 100644 --- a/src/main/resources/include/methodsSummary.ftl +++ b/src/main/resources/include/methodsSummary.ftl @@ -31,7 +31,7 @@ ${stubType(method.responseStub)} - + ${method.methodDescription} @@ -40,4 +40,4 @@ <#else> No Operations - \ No newline at end of file + diff --git a/src/main/resources/include/responseRootStubRow.ftl b/src/main/resources/include/responseRootStubRow.ftl new file mode 100644 index 0000000..f777479 --- /dev/null +++ b/src/main/resources/include/responseRootStubRow.ftl @@ -0,0 +1,10 @@ + + ${stubName(stub)} + +
+
${stubType(stub)}
+ <@stubChildrenAsTable stub=stub/> +
+ + + diff --git a/src/main/resources/include/rootStubRow.ftl b/src/main/resources/include/rootStubRow.ftl index fbcf78e..8885ca4 100644 --- a/src/main/resources/include/rootStubRow.ftl +++ b/src/main/resources/include/rootStubRow.ftl @@ -6,9 +6,8 @@ <@stubChildrenAsTable stub=stub/> - ${stub.required?string("Y","N")} - ${stub.description!} + ${description(stub)} - \ No newline at end of file + diff --git a/src/main/resources/service.ftl b/src/main/resources/service.ftl index 4da25e5..e963eed 100644 --- a/src/main/resources/service.ftl +++ b/src/main/resources/service.ftl @@ -26,41 +26,33 @@ width:20%; } .summary-table tr td:nth-child(4){ - width:20%; - } + width:10%; + } .summary-table tr td:nth-child(5){ - width:35%; + width:45%; } .stub-table tr td:nth-child(1){ - width:20%; + width:10%; } .stub-table tr td:nth-child(2){ width:60%; } - .stub-table tr td:nth-child(4){ - width:10%; + .stub-table tr td:nth-child(3){ + width:30%; } - .stub-table tr td:nth-child(5){ - width:10%; - } - .model-rows-table tr td:nth-child(1){ - width:55%; + width:20%; } .model-rows-table tr td:nth-child(2){ width:25%; } .model-rows-table tr td:nth-child(3){ - width:10%; + width:45%; } - .model-rows-table tr td:nth-child(4){ - width:10%; - } -