Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,15 @@ private String getBulletPrefix(ListAutoNumber scheme, int value) {
* Convert an integer to its alpha equivalent e.g. 1 = A, 2 = B, 27 = AA etc
*/
private String valueToAlpha(int value) {
String alpha = "";
StringBuilder alpha = new StringBuilder();
int modulo;
while (value > 0) {
modulo = (value - 1) % 26;
alpha = (char) (65 + modulo) + alpha;
alpha.append((char) (65 + modulo));
value = (value - modulo) / 26;
}
return alpha;
alpha.reverse();
return alpha.toString();
}

private static String[] _romanChars = new String[] { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public String getLocalXPath() {

String[] xPathTokens = ctXmlColumnPr.getXpath().split("/");
for (int i = numberOfCommonXPathAxis; i < xPathTokens.length; i++) {
localXPath.append("/" + xPathTokens[i]);
localXPath.append("/").append(xPathTokens[i]);
}
return localXPath.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import java.util.Locale;

import org.apache.poi.hsmf.datatypes.Types.MAPIType;
import org.apache.poi.util.StringUtil;

public abstract class Chunk {
public static final String DEFAULT_NAME_PREFIX = "__substg1.0_";
Expand Down Expand Up @@ -62,13 +63,14 @@ public MAPIType getType() {
public String getEntryName() {
String type = this.type.asFileEnding();

String chunkId = Integer.toHexString(this.chunkId);
while (chunkId.length() < 4) {
chunkId = "0" + chunkId;
StringBuilder chunkId = new StringBuilder(Integer.toHexString(this.chunkId));
int need0count = 4 - chunkId.length();
if (need0count > 0) {
chunkId.insert(0, StringUtil.repeat('0', need0count));
}

return this.namePrefix
+ chunkId.toUpperCase(Locale.ROOT)
+ chunkId.toString().toUpperCase(Locale.ROOT)
+ type.toUpperCase(Locale.ROOT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ Licensed to the Apache Software Foundation (ASF) under one or more

package org.apache.poi.hsmf.datatypes;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.apache.poi.hsmf.datatypes.Types.MAPIType;

import static org.apache.poi.hsmf.datatypes.Types.ASCII_STRING;
import static org.apache.poi.hsmf.datatypes.Types.BINARY;
import static org.apache.poi.hsmf.datatypes.Types.BOOLEAN;
Expand All @@ -27,14 +35,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import static org.apache.poi.hsmf.datatypes.Types.SHORT;
import static org.apache.poi.hsmf.datatypes.Types.TIME;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.apache.poi.hsmf.datatypes.Types.MAPIType;

/**
* Holds the list of MAPI Attributes, and allows lookup by friendly name, ID and
* MAPI Property Name.
Expand Down Expand Up @@ -1069,9 +1069,10 @@ private MAPIProperty(int id, MAPIType usualType, String name,
}

public String asFileName() {
String str = Integer.toHexString(id).toUpperCase(Locale.ROOT);
while (str.length() < 4) {
str = "0" + str;
StringBuilder str = new StringBuilder(Integer.toHexString(id).toUpperCase(Locale.ROOT));
int need0count = 4 - str.length();
if (need0count > 0) {
str.insert(0, StringUtil.repeat('0', need0count));
}
return str + usualType.asFileEnding();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more

package org.apache.poi.hsmf.datatypes;

import static org.apache.logging.log4j.util.Unbox.box;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -48,6 +46,9 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndian.BufferUnderrunException;
import org.apache.poi.util.StringUtil;

import static org.apache.logging.log4j.util.Unbox.box;

/**
* <p>
Expand Down Expand Up @@ -419,9 +420,10 @@ private void writeVariableLengthValueHeader(OutputStream out, MAPIProperty prope
}

private String getFileName(MAPIProperty property, MAPIType actualType) {
String str = Integer.toHexString(property.id).toUpperCase(Locale.ROOT);
while (str.length() < 4) {
str = "0" + str;
StringBuilder str = new StringBuilder(Integer.toHexString(property.id).toUpperCase(Locale.ROOT));
int need0count = 4 - str.length();
if (need0count > 0) {
str.insert(0, StringUtil.repeat('0', need0count));
}
MAPIType type = getTypeMapping(actualType);
return str + type.asFileEnding();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import java.util.Locale;
import java.util.Map;

import org.apache.poi.util.StringUtil;

/**
* The types list and details are available from
* http://msdn.microsoft.com/en-us/library/microsoft.exchange.data.contenttypes.tnef.tnefpropertytype%28v=EXCHG.140%29.aspx
Expand Down Expand Up @@ -148,11 +150,12 @@ public static MAPIType getById(int typeId) {
}

public static String asFileEnding(int type) {
String str = Integer.toHexString(type).toUpperCase(Locale.ROOT);
while (str.length() < 4) {
str = "0" + str;
StringBuilder str = new StringBuilder(Integer.toHexString(type).toUpperCase(Locale.ROOT));
int need0count = 4 - str.length();
if (need0count > 0) {
str.insert(0, StringUtil.repeat('0', need0count));
}
return str;
return str.toString();
}

public static String asName(int typeId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import java.util.Comparator;

import org.apache.poi.hsmf.datatypes.MAPIProperty;
import org.apache.poi.util.StringUtil;

/**
* Lists the different MAPI types
Expand Down Expand Up @@ -49,8 +50,11 @@ public int compare(MAPIProperty a, MAPIProperty b) {
}
private void list(ArrayList<MAPIProperty> list, PrintStream out) {
for(MAPIProperty attr : list) {
String id = Integer.toHexString(attr.id);
while(id.length() < 4) { id = "0"+id; }
StringBuilder id = new StringBuilder(Integer.toHexString(attr.id));
int need0count = 4 - id.length();
if (need0count > 0) {
id.insert(0, StringUtil.repeat('0', need0count));
}

int typeId = attr.usualType.getId();
String typeIdStr = Integer.toString(typeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class WordToHtmlUtils extends AbstractWordUtils
{
public static void addBold( final boolean bold, StringBuilder style )
{
style.append( "font-weight:" + ( bold ? "bold" : "normal" ) + ";" );
style.append("font-weight:").append(bold ? "bold" : "normal").append(";");
}

public static void addBorder( BorderCode borderCode, String where,
Expand Down Expand Up @@ -71,22 +71,19 @@ public static void addCharactersProperties(
}
if ( characterRun.getIco24() != -1 )
{
style.append( "color:" + getColor24( characterRun.getIco24() )
+ ";" );
style.append("color:").append(getColor24(characterRun.getIco24())).append(";");
}
if ( characterRun.isHighlighted() )
{
style.append( "background-color:"
+ getColor( characterRun.getHighlightedColor() ) + ";" );
style.append("background-color:").append(getColor(characterRun.getHighlightedColor())).append(";");
}
if ( characterRun.isStrikeThrough() )
{
style.append( "text-decoration:line-through;" );
}
if ( characterRun.isShadowed() )
{
style.append( "text-shadow:" + characterRun.getFontSize() / 24
+ "pt;" );
style.append("text-shadow:").append(characterRun.getFontSize() / 24).append("pt;");
}
if ( characterRun.isSmallCaps() )
{
Expand Down Expand Up @@ -118,12 +115,12 @@ public static void addFontFamily( final String fontFamily,
if ( isEmpty( fontFamily ) )
return;

style.append( "font-family:" + fontFamily + ";" );
style.append("font-family:").append(fontFamily).append(";");
}

public static void addFontSize( final int fontSize, StringBuilder style )
{
style.append( "font-size:" + fontSize + "pt;" );
style.append("font-size:").append(fontSize).append("pt;");
}

public static void addIndent( Paragraph paragraph, StringBuilder style )
Expand All @@ -143,15 +140,15 @@ private static void addIndent( StringBuilder style, final String cssName,
if ( twipsValue == 0 )
return;

style.append( cssName + ":" + ( twipsValue / TWIPS_PER_INCH ) + "in;" );
style.append(cssName).append(":").append(twipsValue / TWIPS_PER_INCH).append("in;");
}

public static void addJustification( Paragraph paragraph,
final StringBuilder style )
{
String justification = getJustification( paragraph.getJustification() );
if ( isNotEmpty( justification ) )
style.append( "text-align:" + justification + ";" );
style.append("text-align:").append(justification).append(";");
}

public static void addParagraphProperties( Paragraph paragraph,
Expand All @@ -170,8 +167,7 @@ public static void addParagraphProperties( Paragraph paragraph,
style.append( "break-before:page;" );
}

style.append( "hyphenate:"
+ ( paragraph.isAutoHyphenated() ? "auto" : "none" ) + ";" );
style.append("hyphenate:").append(paragraph.isAutoHyphenated() ? "auto" : "none").append(";");

if ( paragraph.keepOnPage() )
{
Expand All @@ -188,12 +184,9 @@ public static void addTableCellProperties( TableRow tableRow,
TableCell tableCell, boolean toppest, boolean bottomest,
boolean leftest, boolean rightest, StringBuilder style )
{
style.append( "width:" + ( tableCell.getWidth() / TWIPS_PER_INCH )
+ "in;" );
style.append( "padding-start:"
+ ( tableRow.getGapHalf() / TWIPS_PER_INCH ) + "in;" );
style.append( "padding-end:"
+ ( tableRow.getGapHalf() / TWIPS_PER_INCH ) + "in;" );
style.append("width:").append(tableCell.getWidth() / TWIPS_PER_INCH).append("in;");
style.append("padding-start:").append(tableRow.getGapHalf() / TWIPS_PER_INCH).append("in;");
style.append("padding-end:").append(tableRow.getGapHalf() / TWIPS_PER_INCH).append("in;");

BorderCode top = tableCell.getBrcTop() != null
&& tableCell.getBrcTop().getBorderType() != 0 ? tableCell
Expand Down Expand Up @@ -224,8 +217,7 @@ public static void addTableRowProperties( TableRow tableRow,
{
if ( tableRow.getRowHeight() > 0 )
{
style.append( "height:"
+ ( tableRow.getRowHeight() / TWIPS_PER_INCH ) + "in;" );
style.append("height:").append(tableRow.getRowHeight() / TWIPS_PER_INCH).append("in;");
}
if ( !tableRow.cantSplit() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void testReadFields() {
private String dumpPlexes(ArrayList<PlexOfField> fieldsPlexes) {
StringBuilder dump = new StringBuilder();
for (PlexOfField flds : fieldsPlexes) {
dump.append(flds + "\n");
dump.append(flds).append("\n");
}
return dump.toString();
}
Expand Down
15 changes: 8 additions & 7 deletions poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPalette.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import org.apache.poi.hssf.record.PaletteRecord;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
import org.apache.poi.util.StringUtil;

/**
* Represents a workbook color palette.
Expand Down Expand Up @@ -218,22 +219,22 @@ public String getHexString() {

private String getGnumericPart(byte color)
{
String s;
StringBuilder s;
if (color == 0)
{
s = "0";
s = new StringBuilder("0");
}
else
{
int c = color & 0xff; //as unsigned
c = (c << 8) | c; //pad to 16-bit
s = Integer.toHexString(c).toUpperCase(Locale.ROOT);
while (s.length() < 4)
{
s = "0" + s;
s = new StringBuilder(Integer.toHexString(c).toUpperCase(Locale.ROOT));
int need0count = 4 - s.length();
if (need0count > 0) {
s.insert(0, StringUtil.repeat('0', need0count));
}
}
return s;
return s.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import org.apache.poi.ss.formula.eval.OperandResolver;
import org.apache.poi.ss.formula.eval.RefEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.util.StringUtil;

/**
* Implementation for Excel Bin2Dec() function.
Expand Down Expand Up @@ -109,9 +110,12 @@ private int getDecimalValue(String unsigned) {
private static String toggleBits(String s) {
long i = Long.parseLong(s, 2);
long i2 = i ^ ((1L << s.length()) - 1);
String s2 = Long.toBinaryString(i2);
while (s2.length() < s.length()) s2 = '0' + s2;
return s2;
StringBuilder s2 = new StringBuilder(Long.toBinaryString(i2));
int need0count = s.length() - s2.length();
if (need0count > 0) {
s2.insert(0, StringUtil.repeat('0', need0count));
}
return s2.toString();
}

@Override
Expand Down
Loading