Skip to content

Commit

Permalink
Merge pull request #507 from syjer/remove-unused-utils-2
Browse files Browse the repository at this point in the history
remove more unused utils/misc cleanup
  • Loading branch information
danfickle authored Jul 10, 2020
2 parents 77bc108 + b29fed6 commit 684fd40
Show file tree
Hide file tree
Showing 15 changed files with 15 additions and 1,475 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,63 +48,6 @@ public final class ValueConstants {
*/
private final static Map<Short, String> sacTypesStrings;

/**
* A text representation of the CSS type for this value.
*
* @param cssType PARAM
* @param primitiveValueType PARAM
* @return Returns
*/
public static String cssType(int cssType, int primitiveValueType) {
String desc = null;
if (cssType == CSSValue.CSS_PRIMITIVE_VALUE) {
if (primitiveValueType >= TYPE_DESCRIPTIONS.size()) {
desc = "{unknown: " + primitiveValueType + "}";
} else {
desc = TYPE_DESCRIPTIONS.get(primitiveValueType);
if (desc == null) {
desc = "{UNKNOWN VALUE TYPE}";
}
}
} else {
desc = "{value list}";
}
return desc;
}

/**
* Description of the Method
*
* @param type PARAM
* @return Returns
*/
public static short sacPrimitiveTypeForString(String type) {
if ("em".equals(type)) {
return CSSPrimitiveValue.CSS_EMS;
} else if ("ex".equals(type)) {
return CSSPrimitiveValue.CSS_EXS;
} else if ("px".equals(type)) {
return CSSPrimitiveValue.CSS_PX;
} else if ("%".equals(type)) {
return CSSPrimitiveValue.CSS_PERCENTAGE;
} else if ("in".equals(type)) {
return CSSPrimitiveValue.CSS_IN;
} else if ("cm".equals(type)) {
return CSSPrimitiveValue.CSS_CM;
} else if ("mm".equals(type)) {
return CSSPrimitiveValue.CSS_MM;
} else if ("pt".equals(type)) {
return CSSPrimitiveValue.CSS_PT;
} else if ("pc".equals(type)) {
return CSSPrimitiveValue.CSS_PC;
} else if (type == null) {
//this is only valid if length is 0
return CSSPrimitiveValue.CSS_PX;
} else {
throw new XRRuntimeException("Unknown type on CSS value: " + type);
}
}

/**
* Description of the Method
*
Expand All @@ -115,22 +58,6 @@ public static String stringForSACPrimitiveType(short type) {
return sacTypesStrings.get(new Short(type));
}

/**
* Returns true if the specified value was absolute (even if we have a
* computed value for it), meaning that either the value can be used
* directly (e.g. pixels) or there is a fixed context-independent conversion
* for it (e.g. inches). Proportional types (e.g. %) return false.
*
* @param primitive The CSSValue instance to check.
* @return See desc.
*/
//TODO: method may be unnecessary (tobe)
public static boolean isAbsoluteUnit(CSSPrimitiveValue primitive) {
short type = 0;
type = primitive.getPrimitiveType();
return isAbsoluteUnit(type);
}

/**
* Returns true if the specified type absolute (even if we have a computed
* value for it), meaning that either the value can be used directly (e.g.
Expand Down Expand Up @@ -202,27 +129,6 @@ public static boolean isAbsoluteUnit(short type) {
}
}

/**
* Gets the cssValueTypeDesc attribute of the {@link CSSValue} object
*
* @param cssValue PARAM
* @return The cssValueTypeDesc value
*/
public static String getCssValueTypeDesc(CSSValue cssValue) {
switch (cssValue.getCssValueType()) {
case CSSValue.CSS_CUSTOM:
return "CSS_CUSTOM";
case CSSValue.CSS_INHERIT:
return "CSS_INHERIT";
case CSSValue.CSS_PRIMITIVE_VALUE:
return "CSS_PRIMITIVE_VALUE";
case CSSValue.CSS_VALUE_LIST:
return "CSS_VALUE_LIST";
default:
return "UNKNOWN";
}
}

/**
* Returns true if the SAC primitive value type is a number unit--a unit
* that can only contain a numeric value. This is a shorthand way of saying,
Expand Down Expand Up @@ -306,53 +212,6 @@ public static boolean isNumber(short cssPrimitiveType) {
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_PC), "pc");
}

/**
* Incomplete routine to try and determine the
* CSSPrimitiveValue short code for a given value,
* e.g. 14pt is CSS_PT.
*
* @param value PARAM
* @return Returns
*/
public static short guessType(String value) {
short type = CSSPrimitiveValue.CSS_STRING;
if (value != null && value.length() > 1) {
if (value.endsWith("%")) {
type = CSSPrimitiveValue.CSS_PERCENTAGE;
} else if (value.startsWith("rgb") || value.startsWith("#")) {
type = CSSPrimitiveValue.CSS_RGBCOLOR;
} else {
String hmm = value.substring(value.length() - 2);
if ("pt".equals(hmm)) {
type = CSSPrimitiveValue.CSS_PT;
} else if ("px".equals(hmm)) {
type = CSSPrimitiveValue.CSS_PX;
} else if ("em".equals(hmm)) {
type = CSSPrimitiveValue.CSS_EMS;
} else if ("ex".equals(hmm)) {
type = CSSPrimitiveValue.CSS_EXS;
} else if ("in".equals(hmm)) {
type = CSSPrimitiveValue.CSS_IN;
} else if ("cm".equals(hmm)) {
type = CSSPrimitiveValue.CSS_CM;
} else if ("mm".equals(hmm)) {
type = CSSPrimitiveValue.CSS_MM;
} else {
if (Character.isDigit(value.charAt(value.length() - 1))) {
try {
new Float(value);
type = CSSPrimitiveValue.CSS_NUMBER;
} catch (NumberFormatException ex) {
type = CSSPrimitiveValue.CSS_STRING;
}
} else {
type = CSSPrimitiveValue.CSS_STRING;
}
}
}
}
return type;
}
}// end class

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.openhtmltopdf.css.extend.StylesheetFactory;
import com.openhtmltopdf.css.extend.TreeResolver;
import com.openhtmltopdf.css.sheet.*;
import com.openhtmltopdf.util.Util;
import com.openhtmltopdf.util.XRLog;


