===================================================================== Found a 112 line (589 tokens) duplication in the following files: Starting at line 292 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/xalan2/com/nwalsh/xalan/Table.java Starting at line 312 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/Table.java float relTotal = 0; float relParts[] = new float[numColumns]; float absTotal = 0; float absParts[] = new float[numColumns]; for (int count = 0; count < numColumns; count++) { String width = widths[count]; int pos = width.indexOf("*"); if (pos >= 0) { String relPart = width.substring(0, pos); String absPart = width.substring(pos+1); try { float rel = Float.parseFloat(relPart); relTotal += rel; relParts[count] = rel; } catch (NumberFormatException e) { System.out.println(relPart + " is not a valid relative unit."); } int pixels = 0; if (absPart != null && !absPart.equals("")) { pixels = convertLength(absPart); } absTotal += pixels; absParts[count] = pixels; } else { relParts[count] = 0; int pixels = 0; if (width != null && !width.equals("")) { pixels = convertLength(width); } absTotal += pixels; absParts[count] = pixels; } } // Ok, now we have the relative widths and absolute widths in // two parallel arrays. // // - If there are no relative widths, output the absolute widths // - If there are no absolute widths, output the relative widths // - If there are a mixture of relative and absolute widths, // - If the table width is absolute, turn these all into absolute // widths. // - If the table width is relative, turn these all into absolute // widths in the nominalWidth and then turn them back into // percentages. if (relTotal == 0) { for (int count = 0; count < numColumns; count++) { Float f = new Float(absParts[count]); if (foStylesheet) { int pixels = f.intValue(); float inches = (float) pixels / pixelsPerInch; widths[count] = inches + "in"; } else { widths[count] = Integer.toString(f.intValue()); } } } else if (absTotal == 0) { for (int count = 0; count < numColumns; count++) { float rel = relParts[count] / relTotal * 100; Float f = new Float(rel); widths[count] = Integer.toString(f.intValue()); } widths = correctRoundingError(widths); } else { int pixelWidth = nominalWidth; if (tableWidth.indexOf("%") <= 0) { pixelWidth = convertLength(tableWidth); } if (pixelWidth <= absTotal) { System.out.println("Table is wider than table width."); } else { pixelWidth -= absTotal; } absTotal = 0; for (int count = 0; count < numColumns; count++) { float rel = relParts[count] / relTotal * pixelWidth; relParts[count] = rel + absParts[count]; absTotal += rel + absParts[count]; } if (tableWidth.indexOf("%") <= 0) { for (int count = 0; count < numColumns; count++) { Float f = new Float(relParts[count]); if (foStylesheet) { int pixels = f.intValue(); float inches = (float) pixels / pixelsPerInch; widths[count] = inches + "in"; } else { widths[count] = Integer.toString(f.intValue()); } } } else { for (int count = 0; count < numColumns; count++) { float rel = relParts[count] / absTotal * 100; Float f = new Float(rel); widths[count] = Integer.toString(f.intValue()); } widths = correctRoundingError(widths); } } ===================================================================== Found a 96 line (421 tokens) duplication in the following files: Starting at line 78 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/xalan2/com/nwalsh/xalan/Table.java Starting at line 77 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/Table.java public Table() { } /** Initialize the internal hash table with proper values. */ protected static void initializeHash() { unitHash = new Hashtable(); unitHash.put("in", new Float(pixelsPerInch)); unitHash.put("cm", new Float(pixelsPerInch / 2.54)); unitHash.put("mm", new Float(pixelsPerInch / 25.4)); unitHash.put("pc", new Float((pixelsPerInch / 72) * 12)); unitHash.put("pt", new Float(pixelsPerInch / 72)); unitHash.put("px", new Float(1)); } /** Set the pixels-per-inch value. Only positive values are legal. */ public static void setPixelsPerInch(int value) { if (value > 0) { pixelsPerInch = value; initializeHash(); } } /** Return the current pixels-per-inch value. */ public int getPixelsPerInch() { return pixelsPerInch; } /** *

