[hibernate-commits] Hibernate SVN: r11468 - trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri May 4 09:14:04 EDT 2007
Author: steve.ebersole at jboss.com
Date: 2007-05-04 09:14:04 -0400 (Fri, 04 May 2007)
New Revision: 11468
Added:
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/IndexReportGenerator.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/TranslationReportGenerator.java
Removed:
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/ReportGenerator.java
Modified:
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/TranslationDiffReport.java
Log:
fixed the diff report; yay!
Added: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/IndexReportGenerator.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/IndexReportGenerator.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/IndexReportGenerator.java 2007-05-04 13:14:04 UTC (rev 11468)
@@ -0,0 +1,70 @@
+package org.jboss.maven.docbook.revdiff;
+
+import java.util.Locale;
+import java.util.List;
+import java.util.Iterator;
+import java.util.ResourceBundle;
+
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.reporting.MavenReportException;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class IndexReportGenerator {
+ private final ResourceBundle bundle;
+ private final Sink sink;
+ private final Log log;
+
+ public static class TranslationReportDescriptor {
+ private final Locale translation;
+ private final String reportPath;
+
+ public TranslationReportDescriptor(Locale translation, String reportPath) {
+ this.translation = translation;
+ this.reportPath = reportPath;
+ }
+ }
+
+ public IndexReportGenerator(ResourceBundle bundle, Sink sink, Log log) {
+ this.bundle = bundle;
+ this.sink = sink;
+ this.log = log;
+ }
+
+ public void generate(List reportDescriptors) throws MavenReportException {
+ log.debug( "writing index report via provided sink" );
+ sink.head();
+ sink.text( bundle.getString( "report.name" ) );
+ sink.head_();
+
+ sink.body();
+ sink.sectionTitle1();
+ sink.anchor( bundle.getString( "report.header" ) );
+ sink.anchor_();
+ sink.text( bundle.getString( "report.header" ) );
+ sink.sectionTitle1_();
+
+ sink.table();
+ Iterator itr = reportDescriptors.iterator();
+ while ( itr.hasNext() ) {
+ final TranslationReportDescriptor descriptor = ( TranslationReportDescriptor ) itr.next();
+ sink.tableRow();
+ sink.tableCell();
+ sink.link( descriptor.reportPath );
+ sink.text( descriptor.translation.getDisplayName( Locale.ENGLISH ) + " (" + descriptor.translation.toString() + ")" );
+ sink.link_();
+ sink.tableCell_();
+ sink.tableRow_();
+ }
+ sink.table_();
+
+ sink.body_();
+ sink.flush();
+ sink.close();
+ log.debug( "index report sink flushed and closed" );
+ }
+}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/ReportGenerator.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/ReportGenerator.java 2007-05-04 04:45:30 UTC (rev 11467)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/ReportGenerator.java 2007-05-04 13:14:04 UTC (rev 11468)
@@ -1,187 +0,0 @@
-package org.jboss.maven.docbook.revdiff;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.ResourceBundle;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import org.apache.maven.plugin.logging.Log;
-import org.codehaus.plexus.util.FileUtils;
-
-/**
- * Generate a diff report.
- *
- * @author Christian Bauer
- * @author Steve Ebersole
- */
-public class ReportGenerator {
- // todo : use templating...
- private final String base;
- private final ResourceBundle bundle;
- private final Log log;
-
- public ReportGenerator(File basedir, ResourceBundle bundle, Log log) {
- try {
- this.base = basedir.toURL().toExternalForm();
- }
- catch ( MalformedURLException e ) {
- throw new IllegalArgumentException( "basedir was a malformed url" );
- }
- log.debug( "constructing docbook diff report generator [base=" + base + "]" );
- this.bundle = bundle;
- this.log = log;
- }
-
- public void generate(Diff diff, File output, String translation) throws GenerationException {
- if ( output.exists() ) {
- log.debug( "cleaning up previous translation-diff report output [" + output.getAbsolutePath() + "]" );
- output.delete();
- }
-
- File outputDirectory = output.getParentFile();
- if ( !outputDirectory.exists() ) {
- String outputDirectoryPath = outputDirectory.getAbsolutePath();
- log.debug( "creating translation-diff report directory [" + outputDirectoryPath + "]" );
- FileUtils.mkdir( outputDirectoryPath );
- }
-
- try {
- output.createNewFile();
- }
- catch ( IOException e ) {
- throw new GenerationException( "unable to create output file [" + output.getAbsolutePath() + "]", e );
- }
-
- try {
- FileWriter writer = new FileWriter( output );
- writer.write( pageHead( translation ) );
-
- writer.write( "<table cellpadding=4>" );
-
- writer.write( generateNewInMaster( diff ) );
- writer.write( "<tr><td> </td></tr>" );
- writer.write( generateDiffRevision( diff ) );
- writer.write( "<tr><td> </td></tr>" );
- writer.write( generateNewInTranslation( diff ) );
-
- writer.write( "</table>" );
- writer.write( pageFoot() );
- writer.close();
- }
- catch ( IOException e ) {
- throw new GenerationException( "error writing report [" + output.getAbsolutePath() + "]", e );
- }
- }
-
- private String pageHead(String translation) {
- StringBuffer buf = new StringBuffer( 256 );
- buf.append( "<html><head><title>" ).append( bundle.getString( "report.name" ) ).append( "</title></head><body><div align=\"center\">" );
- buf.append( "<h3>" ).append( bundle.getString( "report.header") ).append( " - " ).append( translation ).append( "</h3>" );
- return buf.toString();
- }
-
- private String pageFoot() {
- StringBuffer buf = new StringBuffer( 256 );
- buf.append( "</div></body></html>" );
- return buf.toString();
- }
-
- private String generateNewInMaster(Diff diff) {
- StringBuffer buf = new StringBuffer();
- Iterator itr = diff.getElementsOnlyInMaster();
- while ( itr.hasNext() ) {
- final ContentItem contentItem = ( ContentItem ) itr.next();
- buf.append( "<tr><td bgcolor=#eeeeee>ID: " ).append( contentItem.getIdentifier() ).append( "</td></tr>" );
- buf.append( "<tr><td>" );
- buf.append( "<b>" ).append( formatReference( contentItem.getMasterDescriptor() ) ).append( "</b>" );
- buf.append( "</td></tr>" );
- }
-
- String result = "";
- if ( buf.length() > 0 ) {
- result = "<tr bgcolor=#cccccc><td><b>New in master:</b></td></tr>";
- }
- return result + buf.toString();
- }
-
- private String generateDiffRevision(Diff diff) {
- StringBuffer buf = new StringBuffer();
- Iterator itr = diff.getElementsDiffRevision();
- while ( itr.hasNext() ) {
- final ContentItem contentItem = ( ContentItem ) itr.next();
- buf.append( "<tr><td bgcolor=#eeeeee>ID: " ).append( contentItem.getIdentifier() ).append( "</td></tr>" );
- if ( !contentItem.getMasterDescriptor().getElementName().equals( contentItem.getTranslationDescriptor().getElementName() ) ) {
- buf.append( "<tr><td bgcolor=#ee6666>" );
- buf.append( "Element names differ: " )
- .append( contentItem.getMasterDescriptor().getElementName() )
- .append( "/" )
- .append( contentItem.getTranslationDescriptor().getElementName() );
- buf.append( "</td></tr>" );
- }
- buf.append( "<tr><td>" );
- buf.append( "Master: <b>" ).append( formatReference( contentItem.getMasterDescriptor() ) ).append( "</b>" );
- buf.append( "</td></tr>" );
- buf.append( "<tr><td>" );
- buf.append( "Translation: <b>" ).append( formatReference( contentItem.getTranslationDescriptor() ) ).append( "</b>" );
- buf.append( "</td></tr>" );
- buf.append( "<tr><td>" );
- buf.append( "Master Revision: " ).append( contentItem.getMasterDescriptor().getRevision() );
- buf.append( "</td></tr>" );
- buf.append( "<tr><td>" );
- buf.append( "Translation Revision: " ).append( contentItem.getTranslationDescriptor().getRevision() );
- buf.append( "</td></tr>" );
- }
-
- String result = "";
- if ( buf.length() > 0 ) {
- result = "<tr bgcolor=#cccccc><td><b>Translation needs update:</b></td></tr>";
- }
- return result + buf.toString();
- }
-
- private String generateNewInTranslation(Diff diff) {
- StringBuffer buf = new StringBuffer();
- Iterator itr = diff.getElementsOnlyInTranslation();
- while ( itr.hasNext() ) {
- final ContentItem contentItem = ( ContentItem ) itr.next();
- buf.append( "<tr><td bgcolor=#eeeeee>ID: " ).append( contentItem.getIdentifier() ).append( "</td></tr>" );
- buf.append( "<tr><td>" );
- buf.append( "<b>" ).append( formatReference( contentItem.getTranslationDescriptor() ) ).append( "</b>" );
- buf.append( "</td></tr>" );
- }
- String result = "";
- if ( buf.length() > 0 ) {
- result = "<tr bgcolor=#cccccc><td><b>Only present in translation:</b></td></tr>";
- }
- return result + buf.toString();
- }
-
- private String formatReference(ContentItemDescriptor descriptor) {
- return makeSystemIdRelative( descriptor.getSourceSystemId() ) +
- ":" + descriptor.getElementName() +
- " (" + descriptor.getRow() + "," + descriptor.getColumn() + ")";
- }
-
- private String makeSystemIdRelative(String systemId) {
- String systemIdUrl = toURL( systemId ).toExternalForm();
- log.debug( "checking source [" + systemIdUrl + "] against base [" + base + "]" );
- if ( systemIdUrl.startsWith( base ) ) {
- return systemIdUrl.substring( base.length() );
- }
- else {
- return systemIdUrl;
- }
- }
-
- private URL toURL(String systemId) {
- try {
- return new URL( systemId );
- }
- catch ( MalformedURLException e ) {
- throw new UnsupportedOperationException( "unable to parse systemId [" + systemId + "] as URL" );
- }
- }
-}
Modified: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/TranslationDiffReport.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/TranslationDiffReport.java 2007-05-04 04:45:30 UTC (rev 11467)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/TranslationDiffReport.java 2007-05-04 13:14:04 UTC (rev 11468)
@@ -4,7 +4,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
@@ -49,8 +48,7 @@
/**
* Which translation is considered the master.
*
- * @parameter default="en"
- * @required
+ * @parameter default-value="en"
*/
private String masterTranslation;
@@ -58,23 +56,21 @@
* (non master) translations to be included in the report.
*
* @parameter
- * @required
*/
- private String[] translations;
+ private String[] translationIncludes;
/**
* Patternsets of sources (relative to translationsDirectory) to include
* in reporting.
*
- * @parameter default="*.xml"
- * @required
+ * @parameter
*/
private String[] sourceIncludes;
/**
* A boolean, indicating if XInclude should be supported.
*
- * @parameter default="false"
+ * @parameter default-value="false"
*/
private boolean xincludeSupported;
@@ -154,8 +150,7 @@
}
public boolean canGenerateReport() {
- return translations != null && translations.length > 0
- && sourceIncludes != null && sourceIncludes.length > 0;
+ return true;
}
protected void executeReport(Locale locale) throws MavenReportException {
@@ -172,25 +167,42 @@
return;
}
+ if ( translationIncludes == null || translationIncludes.length == 0 ) {
+ // use all translations...
+ ArrayList includes = new ArrayList();
+ File[] subdirs = translationsDirectory.listFiles();
+ for ( int i = 0; i < subdirs.length; i++ ) {
+ includes.add( subdirs[i].getName() );
+ }
+ translationIncludes = ( String[] ) includes.toArray( new String[ includes.size() ] );
+ }
+
+ if ( sourceIncludes == null || sourceIncludes.length == 0 ) {
+ sourceIncludes = new String[] { "*.xml" };
+ }
+
List reports = new ArrayList();
- for ( int i = 0; i < translations.length; i++ ) {
- if ( masterTranslation.equals( translations[i] ) ) {
+ for ( int i = 0; i < translationIncludes.length; i++ ) {
+ if ( masterTranslation.equals( translationIncludes[i] ) ) {
continue;
}
- final File translationDirectory = new File( translationsDirectory, translations[i] );
+ final File translationDirectory = new File( translationsDirectory, translationIncludes[i] );
if ( ! translationDirectory.exists() ) {
getLog().info( "translation directory [" + translationDirectory.getAbsolutePath() + "] did not exist" );
continue;
}
- File output = new File( getReportOutputDirectory(), "report-" + translations[i] + ".html" );
- prepReportFile( output );
-
- generateTranslationReport( masterTranslationDirectory, translationDirectory, output, new Locale( translations[i] ) );
- reports.add( output.getName() );
+ if ( generateTranslationReport( masterTranslationDirectory, translationDirectory, translationIncludes[i] ) ) {
+ reports.add(
+ new IndexReportGenerator.TranslationReportDescriptor(
+ new Locale( translationIncludes[i] ),
+ NAME + "/" + buildTranslationReportName( translationIncludes[i] )
+ )
+ );
+ }
}
- writeReportIndex( reports );
+ new IndexReportGenerator( getBundle( locale ), getSink(), getLog() ).generate( reports );
}
private void prepReportFile(File reportFile) throws MavenReportException {
@@ -207,12 +219,15 @@
}
}
- private void generateTranslationReport(
+ private String buildTranslationReportName(String translationName) {
+ return "report-" + translationName + ".html";
+ }
+
+ private boolean generateTranslationReport(
File masterTranslationDirectory,
File translationDirectory,
- File output,
- Locale locale) throws MavenReportException {
- getLog().debug( "starting docbook:diff processing [translation=" + locale + "]" );
+ String translationName) throws MavenReportException {
+ getLog().debug( "starting docbook:diff processing [translation=" + translationName + "]" );
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir( masterTranslationDirectory );
@@ -228,12 +243,16 @@
if ( ! Arrays.equals( masterSources, translationSources ) ) {
getLog().warn( "includes returned different master and translation sets" );
- return;
+ return false;
}
+ Locale locale = new Locale( translationName );
+ File output = new File( getReportOutputDirectory(), buildTranslationReportName( translationName ) );
+ prepReportFile( output );
+
try {
DiffCreator diffCreator = new DiffCreator( xincludeSupported, getLog() );
- ReportGenerator generator = new ReportGenerator( translationsDirectory, getBundle( locale ), getLog() );
+ TranslationReportGenerator generator = new TranslationReportGenerator( translationsDirectory, getBundle( locale ), getLog() );
for ( int i = 0; i < masterSources.length; i++ ) {
getLog().debug( "processing source [" + masterSources[i] + "]" );
@@ -246,39 +265,7 @@
catch ( GenerationException e ) {
throw new MavenReportException( "unable to generate report", e );
}
+ return true;
}
- private void writeReportIndex(List reports) throws MavenReportException {
- getLog().debug( "writing index report via provided sink" );
- getSink().head();
- getSink().text( getBundle( Locale.ENGLISH ).getString( "report.name" ) );
- getSink().head_();
-
- getSink().body();
- getSink().sectionTitle1();
- getSink().anchor( getBundle( Locale.ENGLISH ).getString( "report.header" ) );
- getSink().anchor_();
- getSink().text( getBundle( Locale.ENGLISH ).getString( "report.header" ) );
- getSink().sectionTitle1_();
-
- getSink().table();
- Iterator itr = reports.iterator();
- while ( itr.hasNext() ) {
- final String reportURL = ( String ) itr.next();
- getSink().tableRow();
- getSink().tableCell();
- getSink().link( reportURL );
- getSink().text( reportURL );
- getSink().link_();
- getSink().tableCell_();
- getSink().tableRow_();
- }
- getSink().table_();
-
- getSink().body_();
- getSink().flush();
- getSink().close();
- getLog().debug( "index report sink flushed and closed" );
- }
-
}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/TranslationReportGenerator.java (from rev 11464, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/ReportGenerator.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/TranslationReportGenerator.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/TranslationReportGenerator.java 2007-05-04 13:14:04 UTC (rev 11468)
@@ -0,0 +1,187 @@
+package org.jboss.maven.docbook.revdiff;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.ResourceBundle;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * Generate a diff report.
+ *
+ * @author Christian Bauer
+ * @author Steve Ebersole
+ */
+public class TranslationReportGenerator {
+ // todo : use templating...
+ private final String base;
+ private final ResourceBundle bundle;
+ private final Log log;
+
+ public TranslationReportGenerator(File basedir, ResourceBundle bundle, Log log) {
+ try {
+ this.base = basedir.toURL().toExternalForm();
+ }
+ catch ( MalformedURLException e ) {
+ throw new IllegalArgumentException( "basedir was a malformed url" );
+ }
+ log.debug( "constructing docbook diff report generator [base=" + base + "]" );
+ this.bundle = bundle;
+ this.log = log;
+ }
+
+ public void generate(Diff diff, File output, String translation) throws GenerationException {
+ if ( output.exists() ) {
+ log.debug( "cleaning up previous translation-diff report output [" + output.getAbsolutePath() + "]" );
+ output.delete();
+ }
+
+ File outputDirectory = output.getParentFile();
+ if ( !outputDirectory.exists() ) {
+ String outputDirectoryPath = outputDirectory.getAbsolutePath();
+ log.debug( "creating translation-diff report directory [" + outputDirectoryPath + "]" );
+ FileUtils.mkdir( outputDirectoryPath );
+ }
+
+ try {
+ output.createNewFile();
+ }
+ catch ( IOException e ) {
+ throw new GenerationException( "unable to create output file [" + output.getAbsolutePath() + "]", e );
+ }
+
+ try {
+ FileWriter writer = new FileWriter( output );
+ writer.write( pageHead( translation ) );
+
+ writer.write( "<table cellpadding=4>" );
+
+ writer.write( generateNewInMaster( diff ) );
+ writer.write( "<tr><td> </td></tr>" );
+ writer.write( generateDiffRevision( diff ) );
+ writer.write( "<tr><td> </td></tr>" );
+ writer.write( generateNewInTranslation( diff ) );
+
+ writer.write( "</table>" );
+ writer.write( pageFoot() );
+ writer.close();
+ }
+ catch ( IOException e ) {
+ throw new GenerationException( "error writing report [" + output.getAbsolutePath() + "]", e );
+ }
+ }
+
+ private String pageHead(String translation) {
+ StringBuffer buf = new StringBuffer( 256 );
+ buf.append( "<html><head><title>" ).append( bundle.getString( "report.name" ) ).append( "</title></head><body><div align=\"center\">" );
+ buf.append( "<h3>" ).append( bundle.getString( "report.header") ).append( " - " ).append( translation ).append( "</h3>" );
+ return buf.toString();
+ }
+
+ private String pageFoot() {
+ StringBuffer buf = new StringBuffer( 256 );
+ buf.append( "</div></body></html>" );
+ return buf.toString();
+ }
+
+ private String generateNewInMaster(Diff diff) {
+ StringBuffer buf = new StringBuffer();
+ Iterator itr = diff.getElementsOnlyInMaster();
+ while ( itr.hasNext() ) {
+ final ContentItem contentItem = ( ContentItem ) itr.next();
+ buf.append( "<tr><td bgcolor=#eeeeee>ID: " ).append( contentItem.getIdentifier() ).append( "</td></tr>" );
+ buf.append( "<tr><td>" );
+ buf.append( "<b>" ).append( formatReference( contentItem.getMasterDescriptor() ) ).append( "</b>" );
+ buf.append( "</td></tr>" );
+ }
+
+ String result = "";
+ if ( buf.length() > 0 ) {
+ result = "<tr bgcolor=#cccccc><td><b>New in master:</b></td></tr>";
+ }
+ return result + buf.toString();
+ }
+
+ private String generateDiffRevision(Diff diff) {
+ StringBuffer buf = new StringBuffer();
+ Iterator itr = diff.getElementsDiffRevision();
+ while ( itr.hasNext() ) {
+ final ContentItem contentItem = ( ContentItem ) itr.next();
+ buf.append( "<tr><td bgcolor=#eeeeee>ID: " ).append( contentItem.getIdentifier() ).append( "</td></tr>" );
+ if ( !contentItem.getMasterDescriptor().getElementName().equals( contentItem.getTranslationDescriptor().getElementName() ) ) {
+ buf.append( "<tr><td bgcolor=#ee6666>" );
+ buf.append( "Element names differ: " )
+ .append( contentItem.getMasterDescriptor().getElementName() )
+ .append( "/" )
+ .append( contentItem.getTranslationDescriptor().getElementName() );
+ buf.append( "</td></tr>" );
+ }
+ buf.append( "<tr><td>" );
+ buf.append( "Master: <b>" ).append( formatReference( contentItem.getMasterDescriptor() ) ).append( "</b>" );
+ buf.append( "</td></tr>" );
+ buf.append( "<tr><td>" );
+ buf.append( "Translation: <b>" ).append( formatReference( contentItem.getTranslationDescriptor() ) ).append( "</b>" );
+ buf.append( "</td></tr>" );
+ buf.append( "<tr><td>" );
+ buf.append( "Master Revision: " ).append( contentItem.getMasterDescriptor().getRevision() );
+ buf.append( "</td></tr>" );
+ buf.append( "<tr><td>" );
+ buf.append( "Translation Revision: " ).append( contentItem.getTranslationDescriptor().getRevision() );
+ buf.append( "</td></tr>" );
+ }
+
+ String result = "";
+ if ( buf.length() > 0 ) {
+ result = "<tr bgcolor=#cccccc><td><b>Translation needs update:</b></td></tr>";
+ }
+ return result + buf.toString();
+ }
+
+ private String generateNewInTranslation(Diff diff) {
+ StringBuffer buf = new StringBuffer();
+ Iterator itr = diff.getElementsOnlyInTranslation();
+ while ( itr.hasNext() ) {
+ final ContentItem contentItem = ( ContentItem ) itr.next();
+ buf.append( "<tr><td bgcolor=#eeeeee>ID: " ).append( contentItem.getIdentifier() ).append( "</td></tr>" );
+ buf.append( "<tr><td>" );
+ buf.append( "<b>" ).append( formatReference( contentItem.getTranslationDescriptor() ) ).append( "</b>" );
+ buf.append( "</td></tr>" );
+ }
+ String result = "";
+ if ( buf.length() > 0 ) {
+ result = "<tr bgcolor=#cccccc><td><b>Only present in translation:</b></td></tr>";
+ }
+ return result + buf.toString();
+ }
+
+ private String formatReference(ContentItemDescriptor descriptor) {
+ return makeSystemIdRelative( descriptor.getSourceSystemId() ) +
+ ":" + descriptor.getElementName() +
+ " (" + descriptor.getRow() + "," + descriptor.getColumn() + ")";
+ }
+
+ private String makeSystemIdRelative(String systemId) {
+ String systemIdUrl = toURL( systemId ).toExternalForm();
+ log.debug( "checking source [" + systemIdUrl + "] against base [" + base + "]" );
+ if ( systemIdUrl.startsWith( base ) ) {
+ return systemIdUrl.substring( base.length() );
+ }
+ else {
+ return systemIdUrl;
+ }
+ }
+
+ private URL toURL(String systemId) {
+ try {
+ return new URL( systemId );
+ }
+ catch ( MalformedURLException e ) {
+ throw new UnsupportedOperationException( "unable to parse systemId [" + systemId + "] as URL" );
+ }
+ }
+}
More information about the hibernate-commits
mailing list