Author: ltheussl
Date: Tue Jun 2 09:43:33 2009
New Revision: 780986
URL: http://svn.apache.org/viewvc?rev=780986&view=rev
Log:
Add a DocumentModelSink to extract meta information from documents.
Added:
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/document/
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/document/DocumentModelSink.java
(with props)
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/document/DocumentModelSinkTest.java
(with props)
Added:
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/document/DocumentModelSink.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/document/DocumentModelSink.java?rev=780986&view=auto
==
---
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/document/DocumentModelSink.java
(added)
+++
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/document/DocumentModelSink.java
Tue Jun 2 09:43:33 2009
@@ -0,0 +1,328 @@
+package org.apache.maven.doxia.document;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.text.ParseException;
+
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Locale;
+
+import javax.swing.text.html.HTML.Attribute;
+
+import org.apache.maven.doxia.sink.SinkAdapter;
+import org.apache.maven.doxia.sink.SinkEventAttributes;
+import org.apache.maven.doxia.util.DoxiaUtils;
+
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * A Sink that collects meta-information emitted by a parser and stores it in
a DocumentModel.
+ *
+ * Use like:
+ *
+ *
+ * DocumentModelSink sink = new DocumentModelSink();
+ * parser.parse( reader, sink );
+ * DocumentModel model = sink.getModel();
+ *
+ *
+ * The sink only collects information from the title(),
author
+ * and date events, as well as meta-information emitted via
unknown(),
+ * all other events are ignored.
+ *
+ * @author ltheussl
+ * @version $Id$
+ * @since 1.1.1.
+ */
+
+public class DocumentModelSink
+extends SinkAdapter
+{
+private final DocumentModel model;
+
+private StringBuffer buffer;
+private DocumentAuthor author;
+
+/**
+ * Create a DocumentModelSink.
+ */
+public DocumentModelSink()
+{
+this.model = new DocumentModel();
+model.setMeta( new DocumentMeta() );
+}
+
+/**
+ * Retrieve the DocumentModel created by this Sink.
+ *
+ * @return the DocumentModel.
+ */
+public DocumentModel getModel()
+{
+return model;
+}
+
+/** Start recording a title. */
+public void title()
+{
+title( null );
+}
+
+/**
+ * Start recording a title. Only text events within a title event are
recorded.
+ *
+ * @param attributes ignored.
+ */
+public void title( SinkEventAttributes attributes )
+{
+this.buffer = new StringBuffer();
+}
+
+/** End recording a title. */
+public void title_()
+{
+String title = buffer.toString();
+
+if ( StringUtils.isNotEmpty( title ) )
+{
+getModel().getMeta().setTitle( buffer.toString() );
+}
+
+this.buffer = null;
+}
+
+/** Start recording an author. */
+public void author()
+{
+author( null );
+}
+
+/**
+ * Start recording an author. Only text events within an author event are
recorded.
+ *
+ * @param attributes only email attribute is recognized.
+ */
+public void author( SinkEventAttributes attributes )
+{
+this.buffer = new StringBuffer();
+this.author = new DocumentAuthor();
+
+if ( attributes != null )
+{
+for ( Enumeration e = attributes.getAttributeNames() ;
e.hasMoreElements() ; )
+{
+String name = e.nextElement().toString();
+
+if ( name.equals( SinkEventAttributes.EMAIL ) )
+{
+author.setEmail( attributes.getAttribute( name
).toString() );
+}
+els
Author: ltheussl
Date: Tue Jun 2 10:49:53 2009
New Revision: 781000
URL: http://svn.apache.org/viewvc?rev=781000&view=rev
Log:
Fix some links
Modified:
maven/doxia/site/src/site/pdf.xml
maven/doxia/site/src/site/xdoc/references/xdoc-format.xml
Modified: maven/doxia/site/src/site/pdf.xml
URL:
http://svn.apache.org/viewvc/maven/doxia/site/src/site/pdf.xml?rev=781000&r1=780999&r2=781000&view=diff
==
--- maven/doxia/site/src/site/pdf.xml (original)
+++ maven/doxia/site/src/site/pdf.xml Tue Jun 2 10:49:53 2009
@@ -52,6 +52,8 @@
+
+
Modified: maven/doxia/site/src/site/xdoc/references/xdoc-format.xml
URL:
http://svn.apache.org/viewvc/maven/doxia/site/src/site/xdoc/references/xdoc-format.xml?rev=781000&r1=780999&r2=781000&view=diff
==
--- maven/doxia/site/src/site/xdoc/references/xdoc-format.xml (original)
+++ maven/doxia/site/src/site/xdoc/references/xdoc-format.xml Tue Jun 2
10:49:53 2009
@@ -31,6 +31,7 @@
+
@@ -38,6 +39,8 @@
+
+
An 'xdoc' is an XML document conforming to a small and simple set of
tags.
@@ -57,12 +60,14 @@
-
+
+
The full documentation is available here.
+
The following is a sample XDoc document:
@@ -113,6 +118,7 @@
+
tags are special.
@@ -124,6 +130,7 @@
foo]]>
+
Doxia will produce
and
@@ -143,6 +150,7 @@
A subsubsection
+
The core doxia modules do not construct anchors from
@@ -203,6 +211,7 @@
+
Doxia is able to validate your xdoc files as described
here.
@@ -212,6 +221,7 @@
Here is a list of common mistakes to be aware of:
+
Wrong:
@@ -247,6 +257,7 @@
+
Wrong:
@@ -272,6 +283,7 @@
+
@@ -281,6 +293,7 @@
+
Wrong:
Author: ltheussl
Date: Tue Jun 2 12:44:20 2009
New Revision: 781021
URL: http://svn.apache.org/viewvc?rev=781021&view=rev
Log:
Move the DocumentModelSink into the sandbox. Add a dedicated project for code
to review.
Removed:
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/document/
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/document/DocumentModelSinkTest.java