Expand Down Expand Up @@ -220,14 +219,18 @@ private Mapper getMapper(Object e) {
return m;
}

private static boolean isNullOrEmpty(String str) {
return str == null || str.length() == 0;
}

private com.openhtmltopdf.css.sheet.Ruleset getElementStyle(Object e) {
//synchronized (e) {
if (_attRes == null || _styleFactory == null) {
return null;
}

String style = _attRes.getElementStyling(e);
if (Util.isNullOrEmpty(style)) {
if (isNullOrEmpty(style)) {
return null;
}

Expand All @@ -241,7 +244,7 @@ private com.openhtmltopdf.css.sheet.Ruleset getNonCssStyle(Object e) {
return null;
}
String style = _attRes.getNonCssStyling(e);
if (Util.isNullOrEmpty(style)) {
if (isNullOrEmpty(style)) {
return null;
}
return _styleFactory.parseStyleDeclaration(com.openhtmltopdf.css.sheet.StylesheetInfo.AUTHOR, style);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
import java.util.logging.Level;

Expand Down Expand Up @@ -1974,14 +1972,6 @@ private String getTokenValue(Token t, boolean literal) {
}
}

private boolean isRelativeURI(String uri) {
try {
return uri.length() > 0 && (uri.charAt(0) != '/' && ! new URI(uri).isAbsolute());
} catch (URISyntaxException e) {
return false;
}
}

private int getCurrentLine() {
return _lexer.yyline();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ public void setChildOffset(int childOffset) {

private static class RelayoutData {
private LayoutState _layoutState;
private int _listIndex;

private boolean _startsRun;
private boolean _endsRun;
Expand Down Expand Up @@ -482,14 +481,6 @@ public int getChildOffset() {
public void setChildOffset(int childOffset) {
_childOffset = childOffset;
}

public int getListIndex() {
return _listIndex;
}

public void setListIndex(int listIndex) {
_listIndex = listIndex;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,34 +196,18 @@ public void setInitialMeasurements(InlineBoxMeasurements measurements) {
}

private static final class ChildContextData {
private Box _root;
private VerticalAlignContext _verticalAlignContext;


public ChildContextData() {
}
private final Box _root;
private final VerticalAlignContext _verticalAlignContext;

public ChildContextData(Box root, VerticalAlignContext vaContext) {
_root = root;
_verticalAlignContext = vaContext;
}

public Box getRoot() {
return _root;
}

public void setRoot(Box root) {
_root = root;
}

public VerticalAlignContext getVerticalAlignContext() {
return _verticalAlignContext;
}

public void setVerticalAlignContext(VerticalAlignContext verticalAlignContext) {
_verticalAlignContext = verticalAlignContext;
}

private void moveContextContents(int ty) {
moveInlineContents(_root, ty);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import com.openhtmltopdf.extend.FSImage;
import com.openhtmltopdf.extend.OutputDevice;
import com.openhtmltopdf.util.Configuration;
import com.openhtmltopdf.util.Uu;
import com.openhtmltopdf.util.XRLog;

import java.awt.*;
import java.awt.geom.Area;
Expand All @@ -50,14 +50,6 @@
* implementations for many <code>OutputDevice</code> methods.
*/
public abstract class AbstractOutputDevice implements OutputDevice {

public static class ClipInfo {
public final List<Object> _ops;

public ClipInfo(List<Object> ops) {
this._ops = ops;
}
}

private FontSpecification _fontSpec;

Expand Down Expand Up @@ -210,8 +202,7 @@ private FSImage getBackgroundImage(RenderingContext c, CalculatedStyle style) {
try {
return c.getUac().getImageResource(uri).getImage();
} catch (Exception ex) {
ex.printStackTrace();
Uu.p(ex);
XRLog.exception("Failed to load background image at uri " + uri, ex);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @author Patrick Wright
*/
public abstract class AbstractResource implements Resource {
private static enum StreamType { READER, STREAM, INPUT_SOURCE; }
private enum StreamType { READER, STREAM, INPUT_SOURCE; }
private final StreamType streamType;

private InputSource inputSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,6 @@ public static String encode( String s ) {
return sbuf.toString();
}

/**
* Description of the Method
*
* @param chars PARAM
* @return Returns
*/
public static String encode( char[] chars ) {
StringBuilder sbuf = new StringBuilder();
int len = chars.length;
for ( int i = 0; i < len; i++ ) {
int ch = chars[i];
append( sbuf, ch );
}
return sbuf.toString();
}

/**
* Description of the Method
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public abstract class AbstractControl implements FormControl {
private boolean _successful;
private boolean _enabled;

private List _listeners = new ArrayList();
private List<FormControlListener> _listeners = new ArrayList<>();

public AbstractControl(XhtmlForm form, Element e) {
_form = form;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ButtonControl extends AbstractControl {

private String _type, _label;
private boolean _extended;
private List _listeners = new ArrayList();
private List<ButtonControlListener> _listeners = new ArrayList<>();

public ButtonControl(XhtmlForm form, Element e) {
super(form, e);
Expand Down Expand Up @@ -75,8 +75,8 @@ public void removeButtonControlListener(ButtonControlListener listener) {
}

public boolean press() {
for (Iterator iter = _listeners.iterator(); iter.hasNext();) {
if(!((ButtonControlListener) iter.next()).pressed(this))
for (Iterator<ButtonControlListener> iter = _listeners.iterator(); iter.hasNext();) {
if(!(iter.next()).pressed(this))
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public class ArrayUtil {
public static String[] cloneOrEmpty(String[] source){
return source == null ? Constants.EMPTY_STR_ARR : (String[]) source.clone();
}
public static byte[] cloneOrEmpty(byte[] source){
return source == null ? Constants.EMPTY_BYTE_ARR : (byte[]) source.clone();
}

public static int[] cloneOrEmpty(int[] source) {
return source == null ? Constants.EMPTY_INT_ARR : (int[]) source.clone();
Expand Down
Loading

0 comments on commit 684fd40

Please sign in to comment.