IDEMPIERE-4893 NPE on PDF report of Test record (#1180)
- Fix NPE trying to print any HTML content in PDF as form using internal engine - Fix problem printing HTML content as plain text
This commit is contained in:
parent
26aac62a4a
commit
69d11d0370
|
@ -21,6 +21,7 @@ import java.awt.Rectangle;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTML Form Print ELement.
|
* HTML Form Print ELement.
|
||||||
|
@ -141,13 +142,19 @@ public class HTMLElement extends PrintElement
|
||||||
{
|
{
|
||||||
if (content == null)
|
if (content == null)
|
||||||
return false;
|
return false;
|
||||||
String s = content.toString();
|
// code borrowed from https://denofdevelopers.com/how-to-detect-if-string-is-html-or-not-in-android/
|
||||||
if (s.length() < 20) // assumption
|
final String TAG_START = "<\\w+((\\s+\\w+(\\s*=\\s*(?:\".*?\"|'.*?'|[^'\">\\s]+))?)+\\s*|\\s*)>";
|
||||||
return false;
|
final String TAG_END = "</\\w+>";
|
||||||
s = s.trim().toUpperCase();
|
final String TAG_SELF_CLOSING = "<\\w+((\\s+\\w+(\\s*=\\s*(?:\".*?\"|'.*?'|[^'\">\\s]+))?)+\\s*|\\s*)/>";
|
||||||
if (s.startsWith("<HTML>"))
|
final String HTML_ENTITY = "&[a-zA-Z][a-zA-Z0-9]+;";
|
||||||
return true;
|
final Pattern htmlPattern = Pattern
|
||||||
return false;
|
.compile("(" + TAG_START + ".*" + TAG_END + ")|(" + TAG_SELF_CLOSING + ")|(" + HTML_ENTITY + ")", Pattern.DOTALL);
|
||||||
|
boolean isHTML = false;
|
||||||
|
String htmlString = content.toString();
|
||||||
|
if (htmlString != null) {
|
||||||
|
isHTML = htmlPattern.matcher(htmlString).find();
|
||||||
|
}
|
||||||
|
return isHTML;
|
||||||
} // isHTML
|
} // isHTML
|
||||||
|
|
||||||
} // HTMLElement
|
} // HTMLElement
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.print.layout;
|
package org.compiere.print.layout;
|
||||||
|
|
||||||
|
import java.awt.Container;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.Shape;
|
import java.awt.Shape;
|
||||||
|
@ -98,6 +99,7 @@ public class HTMLRenderer extends View implements Externalizable
|
||||||
m_factory = f;
|
m_factory = f;
|
||||||
m_view = v;
|
m_view = v;
|
||||||
m_view.setParent(this);
|
m_view.setParent(this);
|
||||||
|
m_container = new Container();
|
||||||
m_element = m_view.getElement();
|
m_element = m_view.getElement();
|
||||||
// initially layout to the preferred size
|
// initially layout to the preferred size
|
||||||
setSize(m_view.getPreferredSpan(X_AXIS), m_view.getPreferredSpan(Y_AXIS));
|
setSize(m_view.getPreferredSpan(X_AXIS), m_view.getPreferredSpan(Y_AXIS));
|
||||||
|
@ -106,6 +108,7 @@ public class HTMLRenderer extends View implements Externalizable
|
||||||
private int m_width;
|
private int m_width;
|
||||||
private View m_view;
|
private View m_view;
|
||||||
private ViewFactory m_factory;
|
private ViewFactory m_factory;
|
||||||
|
private Container m_container;
|
||||||
private Element m_element;
|
private Element m_element;
|
||||||
private Rectangle m_allocation;
|
private Rectangle m_allocation;
|
||||||
private float m_viewWidth;
|
private float m_viewWidth;
|
||||||
|
@ -436,4 +439,10 @@ public class HTMLRenderer extends View implements Externalizable
|
||||||
float height = in.readFloat();
|
float height = in.readFloat();
|
||||||
setSize(width, height);
|
setSize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Container getContainer() {
|
||||||
|
return m_container;
|
||||||
|
}
|
||||||
|
|
||||||
} // HTMLRenderer
|
} // HTMLRenderer
|
||||||
|
|
Loading…
Reference in New Issue