Convert a length specification to a number of pixels.

* *

The specified length should be of the form [+/-]999.99xx, * where xx is a valid unit.

*/ public static int convertLength(String length) { // The format of length should be 999.999xx int sign = 1; String digits = ""; String units = ""; char lench[] = length.toCharArray(); float flength = 0; boolean done = false; int pos = 0; float factor = 1; int pixels = 0; if (unitHash == null) { initializeHash(); } if (lench[pos] == '+' || lench[pos] == '-') { if (lench[pos] == '-') { sign = -1; } pos++; } while (!done) { if (pos >= lench.length) { done = true; } else { if ((lench[pos] > '9' || lench[pos] < '0') && lench[pos] != '.') { done = true; units = length.substring(pos); } else { digits += lench[pos++]; } } } try { flength = Float.parseFloat(digits); } catch (NumberFormatException e) { System.out.println(digits + " is not a number; 1 used instead."); flength = 1; } Float f = null; if (!units.equals("")) { f = (Float) unitHash.get(units); if (f == null) { System.out.println(units + " is not a known unit; 1 used instead."); factor = 1; } else { factor = f.floatValue(); } } else { factor = 1; } f = new Float(flength * factor); pixels = f.intValue() * sign; return pixels; } ===================================================================== Found a 51 line (286 tokens) duplication in the following files: Starting at line 44 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/xalan2/com/nwalsh/xalan/ImageIntrinsics.java Starting at line 42 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/ImageIntrinsics.java public ImageIntrinsics(String imageFn) { image = Toolkit.getDefaultToolkit().getImage (imageFn); width = image.getWidth(this); while (!imageFailed && (width == -1 || depth == -1)) { try { java.lang.Thread.currentThread().sleep(50); } catch (Exception e) { // nop; } width = image.getWidth(this); depth = image.getHeight(this); } if (imageFailed) { // Maybe it's an EPS or PDF? // FIXME: this code is crude BufferedReader ir = null; String line = null; int lineLimit = 100; try { ir = new BufferedReader(new FileReader(new File(imageFn))); line = ir.readLine(); if (line != null && line.startsWith("%PDF-")) { // We've got a PDF! while (lineLimit > 0 && line != null) { lineLimit--; if (line.startsWith("/CropBox [")) { line = line.substring(10); if (line.indexOf("]") >= 0) { line = line.substring(0, line.indexOf("]")); } parseBox(line); lineLimit = 0; } line = ir.readLine(); } } else if (line != null && line.startsWith("%!") && line.indexOf(" EPSF-") > 0) { // We've got an EPS! while (lineLimit > 0 && line != null) { lineLimit--; if (line.startsWith("%%BoundingBox: ")) { line = line.substring(15); parseBox(line); lineLimit = 0; } line = ir.readLine(); } } else { ===================================================================== Found a 38 line (244 tokens) duplication in the following files: Starting at line 455 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/CalloutEmitter.java Starting at line 151 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/NumberLinesEmitter.java while (!tempStack.empty()) { StartElementInfo elem = (StartElementInfo) tempStack.pop(); AttributeCollection attr = (AttributeCollection)elem.getAttributes(); AttributeCollection newAttr = new AttributeCollection(namePool); for (int acount = 0; acount < attr.getLength(); acount++) { String localName = attr.getLocalName(acount); int nameCode = attr.getNameCode(acount); String type = attr.getType(acount); String value = attr.getValue(acount); String uri = attr.getURI(acount); String prefix = ""; if (localName.indexOf(':') > 0) { prefix = localName.substring(0, localName.indexOf(':')); localName = localName.substring(localName.indexOf(':')+1); } if (uri.equals("") && ((foStylesheet && localName.equals("id")) || (!foStylesheet && (localName.equals("id") || localName.equals("name"))))) { // skip this attribute } else { newAttr.addAttribute(prefix, uri, localName, type, value); } } rtfEmitter.startElement(elem.getNameCode(), newAttr, elem.getNamespaces(), elem.getNSCount()); elementStack.push(elem); } } else { ===================================================================== Found a 80 line (226 tokens) duplication in the following files: Starting at line 369 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/CalloutEmitter.java Starting at line 227 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/NumberLinesEmitter.java } /** Process end element events. */ public void endElement(int nameCode) throws TransformerException { if (!elementStack.empty()) { // if we didn't push the very first element (an fo:block or // pre or div surrounding the whole block), then the stack will // be empty when we get to the end of the first element... elementStack.pop(); } rtfEmitter.endElement(nameCode); } /** Process start element events. */ public void startElement(int nameCode, org.xml.sax.Attributes attributes, int[] namespaces, int nscount) throws TransformerException { if (!skipThisElement(nameCode)) { StartElementInfo sei = new StartElementInfo(nameCode, attributes, namespaces, nscount); elementStack.push(sei); } firstElement = false; rtfEmitter.startElement(nameCode, attributes, namespaces, nscount); } /** *

Protect the outer-most block wrapper.

* *

Open elements in the result tree fragment are closed and reopened * around callouts (so that callouts don't appear inside links or other * environments). But if the result tree fragment is a single block * (a div or pre in HTML, an fo:block in FO), that outer-most block is * treated specially.

* *

This method returns true if the element in question is that * outermost block.

* * @param nameCode The name code for the element * * @return True if the element is the outer-most block, false otherwise. */ protected boolean skipThisElement(int nameCode) { // FIXME: This is such a gross hack... if (firstElement) { int thisFingerprint = namePool.getFingerprint(nameCode); int foBlockFingerprint = namePool.getFingerprint(foURI, "block"); int htmlPreFingerprint = namePool.getFingerprint("", "pre"); int htmlDivFingerprint = namePool.getFingerprint("", "div"); int xhtmlPreFingerprint = namePool.getFingerprint(xhURI, "pre"); int xhtmlDivFingerprint = namePool.getFingerprint(xhURI, "div"); if ((foStylesheet && thisFingerprint == foBlockFingerprint) || (!foStylesheet && (thisFingerprint == htmlPreFingerprint || thisFingerprint == htmlDivFingerprint || thisFingerprint == xhtmlPreFingerprint || thisFingerprint == xhtmlDivFingerprint))) { // Don't push the outer-most wrapping div, pre, or fo:block return true; } } return false; } /** *

A private class for maintaining the information required to call * the startElement method.

* *

In order to close and reopen elements, information about those * elements has to be maintained. This class is just the little record * that we push on the stack to keep track of that info.

*/ private class StartElementInfo { ===================================================================== Found a 36 line (193 tokens) duplication in the following files: Starting at line 496 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/xalan2/com/nwalsh/xalan/Table.java Starting at line 442 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/Table.java protected static String[] correctRoundingError(String widths[]) { int totalWidth = 0; for (int count = 0; count < widths.length; count++) { try { int width = Integer.parseInt(widths[count]); totalWidth += width; } catch (NumberFormatException nfe) { // nop; "can't happen" } } float totalError = 100 - totalWidth; float columnError = totalError / widths.length; float error = 0; for (int count = 0; count < widths.length; count++) { try { int width = Integer.parseInt(widths[count]); error = error + columnError; if (error >= 1.0) { int adj = (int) Math.round(Math.floor(error)); error = error - (float) Math.floor(error); width = width + adj; widths[count] = Integer.toString(width) + "%"; } else { widths[count] = Integer.toString(width) + "%"; } } catch (NumberFormatException nfe) { // nop; "can't happen" } } return widths; } } ===================================================================== Found a 46 line (187 tokens) duplication in the following files: Starting at line 760 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/xalan2/com/nwalsh/xalan/Verbatim.java Starting at line 311 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/CalloutEmitter.java && !units.equalsIgnoreCase("linerange")) { System.out.println("Only linecolumn and linerange units are supported"); return; } if (coords == null) { System.out.println("Coords must be specified"); return; } // Now let's see if we can interpret the coordinates... StringTokenizer st = new StringTokenizer(coords); int tokenCount = 0; int c1 = 0; int c2 = 0; while (st.hasMoreTokens()) { tokenCount++; if (tokenCount > 2) { System.out.println("Unparseable coordinates"); return; } try { String token = st.nextToken(); int coord = Integer.parseInt(token); c2 = coord; if (tokenCount == 1) { c1 = coord; } } catch (NumberFormatException e) { System.out.println("Unparseable coordinate"); return; } } // Make sure we aren't going to blow past the end of our array if (calloutCount == callout.length) { Callout bigger[] = new Callout[calloutCount+10]; for (int count = 0; count < callout.length; count++) { bigger[count] = callout[count]; } callout = bigger; } // Ok, add the callout if (tokenCount == 2) { if (units != null && units.equalsIgnoreCase("linerange")) { ===================================================================== Found a 43 line (184 tokens) duplication in the following files: Starting at line 117 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/xalan2/com/nwalsh/xalan/ImageIntrinsics.java Starting at line 117 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/ImageIntrinsics.java public int getDepth(int defaultDepth) { if (depth >= 0) { return depth; } else { return defaultDepth; } } private void parseBox(String line) { int [] corners = new int [4]; int count = 0; StringTokenizer st = new StringTokenizer(line); while (count < 4 && st.hasMoreTokens()) { try { corners[count++] = Integer.parseInt(st.nextToken()); } catch (Exception e) { // nop; } } width = corners[2] - corners[0]; depth = corners[3] - corners[1]; } public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { if ((infoflags & ImageObserver.ERROR) == ImageObserver.ERROR) { imageFailed = true; return false; } // I really only care about the width and height, but if I return false as // soon as those are available, the BufferedInputStream behind the loader // gets closed too early. int flags = ImageObserver.ALLBITS; if ((infoflags & flags) == flags) { return false; } else { return true; } } } ===================================================================== Found a 32 line (178 tokens) duplication in the following files: Starting at line 59 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/xalan2/com/nwalsh/xalan/CVS.java Starting at line 59 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/CVS.java public static String localTime (String cvsDate) { // A cvsDate has the following form "$Date: 2004/03/15 14:20:36 $" if (!cvsDate.startsWith("$Date: ")) { return cvsDate; } String yrS = cvsDate.substring(7,11); String moS = cvsDate.substring(12,14); String daS = cvsDate.substring(15,17); String hrS = cvsDate.substring(18,20); String miS = cvsDate.substring(21,23); String seS = cvsDate.substring(24,26); TimeZone tz = TimeZone.getTimeZone("GMT+0"); GregorianCalendar gmtCal = new GregorianCalendar(tz); try { gmtCal.set(Integer.parseInt(yrS), Integer.parseInt(moS)-1, Integer.parseInt(daS), Integer.parseInt(hrS), Integer.parseInt(miS), Integer.parseInt(seS)); } catch (NumberFormatException e) { // nop } Date d = gmtCal.getTime(); return d.toString(); } } ===================================================================== Found a 27 line (164 tokens) duplication in the following files: Starting at line 462 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/CalloutEmitter.java Starting at line 156 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/UnwrapLinksEmitter.java String localName = attr.getLocalName(acount); String type = attr.getType(acount); String value = attr.getValue(acount); String uri = attr.getURI(acount); String prefix = ""; if (localName.indexOf(':') > 0) { prefix = localName.substring(0, localName.indexOf(':')); localName = localName.substring(localName.indexOf(':')+1); } if (uri.equals("") && ((foStylesheet && localName.equals("id")) || (!foStylesheet && (localName.equals("id") || localName.equals("name"))))) { // skip this attribute } else { newAttr.addAttribute(prefix, uri, localName, type, value); } } rtfEmitter.startElement(elem.getNameCode(), newAttr, elem.getNamespaces(), elem.getNSCount()); ===================================================================== Found a 59 line (156 tokens) duplication in the following files: Starting at line 71 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/xalan2/com/nwalsh/xalan/Callout.java Starting at line 31 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/Callout.java } /** *

The compareTo method compares this Callout with another.

* *

Given two Callouts, A and B, A < B if:

* *
    *
  1. A.line < B.line, or
  2. *
  3. A.line = B.line && A.col < B.col, or
  4. *
  5. A.line = B.line && A.col = B.col && A.callout < B.callout
  6. *
  7. Otherwise, they're equal.
  8. *
*/ public int compareTo (Object o) { Callout c = (Callout) o; if (line == c.getLine()) { if (col > c.getColumn()) { return 1; } else if (col < c.getColumn()) { return -1; } else { if (callout < c.getCallout()) { return -1; } else if (callout > c.getCallout()) { return 1; } else { return 0; } } } else { if (line > c.getLine()) { return 1; } else { return -1; } } } /** Access the Callout's area. */ public Element getArea() { return area; } /** Access the Callout's line. */ public int getLine() { return line; } /** Access the Callout's column. */ public int getColumn() { return col; } /** Access the Callout's callout number. */ public int getCallout() { return callout; } ===================================================================== Found a 17 line (116 tokens) duplication in the following files: Starting at line 474 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/xalan2/com/nwalsh/xalan/Table.java Starting at line 914 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/xalan2/com/nwalsh/xalan/Verbatim.java } private Attributes copyAttributes(Element node) { AttributesImpl attrs = new AttributesImpl(); NamedNodeMap nnm = node.getAttributes(); for (int count = 0; count < nnm.getLength(); count++) { Attr attr = (Attr) nnm.item(count); String name = attr.getName(); if (name.startsWith("xmlns:") || name.equals("xmlns")) { // Skip it; (don't ya just love it!!) } else { attrs.addAttribute(attr.getNamespaceURI(), attr.getName(), attr.getName(), "CDATA", attr.getValue()); } } return attrs; } ===================================================================== Found a 13 line (106 tokens) duplication in the following files: Starting at line 309 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/xalan2/com/nwalsh/xalan/Verbatim.java Starting at line 691 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/xalan2/com/nwalsh/xalan/Verbatim.java } if (pos > 0) { rtf.characters(chars, 0, pos); } } else if (node.getNodeType() == Node.COMMENT_NODE) { String text = node.getNodeValue(); char chars[] = text.toCharArray(); rtf.comment(chars, 0, text.length()); } else if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { rtf.processingInstruction(node.getNodeName(), node.getNodeValue()); } else { System.out.println("Warning: unexpected node type in calloutFragment: " + node.getNodeType() + ": " + node.getNodeName()); ===================================================================== Found a 43 line (105 tokens) duplication in the following files: Starting at line 492 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/CalloutEmitter.java Starting at line 191 of /home/tom/pmd/pmd-web/src/sushi/WEB-INF/src/xml/stylesheets/docbook-xsl-1.65.1/extensions/saxon643/com/nwalsh/saxon/UnwrapLinksEmitter.java } /** *

A private class for maintaining the information required to call * the startElement method.

* *

In order to close and reopen elements, information about those * elements has to be maintained. This class is just the little record * that we push on the stack to keep track of that info.

*/ private class StartElementInfo { private int _nameCode; org.xml.sax.Attributes _attributes; int[] _namespaces; int _nscount; public StartElementInfo(int nameCode, org.xml.sax.Attributes attributes, int[] namespaces, int nscount) { _nameCode = nameCode; _attributes = attributes; _namespaces = namespaces; _nscount = nscount; } public int getNameCode() { return _nameCode; } public org.xml.sax.Attributes getAttributes() { return _attributes; } public int[] getNamespaces() { return _namespaces; } public int getNSCount() { return _nscount; } } }