db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r1437872 - in /db/derby/code/trunk/java/build/org/apache/derbyBuild: GeneratorBase.java ReleaseNotesGenerator.java
Date Thu, 24 Jan 2013 07:18:37 GMT
Author: kristwaa
Date: Thu Jan 24 07:18:37 2013
New Revision: 1437872

URL: http://svn.apache.org/viewvc?rev=1437872&view=rev
Log:
DERBY-6044: Fix poor word breaking in table on download page(s)

Some browsers break up DERBY-XXXX at the hyphen even though they shouldn't.
Work around this by using a div-element to size the first column of the table.

Patch file: derby-6044-1a-stop_breaking_up_jira_id.diff

Modified:
    db/derby/code/trunk/java/build/org/apache/derbyBuild/GeneratorBase.java
    db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNotesGenerator.java

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/GeneratorBase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/GeneratorBase.java?rev=1437872&r1=1437871&r2=1437872&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/GeneratorBase.java (original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/GeneratorBase.java Thu Jan 24 07:18:37
2013
@@ -54,6 +54,7 @@ public class GeneratorBase extends Task 
     private static final String BOLD = "b";
     private static final String BORDER = "border";
     private static final String COLUMN = "td";
+    private static final String COLUMN_HEADER = "th";
     private static final String HORIZONTAL_LINE = "hr";
     protected static final String HTML = "html";
     private static final String DIVISION = "div";
@@ -299,6 +300,39 @@ public class GeneratorBase extends Task 
     }
 
     /**
+     * Wraps the text content of the given node inside a div tag.
+     *
+     * @param node node currently containing the text
+     * @return The new div-element which has been appended to {@code node}.
+     * @throws DOMException 
+     */
+    private static Element wrapTextContentInDiv(Element node)
+            throws DOMException {
+        Document doc = node.getOwnerDocument();
+        Element div = doc.createElement(DIVISION);
+        div.setTextContent(node.getTextContent());
+        node.setTextContent("");
+        node.appendChild(div);
+        return div;
+    }
+
+    /**
+     * Sets/overwrites the specified attribute.
+     *
+     * @param node target node
+     * @param name attribute name
+     * @param value attribute value
+     * @throws DOMException 
+     */
+    private static void setAttribute(Element node, String name, String value)
+            throws DOMException {
+        Node attr = node.getOwnerDocument().createAttribute(name);
+        attr.setNodeValue(value);
+
+        node.getAttributes().setNamedItem(attr);
+    }
+    
+    /**
      * Create an html text element.
      * @param doc
      * @param tag
@@ -517,22 +551,35 @@ public class GeneratorBase extends Task 
         Document doc = parent.getOwnerDocument();
         Element table = doc.createElement(TABLE);
         Element headingRow = insertRow(table);
-        int count = columnHeadings.length;
 
         parent.appendChild(table);
         table.setAttribute(BORDER, Integer.toString(borderWidth));
 
-        for (int i = 0; i < count; i++) {
-            Element headingColumn = insertColumn(headingRow);
-            Element boldText = boldText(doc, columnHeadings[i]);
-
-            headingColumn.appendChild(boldText);
+        for (String headerText : columnHeadings) {
+            Element headingColumn = insertColumnHeader(headingRow);
+            headingColumn.setTextContent(headerText);
         }
 
         return table;
     }
 
     /**
+     * Sets the width of the first column in the given table.
+     *
+     * @param table target table
+     * @throws DOMException
+     */
+    protected void fixWidthOfFirstColumn(Element table)
+            throws DOMException {
+        NodeList headers = table.getElementsByTagName(COLUMN_HEADER);
+        // Just fail if someone removes the th-elements.
+        Element th = (Element)headers.item(0);
+        Element div = wrapTextContentInDiv(th);
+        setAttribute(div, "style", "width:110px;");
+        th.appendChild(div);
+    }
+    
+    /**
      * Insert a row at the end of a table
      * @param table
      * @return created row Element
@@ -540,12 +587,7 @@ public class GeneratorBase extends Task 
      */
     public static Element insertRow(Element table)
             throws Exception {
-        Document doc = table.getOwnerDocument();
-        Element row = doc.createElement(ROW);
-
-        table.appendChild(row);
-
-        return row;
+        return insertTableElement(table, ROW);
     }
 
     /**
@@ -556,12 +598,36 @@ public class GeneratorBase extends Task 
      */
     public static Element insertColumn(Element row)
             throws Exception {
-        Document doc = row.getOwnerDocument();
-        Element column = doc.createElement(COLUMN);
+        return insertTableElement(row, COLUMN);
+    }
+
+    /**
+     * Insert a header column at the end of the row.
+     * @param row
+     * @return Created column Element
+     * @throws DOMException
+     */
+    public static Element insertColumnHeader(Element row)
+            throws DOMException {
+        return insertTableElement(row, COLUMN_HEADER);
+    }
 
-        row.appendChild(column);
+    /**
+     * Inserts the specified element to the parent element.
+     *
+     * @param parent enclosing element, typically a table or a row
+     * @param type type of the new element to be inserted, typically a
+     *      column value or a row
+     * @return The newly inserted element.
+     * @throws DOMException if modifying the DOM fails
+     */
+    private static Element insertTableElement(Element parent, String type)
+            throws DOMException {
+        Document doc = parent.getOwnerDocument();
+        Element newElement = doc.createElement(type);
+        parent.appendChild(newElement);
 
-        return column;
+        return newElement;
     }
 
     /**

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNotesGenerator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNotesGenerator.java?rev=1437872&r1=1437871&r2=1437872&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNotesGenerator.java (original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/ReleaseNotesGenerator.java Thu Jan
24 07:18:37 2013
@@ -332,6 +332,9 @@ public class ReleaseNotesGenerator exten
         Element table = createTable
             (bugListSection, DEFAULT_TABLE_BORDER_WIDTH,
             new String[] { ISSUE_ID_HEADLINE, DESCRIPTION_HEADLINE });
+        // If we don't fix the width of the first column, the string
+        // "DERBY-XXXX" is often broken up at the hyphen by some browsers.
+        fixWidthOfFirstColumn(table);
 
         for ( Iterator i=bugList.iterator(); i.hasNext(); ) {
             JiraIssue issue = (JiraIssue) i.next();



Mime
View raw message