Author: gertv
Date: Mon May 31 17:47:32 2010
New Revision: 949817
URL: http://svn.apache.org/viewvc?rev=949817&view=rev
Log:
Add support for setting a programlisting language attribute
Added:
servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/Test.xml
Modified:
servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/SnippetMojo.java
servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/confluence/ConfluenceConverter.java
servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/snippet/SnippetHandler.java
servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/java/org/apache/servicemix/docs/SnippetMojoTest.java
servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.xml
Modified:
servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/SnippetMojo.java
URL:
http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/SnippetMojo.java?rev=949817&r1=949816&r2=949817&view=diff
==============================================================================
---
servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/SnippetMojo.java
(original)
+++
servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/SnippetMojo.java
Mon May 31 17:47:32 2010
@@ -46,7 +46,7 @@ public class SnippetMojo extends Abstrac
protected URL snippetBase;
private static URLStreamHandlerFactory factory = null;
-
+
public void execute() throws MojoExecutionException {
if (factory == null) {
getLog().info("Registering additional URL handlers (snippet://)");
Modified:
servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/confluence/ConfluenceConverter.java
URL:
http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/confluence/ConfluenceConverter.java?rev=949817&r1=949816&r2=949817&view=diff
==============================================================================
---
servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/confluence/ConfluenceConverter.java
(original)
+++
servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/confluence/ConfluenceConverter.java
Mon May 31 17:47:32 2010
@@ -22,6 +22,8 @@ import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -40,7 +42,7 @@ public class ConfluenceConverter {
private int currentLevel = 0;
private Stack<String> elements = new Stack<String>();
-
+
public ConfluenceConverter(Reader reader, Writer writer) {
if (reader instanceof BufferedReader) {
this.reader = (BufferedReader) reader;
@@ -73,7 +75,7 @@ public class ConfluenceConverter {
} else if (line.startsWith("-")) {
writeGlossaryList(line);
} else if (line.trim().startsWith("{code")) {
- writeProgramListing();
+ writeProgramListing(line);
} else {
writePara(line);
}
@@ -146,10 +148,14 @@ public class ConfluenceConverter {
closeElement("imageobject");
}
- private void writeProgramListing() throws IOException {
- writeText("<programlisting><![CDATA[");
+ private void writeProgramListing(String line) throws IOException {
+ String language = Macro.parse(line).getParameter("lang");
+ if (language == null) {
+ writeText("<programlisting><![CDATA[");
+ } else {
+ writeText(String.format("<programlisting
language=\"%s\"><![CDATA[", language));
+ }
- String line = null;
while ((line = reader.readLine()) != null && !line.equals("{code}")) {
writeText(line, "");
}
@@ -246,4 +252,49 @@ public class ConfluenceConverter {
private boolean isCurrentElement(String element) {
return elements.peek().equals(element);
}
+
+ /*
+ * Helper class to represent a Confluence macro
+ * {name:parm1=value1?parm2=value2}
+ */
+ private static final class Macro {
+
+ private String name;
+ private final Map<String, String> parameters = new HashMap<String,
String>();
+
+ /**
+ * Get the macro name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get a macro parameter value
+ */
+ public String getParameter(String name) {
+ return parameters.get(name);
+ }
+
+ /**
+ * Parse a line containing a confluence macro
+ */
+ public static Macro parse(String line) {
+ Macro result = new Macro();
+ String macro = line.substring(line.indexOf("{"),
line.indexOf("}"));
+ if (macro.contains(":")) {
+ String[] split = macro.split(":");
+ result.name = split[0];
+ String[] parms = split[1].split("\\?");
+ for (String parm : parms) {
+ String[] pair = parm.split("=");
+ result.parameters.put(pair[0], pair[1]);
+ }
+ } else {
+ result.name = macro;
+ }
+ return result;
+ }
+
+ }
}
Modified:
servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/snippet/SnippetHandler.java
URL:
http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/snippet/SnippetHandler.java?rev=949817&r1=949816&r2=949817&view=diff
==============================================================================
---
servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/snippet/SnippetHandler.java
(original)
+++
servicemix/maven-plugins/docs-maven-plugin/trunk/src/main/java/org/apache/servicemix/docs/snippet/SnippetHandler.java
Mon May 31 17:47:32 2010
@@ -23,6 +23,7 @@ import java.net.URLStreamHandler;
import java.util.HashMap;
import java.util.Map;
+import org.apache.commons.io.FilenameUtils;
import org.apache.maven.plugin.AbstractMojo;
/**
@@ -72,7 +73,7 @@ public class SnippetHandler extends URLS
public InputStream getInputStream() {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PrintWriter out = new PrintWriter(bos);
- out.println("<programlisting><![CDATA[");
+ out.printf("<programlisting language=\"%s\"><![CDATA[%n",
FilenameUtils.getExtension(name));
String id = getQuery(url, "id");
try {
Modified:
servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/java/org/apache/servicemix/docs/SnippetMojoTest.java
URL:
http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/java/org/apache/servicemix/docs/SnippetMojoTest.java?rev=949817&r1=949816&r2=949817&view=diff
==============================================================================
---
servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/java/org/apache/servicemix/docs/SnippetMojoTest.java
(original)
+++
servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/java/org/apache/servicemix/docs/SnippetMojoTest.java
Mon May 31 17:47:32 2010
@@ -50,17 +50,27 @@ public class SnippetMojoTest {
URL url = new URL("snippet://Test.java");
String content = read(url).trim();
- assertTrue(content.startsWith("<programlisting><![CDATA["));
+ assertTrue(content.startsWith("<programlisting
language=\"java\"><![CDATA["));
assertTrue(content.contains("public class Test {"));
assertTrue(content.endsWith("]]></programlisting>"));
}
@Test
+ public void getFullFromXmlFile() throws IOException {
+ URL url = new URL("snippet://Test.xml");
+ String content = read(url).trim();
+
+ assertTrue(content.startsWith("<programlisting
language=\"xml\"><![CDATA["));
+ assertTrue(content.contains("<test/>"));
+ assertTrue(content.endsWith("]]></programlisting>"));
+ }
+
+ @Test
public void getSnippetFromSource() throws IOException {
URL url = new URL("snippet://Test.java?id=doSomething");
String content = read(url).trim();
- assertTrue(content.startsWith("<programlisting><![CDATA["));
+ assertTrue(content.startsWith("<programlisting
language=\"java\"><![CDATA["));
assertFalse(content.contains("public class Test {"));
assertTrue(content.contains("public void doSomething() {"));
assertTrue(content.endsWith("]]></programlisting>"));
Added:
servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/Test.xml
URL:
http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/Test.xml?rev=949817&view=auto
==============================================================================
---
servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/Test.xml
(added)
+++
servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/Test.xml
Mon May 31 17:47:32 2010
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<!--
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+<test/>
\ No newline at end of file
Modified:
servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.xml
URL:
http://svn.apache.org/viewvc/servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.xml?rev=949817&r1=949816&r2=949817&view=diff
==============================================================================
---
servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.xml
(original)
+++
servicemix/maven-plugins/docs-maven-plugin/trunk/src/test/resources/org/apache/servicemix/docs/confluence/code-blocks.xml
Mon May 31 17:47:32 2010
@@ -17,7 +17,7 @@
<para>
The next one specifies the language for the code block.
</para>
- <programlisting><![CDATA[
+ <programlisting language="xml"><![CDATA[
<?xml version="1.0"?>
<hello>
<world/>