📄 wutil.java
字号:
* @return Clear Frame Script
*/
public static script getClearFrame (String target)
{
StringBuffer cmd = new StringBuffer();
cmd.append("var d = parent.").append(target).append(".document;\n");
cmd.append("d.open();\n");
cmd.append("d.write('<link href=\"").append(WEnv.getStylesheetURL()).append("\" rel=\"stylesheet\">');\n");
cmd.append("d.close();");
//
return new script(cmd.toString());
} // getClearFrame
/**
* Return a link and script with new location
* @param url forward url
* @return html
*/
public static HtmlCode getForward (String url)
{
HtmlCode retValue = new HtmlCode();
// Link
a a = new a(url);
a.addElement(url);
retValue.addElement(a);
// Java Script - document.location
script script = new script("window.top.location.replace('" + url + "');");
retValue.addElement(script);
//
return retValue;
} // getForward
/**
* Create Forward Page
* @param response response
* @param title page title
* @param forwardURL url
* @throws ServletException
* @throws IOException
*/
public static void createForwardPage (HttpServletResponse response,
String title, String forwardURL) throws ServletException, IOException
{
response.setContentType("text/html; charset=UTF-8");
WDoc doc = WDoc.create(title);
doc.getBody().addElement(WUtil.getForward(forwardURL));
PrintWriter out = response.getWriter();
doc.output(out);
out.flush();
if (out.checkError())
s_log.error("createForwardPage - error writing");
out.close();
} // createForwardPage
/**
* Does Test exist
* @param test string
* @return true if String with data
*/
public static boolean exists (String test)
{
if (test == null)
return false;
return test.length() > 0;
} // exists
/**
* Does Parameter exist
* @param request request
* @param parameter string
* @return true if String with data
*/
public static boolean exists (HttpServletRequest request, String parameter)
{
if (request == null || parameter == null)
return false;
return exists (request.getParameter(parameter));
} // exists
/**
* Is EMail address valid
* @param email mail address
* @return true if valid
*/
public static boolean isEmailValid (String email)
{
if (email == null || email.length () == 0)
return false;
try
{
InternetAddress ia = new InternetAddress (email, true);
return true;
}
catch (AddressException ex)
{
s_log.warn ("isEmailValid - " + email + " - "
+ ex.getLocalizedMessage ());
}
return false;
} // isEmailValid
/*************************************************************************/
/**
* Decode Properties into String (URL encoded)
*
* @param pp properties
* @return Encoded String
*/
public static String propertiesEncode (Properties pp)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try
{
pp.store(bos, "Compiere"); // Header
}
catch (IOException e)
{
s_log.error("propertiesEncode-store", e);
}
String result = new String (bos.toByteArray());
// System.out.println("String=" + result);
String enc = "UTF-8";
try
{
result = java.net.URLEncoder.encode(result, enc);
}
catch (UnsupportedEncodingException e)
{
s_log.error("propertiesEncode-encode-" + enc, e);
enc = System.getProperty("file.encoding"); // Windows default is Cp1252
try
{
result = java.net.URLEncoder.encode(result, enc);
}
catch (Exception ex)
{
s_log.error("propertiesEncode-encode", ex);
}
}
// System.out.println("String-Encoded=" + result);
return result;
} // propertiesEncode
/**
* Decode data String (URL encoded) into Properties
*
* @param data data
* @return Properties
*/
public static Properties propertiesDecode (String data)
{
String result = null;
// System.out.println("String=" + data);
String enc = "UTF-8";
try
{
result = java.net.URLDecoder.decode(data, enc);
}
catch (UnsupportedEncodingException e)
{
s_log.error("propertiesDecode-decode-" + enc, e);
enc = System.getProperty("file.encoding"); // Windows default is Cp1252
try
{
result = java.net.URLEncoder.encode(data, enc);
}
catch (Exception ex)
{
s_log.error("propertiesDecode-decode", ex);
}
}
// System.out.println("String-Decoded=" + result);
ByteArrayInputStream bis = new ByteArrayInputStream(result.getBytes());
Properties pp = new Properties();
try
{
pp.load(bis);
}
catch (IOException e)
{
s_log.error("propertiesDecode-load", e);
}
return pp;
} // propertiesDecode
/*************************************************************************/
/**
* Convert Array of NamePair to HTTP Option Array.
* <p>
* If the ArrayList does not contain NamePairs, the String value is used
* @see org.compiere.util.NamePair
* @param list ArrayList containing NamePair values
* @param default_ID Sets the default if the key/ID value is found.
* If the value is null or empty, the first value is selected
* @return Option Array
*/
public static option[] convertToOption (NamePair[] list, String default_ID)
{
int size = list.length;
option[] retValue = new option[size];
for (int i = 0; i < size; i++)
{
boolean selected = false;
// select first entry
if (i == 0 && (default_ID == null || default_ID.length() == 0))
selected = true;
// Create option
retValue[i] = new option(list[i].getID()).addElement(list[i].getName());
// Select if ID/Key is same as default ID
if (default_ID != null && default_ID.equals(list[i].getID()))
selected = true;
retValue[i].setSelected(selected);
}
return retValue;
} // convertToOption
/**
* Create label/field table row
*
* @param line - null for new line (table row)
* @param FORMNAME form name
* @param PARAMETER parameter name
* @param labelText label
* @param inputType HTML input type
* @param value data value
* @param sizeDisplay display size
* @param size data size
* @param longField field spanning two columns
* @param mandatory mark as mandatory
* @param onChange onChange call
* @param script script
* @return tr table row
*/
static public tr createField (tr line, String FORMNAME, String PARAMETER,
String labelText, String inputType, Object value,
int sizeDisplay, int size, boolean longField, boolean mandatory, String onChange, StringBuffer script)
{
if (line == null)
line = new tr();
String labelInfo = labelText;
if (mandatory)
{
labelInfo += " <font color=\"red\">*</font>";
String fName = "document." + FORMNAME + "." + PARAMETER;
script.append(fName).append(".required=true; ");
}
label llabel = new label().setFor(PARAMETER).addElement(labelInfo);
llabel.setID("ID_" + PARAMETER + "_Label");
// label.setTitle(description);
line.addElement(new td().addElement(llabel).setAlign(AlignType.right));
input iinput = new input(inputType, PARAMETER, value == null ? "" : value.toString());
iinput.setSize(sizeDisplay).setMaxlength(size);
iinput.setID("ID_" + PARAMETER);
if (onChange != null && onChange.length() > 0)
iinput.setOnChange(onChange);
iinput.setTitle(labelText);
td field = new td().addElement(iinput).setAlign(AlignType.LEFT);
if (longField)
field.setColSpan(3);
line.addElement(field);
return line;
} // addField
} // WUtil
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -