cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r490125 - in /incubator/cayenne/main/trunk/other/build-maven-plugin: pom.xml src/main/java/org/apache/cayenne/maven/plugin/confluence/DocPageRenderer.java
Date Mon, 25 Dec 2006 10:37:18 GMT
Author: aadamchik
Date: Mon Dec 25 02:37:18 2006
New Revision: 490125

URL: http://svn.apache.org/viewvc?view=rev&rev=490125
Log:
removing dependency on cayenne core classes

Modified:
    incubator/cayenne/main/trunk/other/build-maven-plugin/pom.xml
    incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/confluence/DocPageRenderer.java

Modified: incubator/cayenne/main/trunk/other/build-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/other/build-maven-plugin/pom.xml?view=diff&rev=490125&r1=490124&r2=490125
==============================================================================
--- incubator/cayenne/main/trunk/other/build-maven-plugin/pom.xml (original)
+++ incubator/cayenne/main/trunk/other/build-maven-plugin/pom.xml Mon Dec 25 02:37:18 2006
@@ -51,10 +51,5 @@
 			<artifactId>velocity</artifactId>
 			<version>1.4</version>
 		</dependency>
-		<dependency>
-			<groupId>org.apache.cayenne.core</groupId>
-			<artifactId>cayenne-jdk1.4</artifactId>
-			<version>${version}</version>
-		</dependency>
 	</dependencies>
 </project>

Modified: incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/confluence/DocPageRenderer.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/confluence/DocPageRenderer.java?view=diff&rev=490125&r1=490124&r2=490125
==============================================================================
--- incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/confluence/DocPageRenderer.java
(original)
+++ incubator/cayenne/main/trunk/other/build-maven-plugin/src/main/java/org/apache/cayenne/maven/plugin/confluence/DocPageRenderer.java
Mon Dec 25 02:37:18 2006
@@ -27,8 +27,6 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.gen.ClassGeneratorResourceLoader;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
@@ -37,209 +35,220 @@
 import org.objectstyle.confluence.rpc.soap_axis.confluenceservice_v1.ConfluenceSoapService;
 
 /**
- * Extracts embedded links from Confluence documentation and converts them to
- * local fs references
+ * Extracts embedded links from Confluence documentation and converts them to local fs
+ * references
  * 
  * @author Cris Daniluk
  */
 public class DocPageRenderer {
 
-	private static final String URL_PREFIX = "/confluence";
+    private static final String URL_PREFIX = "/confluence";
 
-	/**
-	 * Only attachments within the page are supported right now. This could
-	 * easily be adjusted to find attachments in external documents if
-	 * necessary.
-	 */
-	private static final Pattern attachmentPattern = Pattern
-			.compile("(href|src)=\"" + URL_PREFIX
-					+ "/download/attachments/(.*?)/(.*?)\"");
-
-	/**
-	 * When browsing the local filesystem, browsers like %20 (hex encoded)
-	 * instead of + (legacy HTTP 0.9) for spaces.
-	 */
-	private static final Pattern spaceEncoderPattern = Pattern
-			.compile("href=\"(?!http://).*?\\+.*?\"");
-
-	/**
-	 * Not all images are supported - only the ones referenced by current docs.
-	 */
-	private static final Pattern confluenceImagePattern = Pattern
-			.compile("src=\"" + URL_PREFIX + "/images/icons/(.*?)\"");
-
-	/**
-	 * Take any confluence links to non-doc content and add the url
-	 */
-	private Pattern confluenceLinkPattern = Pattern.compile("href=\"("
-			+ URL_PREFIX + "/display/.*?)\"");
-
-	private Pattern embeddedLinkPattern;
-
-	private ConfluenceSoapService service;
-
-	private String token;
-
-	private String spaceKey;
-
-	private String baseUrl;
-
-	private VelocityContext velCtxt;
-
-	private Template pageTemplate;
-
-	public DocPageRenderer(ConfluenceSoapService service, String baseUrl,
-			String token, String spaceKey, String template) throws Exception {
-
-		// Note that these regexps have a fairly narrow capture - since the HTML
-		// is
-		// machine-generated,
-		// we're kind of assuming it is well-formed
-		embeddedLinkPattern = Pattern.compile("href=\"" + URL_PREFIX
-				+ "/display/" + spaceKey + "/(.*?)\"");
-
-		this.service = service;
-		this.baseUrl = baseUrl;
-		this.token = token;
-		this.spaceKey = spaceKey;
-
-		velCtxt = new VelocityContext();
-
-		initializeClassTemplate(template);
-	}
-
-	private void initializeClassTemplate(String template) throws Exception {
-		VelocityEngine velocityEngine = new VelocityEngine();
-		try {
-
-			// use ClasspathResourceLoader for velocity templates lookup
-			// if Cayenne URL is not null, load resource from this URL
-			Properties props = new Properties();
-
-			// null logger that will prevent velocity.log from being generated
-			props.put(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
-					NullLogSystem.class.getName());
-
-			props.put("resource.loader", "cayenne");
-
-			props.put("cayenne.resource.loader.class",
-					ClassGeneratorResourceLoader.class.getName());
-
-			velocityEngine.init(props);
-		} catch (Exception ex) {
-			throw new CayenneRuntimeException("Can't initialize Velocity", ex);
-		}
-
-		pageTemplate = velocityEngine.getTemplate(template);
-	}
-
-	public void render(DocPage page, Writer out) throws Exception {
-
-		// Add the TOC, unless this is the top-level page
-		StringBuffer toc = new StringBuffer();
-		if (page.getParentRef() != null) {
-			toc.append("<div id=\"cayenne_toc\">\n");
-
-			DocPage root = page.getRoot();
-
-			iterateChildren(toc, page, root);
-			toc.append("</div>\n");
-		}
-
-		// Figure out the level of nesting for relative links
-		String basePath = "";
-		for (int i = 1; i <= page.getDepth(); i++) {
-			basePath += "../";
-		}
-
-		String renderedContent = null;
-		try {
-			renderedContent = service.renderContent(token, spaceKey, page
-					.getId(), page.getRawContent(), new HashMap(Collections
-					.singletonMap("style", "clean")));
-		} catch (Throwable t) {
-			// could have hit a DOS prevention bit so
-			// sleep for 250ms and try again
-			Thread.sleep(250);
-			renderedContent = service.renderContent(token, spaceKey, page
-					.getId(), page.getRawContent(), new HashMap(Collections
-					.singletonMap("style", "clean")));
-		}
-		// Replace cross-doc links
-		Matcher linkMatcher = embeddedLinkPattern.matcher(renderedContent);
-		StringBuffer replacementBuffer = new StringBuffer();
-		while (linkMatcher.find()) {
-			DocPage destPage = DocPage.getPageByTitle(linkMatcher.group(1)
-					.replace('+', ' '));
-
-			// If we don't understand the link, just leave it alone to be safe
-			if (destPage == null) {
-				continue;
-			}
-			linkMatcher.appendReplacement(replacementBuffer, "href=\""
-					+ basePath + destPage.getLinkPath() + "/index.html\"");
-		}
-		linkMatcher.appendTail(replacementBuffer);
-
-		renderedContent = replacementBuffer.toString();
-
-		// renderedContent =
-		// embeddedLinkPattern.matcher(renderedContent).replaceAll("href=\"$1/index.html\"");
-
-		// Replace attachment links
-		renderedContent = attachmentPattern.matcher(renderedContent)
-				.replaceAll("$1=\"$3\"");
-
-		// Convert confluence images to relative links
-		renderedContent = confluenceImagePattern.matcher(renderedContent)
-				.replaceAll("src=\"" + basePath + "images/$1\"");
-
-		// Replace wiki links
-		renderedContent = confluenceLinkPattern.matcher(renderedContent)
-				.replaceAll("href=\"" + baseUrl + "$1\"");
-
-		// Convert local links with + to %20 to make browsers happy (wtf?)
-		Matcher matcher = spaceEncoderPattern.matcher(renderedContent);
-
-		replacementBuffer = new StringBuffer();
-		while (matcher.find()) {
-			matcher.appendReplacement(replacementBuffer, matcher.group(0)
-					.replace("+", "%20"));
-		}
-		matcher.appendTail(replacementBuffer);
-
-		renderedContent = replacementBuffer.toString();
-
-		velCtxt.put("page", page);
-		velCtxt.put("basePath", basePath);
-		velCtxt.put("pageContent", toc.toString() + renderedContent);
-
-		pageTemplate.merge(velCtxt, out);
-
-	}
-
-	private void iterateChildren(StringBuffer toc, DocPage currentPage,
-			DocPage basePage) {
-		toc.append("<ul>\n");
-		for (Iterator baseIter = basePage.getChildren().iterator(); baseIter
-				.hasNext();) {
-
-			DocPage child = (DocPage) baseIter.next();
-
-			toc.append("<li>").append("<a href=\"");
-			for (int i = 1; i <= currentPage.getDepth(); i++) {
-				toc.append("../");
-			}
-			toc.append(child.getLinkPath()).append("/index.html\">");
-			toc.append(child.getTitle()).append("</a>");
-			if (child.hasDescendent(currentPage)) {
-				// render children
-				iterateChildren(toc, currentPage, child);
-			}
+    /**
+     * Only attachments within the page are supported right now. This could easily be
+     * adjusted to find attachments in external documents if necessary.
+     */
+    private static final Pattern attachmentPattern = Pattern.compile("(href|src)=\""
+            + URL_PREFIX
+            + "/download/attachments/(.*?)/(.*?)\"");
+
+    /**
+     * When browsing the local filesystem, browsers like %20 (hex encoded) instead of +
+     * (legacy HTTP 0.9) for spaces.
+     */
+    private static final Pattern spaceEncoderPattern = Pattern
+            .compile("href=\"(?!http://).*?\\+.*?\"");
+
+    /**
+     * Not all images are supported - only the ones referenced by current docs.
+     */
+    private static final Pattern confluenceImagePattern = Pattern.compile("src=\""
+            + URL_PREFIX
+            + "/images/icons/(.*?)\"");
+
+    /**
+     * Take any confluence links to non-doc content and add the url
+     */
+    private Pattern confluenceLinkPattern = Pattern.compile("href=\"("
+            + URL_PREFIX
+            + "/display/.*?)\"");
+
+    private Pattern embeddedLinkPattern;
+
+    private ConfluenceSoapService service;
+
+    private String token;
+
+    private String spaceKey;
+
+    private String baseUrl;
+
+    private VelocityContext velCtxt;
+
+    private Template pageTemplate;
+
+    public DocPageRenderer(ConfluenceSoapService service, String baseUrl, String token,
+            String spaceKey, String template) throws Exception {
+
+        // Note that these regexps have a fairly narrow capture - since the HTML
+        // is
+        // machine-generated,
+        // we're kind of assuming it is well-formed
+        embeddedLinkPattern = Pattern.compile("href=\""
+                + URL_PREFIX
+                + "/display/"
+                + spaceKey
+                + "/(.*?)\"");
+
+        this.service = service;
+        this.baseUrl = baseUrl;
+        this.token = token;
+        this.spaceKey = spaceKey;
+
+        velCtxt = new VelocityContext();
+
+        initializeClassTemplate(template);
+    }
+
+    private void initializeClassTemplate(String template) throws Exception {
+        VelocityEngine velocityEngine = new VelocityEngine();
+        try {
+
+            // use ClasspathResourceLoader for velocity templates lookup
+            // if Cayenne URL is not null, load resource from this URL
+            Properties props = new Properties();
+
+            // null logger that will prevent velocity.log from being generated
+            props.put(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, NullLogSystem.class
+                    .getName());
+
+            props.put("resource.loader", "cayenne");
+
+            props.put(
+                    "cayenne.resource.loader.class",
+                    "org.apache.cayenne.gen.ClassGeneratorResourceLoader");
+
+            velocityEngine.init(props);
+        }
+        catch (Exception ex) {
+            throw new RuntimeException("Can't initialize Velocity", ex);
+        }
+
+        pageTemplate = velocityEngine.getTemplate(template);
+    }
+
+    public void render(DocPage page, Writer out) throws Exception {
+
+        // Add the TOC, unless this is the top-level page
+        StringBuffer toc = new StringBuffer();
+        if (page.getParentRef() != null) {
+            toc.append("<div id=\"cayenne_toc\">\n");
+
+            DocPage root = page.getRoot();
+
+            iterateChildren(toc, page, root);
+            toc.append("</div>\n");
+        }
+
+        // Figure out the level of nesting for relative links
+        String basePath = "";
+        for (int i = 1; i <= page.getDepth(); i++) {
+            basePath += "../";
+        }
+
+        String renderedContent = null;
+        try {
+            renderedContent = service.renderContent(token, spaceKey, page.getId(), page
+                    .getRawContent(), new HashMap(Collections.singletonMap(
+                    "style",
+                    "clean")));
+        }
+        catch (Throwable t) {
+            // could have hit a DOS prevention bit so
+            // sleep for 250ms and try again
+            Thread.sleep(250);
+            renderedContent = service.renderContent(token, spaceKey, page.getId(), page
+                    .getRawContent(), new HashMap(Collections.singletonMap(
+                    "style",
+                    "clean")));
+        }
+        // Replace cross-doc links
+        Matcher linkMatcher = embeddedLinkPattern.matcher(renderedContent);
+        StringBuffer replacementBuffer = new StringBuffer();
+        while (linkMatcher.find()) {
+            DocPage destPage = DocPage.getPageByTitle(linkMatcher.group(1).replace(
+                    '+',
+                    ' '));
+
+            // If we don't understand the link, just leave it alone to be safe
+            if (destPage == null) {
+                continue;
+            }
+            linkMatcher.appendReplacement(replacementBuffer, "href=\""
+                    + basePath
+                    + destPage.getLinkPath()
+                    + "/index.html\"");
+        }
+        linkMatcher.appendTail(replacementBuffer);
+
+        renderedContent = replacementBuffer.toString();
+
+        // renderedContent =
+        // embeddedLinkPattern.matcher(renderedContent).replaceAll("href=\"$1/index.html\"");
+
+        // Replace attachment links
+        renderedContent = attachmentPattern.matcher(renderedContent).replaceAll(
+                "$1=\"$3\"");
+
+        // Convert confluence images to relative links
+        renderedContent = confluenceImagePattern.matcher(renderedContent).replaceAll(
+                "src=\"" + basePath + "images/$1\"");
+
+        // Replace wiki links
+        renderedContent = confluenceLinkPattern.matcher(renderedContent).replaceAll(
+                "href=\"" + baseUrl + "$1\"");
+
+        // Convert local links with + to %20 to make browsers happy (wtf?)
+        Matcher matcher = spaceEncoderPattern.matcher(renderedContent);
+
+        replacementBuffer = new StringBuffer();
+        while (matcher.find()) {
+            matcher.appendReplacement(replacementBuffer, matcher.group(0).replace(
+                    "+",
+                    "%20"));
+        }
+        matcher.appendTail(replacementBuffer);
+
+        renderedContent = replacementBuffer.toString();
+
+        velCtxt.put("page", page);
+        velCtxt.put("basePath", basePath);
+        velCtxt.put("pageContent", toc.toString() + renderedContent);
+
+        pageTemplate.merge(velCtxt, out);
+
+    }
+
+    private void iterateChildren(StringBuffer toc, DocPage currentPage, DocPage basePage)
{
+        toc.append("<ul>\n");
+        for (Iterator baseIter = basePage.getChildren().iterator(); baseIter.hasNext();)
{
+
+            DocPage child = (DocPage) baseIter.next();
+
+            toc.append("<li>").append("<a href=\"");
+            for (int i = 1; i <= currentPage.getDepth(); i++) {
+                toc.append("../");
+            }
+            toc.append(child.getLinkPath()).append("/index.html\">");
+            toc.append(child.getTitle()).append("</a>");
+            if (child.hasDescendent(currentPage)) {
+                // render children
+                iterateChildren(toc, currentPage, child);
+            }
 
-			toc.append("</li>\n");
-		}
+            toc.append("</li>\n");
+        }
 
-		toc.append("</ul>\n");
-	}
+        toc.append("</ul>\n");
+    }
 }



Mime
View raw message