|
|
@ -1,40 +1,13 @@ |
|
|
|
<%@page import="java.nio.file.Path"%> |
|
|
|
|
|
|
|
<%@page import="java.nio.file.Paths"%> |
|
|
|
|
|
|
|
<%@page import="java.nio.file.Files"%> |
|
|
|
|
|
|
|
<%@page import="java.io.File"%> |
|
|
|
|
|
|
|
<%@page import="com.liferay.portal.kernel.log.LogFactoryUtil"%> |
|
|
|
|
|
|
|
<%@page import="com.liferay.portal.kernel.log.Log"%> |
|
|
|
|
|
|
|
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> |
|
|
|
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> |
|
|
|
<%@page import="com.liferay.portal.kernel.util.MapUtil"%> |
|
|
|
<%@page import="com.liferay.portal.kernel.util.MapUtil"%> |
|
|
|
<%@page import="java.io.UnsupportedEncodingException"%> |
|
|
|
|
|
|
|
<%@page import="org.apache.commons.codec.binary.Hex"%> |
|
|
|
|
|
|
|
<%@page import="com.liferay.portal.kernel.util.UnicodeFormatter"%> |
|
|
|
|
|
|
|
<%@page import="com.liferay.portlet.dynamicdatamapping.service.DDMStructureLocalServiceUtil"%> |
|
|
|
<%@page import="com.liferay.portlet.dynamicdatamapping.service.DDMStructureLocalServiceUtil"%> |
|
|
|
<%@page import="com.liferay.portal.kernel.util.StringUtil"%> |
|
|
|
|
|
|
|
<%@page import="org.htmlparser.Node"%> |
|
|
|
|
|
|
|
<%@page import="org.htmlparser.tags.OptionTag"%> |
|
|
|
|
|
|
|
<%@page import="org.htmlparser.tags.TextareaTag"%> |
|
|
|
|
|
|
|
<%@page import="org.htmlparser.tags.InputTag"%> |
|
|
|
|
|
|
|
<%@page import="org.htmlparser.tags.SelectTag"%> |
|
|
|
|
|
|
|
<%@page import="org.htmlparser.tags.Div" %> |
|
|
|
|
|
|
|
<%@page import="org.htmlparser.tags.LabelTag" %> |
|
|
|
|
|
|
|
<%@page import="org.htmlparser.nodes.TagNode"%> |
|
|
|
|
|
|
|
<%@page import="org.htmlparser.nodes.TextNode"%> |
|
|
|
|
|
|
|
<%@page import="org.htmlparser.util.NodeList"%> |
|
|
|
|
|
|
|
<%@page import="org.htmlparser.Parser"%> |
|
|
|
|
|
|
|
<%@page import="org.htmlparser.util.ParserException"%> |
|
|
|
|
|
|
|
<%@page import="javax.portlet.RenderResponse"%> |
|
|
|
|
|
|
|
<%@page import="java.util.Iterator"%> |
|
|
|
|
|
|
|
<%@page import="java.util.Map.Entry"%> |
|
|
|
<%@page import="java.util.Map.Entry"%> |
|
|
|
<%@page import="com.liferay.portal.kernel.util.LocaleUtil"%> |
|
|
|
<%@page import="com.liferay.portal.kernel.util.LocaleUtil"%> |
|
|
|
<%@page import="com.liferay.portal.kernel.util.Validator"%> |
|
|
|
<%@page import="com.liferay.portal.kernel.util.Validator"%> |
|
|
|
<%@page import="com.liferay.portal.kernel.util.ParamUtil"%> |
|
|
|
|
|
|
|
<%@page import="java.util.Set"%> |
|
|
|
<%@page import="java.util.Set"%> |
|
|
|
<%@page import="java.util.Locale"%> |
|
|
|
<%@page import="java.util.Locale"%> |
|
|
|
<%@page import="com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil"%> |
|
|
|
<%@page import="com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil"%> |
|
|
|
<%@page import="com.liferay.portlet.dynamicdatamapping.storage.Fields"%> |
|
|
|
<%@page import="com.liferay.portlet.dynamicdatamapping.storage.Fields"%> |
|
|
|
<%@page import="com.liferay.portlet.dynamicdatalists.model.DDLRecordSet"%> |
|
|
|
|
|
|
|
<%@page import="com.liferay.portlet.dynamicdatalists.service.DDLRecordSetServiceUtil"%> |
|
|
|
|
|
|
|
<%@page import="com.liferay.portlet.dynamicdatalists.model.DDLRecordVersion"%> |
|
|
|
<%@page import="com.liferay.portlet.dynamicdatalists.model.DDLRecordVersion"%> |
|
|
|
<%@page import="com.liferay.portal.kernel.bean.BeanParamUtil"%> |
|
|
|
<%@page import="com.liferay.portal.kernel.bean.BeanParamUtil"%> |
|
|
|
<%@page import="com.liferay.portlet.dynamicdatalists.model.DDLRecord"%> |
|
|
|
<%@page import="com.liferay.portlet.dynamicdatalists.model.DDLRecord"%> |
|
|
@ -44,7 +17,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
<%@ include file="/html/portlet/workflow_tasks/init.jsp" %> |
|
|
|
<%@ include file="/html/portlet/workflow_tasks/init.jsp" %> |
|
|
|
|
|
|
|
|
|
|
|
<!-- ADT BUG BO ID=27 --> |
|
|
|
|
|
|
|
<% |
|
|
|
<% |
|
|
|
String classPkForCarichiLavoro = (String) renderRequest.getAttribute("classPkForCarichiLavoro"); |
|
|
|
String classPkForCarichiLavoro = (String) renderRequest.getAttribute("classPkForCarichiLavoro"); |
|
|
|
%> |
|
|
|
%> |
|
|
@ -57,7 +29,6 @@ |
|
|
|
<span>Visualizza Carichi di Lavoro Istruttori</span> |
|
|
|
<span>Visualizza Carichi di Lavoro Istruttori</span> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</c:if> |
|
|
|
</c:if> |
|
|
|
<!-- ************ --> |
|
|
|
|
|
|
|
<% |
|
|
|
<% |
|
|
|
|
|
|
|
|
|
|
|
long ddmTemplateId = (Long) renderRequest.getAttribute("ddmTemplateId"); |
|
|
|
long ddmTemplateId = (Long) renderRequest.getAttribute("ddmTemplateId"); |
|
|
@ -128,7 +99,6 @@ if (ddmTemplateId > 0) { |
|
|
|
classPK = ddmTemplateId; |
|
|
|
classPK = ddmTemplateId; |
|
|
|
} |
|
|
|
} |
|
|
|
%> |
|
|
|
%> |
|
|
|
|
|
|
|
|
|
|
|
<liferay-util:buffer var="html"> |
|
|
|
<liferay-util:buffer var="html"> |
|
|
|
<liferay-ddm:html |
|
|
|
<liferay-ddm:html |
|
|
|
classNameId="<%= classNameId %>" |
|
|
|
classNameId="<%= classNameId %>" |
|
|
@ -138,232 +108,21 @@ if (ddmTemplateId > 0) { |
|
|
|
requestedLocale="<%= LocaleUtil.fromLanguageId(languageId) %>" |
|
|
|
requestedLocale="<%= LocaleUtil.fromLanguageId(languageId) %>" |
|
|
|
/> |
|
|
|
/> |
|
|
|
</liferay-util:buffer> |
|
|
|
</liferay-util:buffer> |
|
|
|
<% salva("inizio.html", html); %> |
|
|
|
<% |
|
|
|
<%= |
|
|
|
for (Entry<String, List<Map<String, Serializable>>> entry : fieldNameOptions.entrySet()) { |
|
|
|
normalize(html, parameters, fieldNameOptions, renderResponse, prefix, suffix) |
|
|
|
String base = "(?s)\\sname=\"" + renderResponse.getNamespace() + entry.getKey() |
|
|
|
Log _log = LogFactoryUtil.getLog("render_form_task_jsp_salva"); |
|
|
|
+ "_INSTANCE_[^\"]*\"(.*?)value=\"Value"; |
|
|
|
for (Map.Entry<String, List<Map<String, Serializable>>> entry : fieldNameOptions.entrySet()) { |
|
|
|
int counter = 1; |
|
|
|
|
|
|
|
for (Map<String, Serializable> option : entry.getValue()) { |
|
|
|
} |
|
|
|
String regex = base + counter + "\"(.*?)Label" + counter; |
|
|
|
/* html.replaceAll( |
|
|
|
String replace = " name=\"" + entry.getKey() + "\"$1value=\"" + option.get("value") + "\""; |
|
|
|
"\\sname=\"" + renderResponse.getNamespace() + "(.*?)_INSTANCE_[^\"]*", |
|
|
|
if (MapUtil.getBoolean(option, "default")) { |
|
|
|
" name=\"" + prefix + "$1" + suffix |
|
|
|
replace += " checked=\"checked\""; |
|
|
|
)*/ |
|
|
|
} |
|
|
|
%> |
|
|
|
replace += "$2" + option.get("label"); |
|
|
|
|
|
|
|
html = html.replaceAll(regex, replace); |
|
|
|
<%! |
|
|
|
counter++; |
|
|
|
private String normalize(String html, Map<String, Serializable> parameters, |
|
|
|
} |
|
|
|
Map<String, List<Map<String, Serializable>>> fieldNameOptions, |
|
|
|
|
|
|
|
RenderResponse renderResponse, String prefix, String suffix) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Validator.isNull(html)) { |
|
|
|
|
|
|
|
return StringPool.BLANK; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// replace portlet namespace + random namespace |
|
|
|
|
|
|
|
html = html.replaceAll("name=\"" + renderResponse.getNamespace(), "name=\""); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parser parser = Parser.createParser(html, StringPool.UTF8); |
|
|
|
|
|
|
|
NodeList nodeList = (NodeList) parser.parse(null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nodeList.size(); i++) { |
|
|
|
|
|
|
|
filter(nodeList.elementAt(i), parameters, fieldNameOptions, prefix, suffix); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
html = nodeList.toHtml(); |
|
|
|
|
|
|
|
} catch (ParserException e) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add prefix + suffix |
|
|
|
|
|
|
|
html = html.replaceAll("name=\"(.*?)\"", "name=\"" + prefix + "$1" + suffix + "\""); |
|
|
|
|
|
|
|
// ignore ddm fields display |
|
|
|
|
|
|
|
html = html.replaceAll("name=\"" + prefix + "_fieldsDisplay" + suffix + "\"", "name=\"_fieldsDisplay\""); |
|
|
|
|
|
|
|
return html; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void salva(String name, String str) { |
|
|
|
|
|
|
|
Log _log = LogFactoryUtil.getLog("render_form_task_jsp_salva"); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
String debugPath = com.liferay.portal.kernel.util.PropsUtil.get("liferay.home") + "/debug"; |
|
|
|
|
|
|
|
_log.info("debugPath = " + debugPath); |
|
|
|
|
|
|
|
File debugFile = new File(debugPath); |
|
|
|
|
|
|
|
if (!debugFile.exists()) |
|
|
|
|
|
|
|
debugFile.mkdirs(); |
|
|
|
|
|
|
|
Path path = Paths.get(debugPath + "/" + name); |
|
|
|
|
|
|
|
Files.write(path, str.getBytes()); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
_log.error("Errore", e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void filter(Node node, Map<String, Serializable> parameters, |
|
|
|
|
|
|
|
Map<String, List<Map<String, Serializable>>> fieldNameOptions, |
|
|
|
|
|
|
|
String prefix, String suffix) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (node != null) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (node instanceof SelectTag || node instanceof InputTag || node instanceof TextareaTag) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TagNode tag = (TagNode) node; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String name = tag.getAttribute("name"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String namespace = getNamespace(node); |
|
|
|
|
|
|
|
if (Validator.isNotNull(namespace)) { |
|
|
|
|
|
|
|
name = name.replaceAll(namespace, StringPool.BLANK); |
|
|
|
|
|
|
|
tag.setAttribute("name", name); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String value = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (parameters.containsKey(name)) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
value = parameters.get(name).toString(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (node instanceof TextareaTag) { |
|
|
|
|
|
|
|
if (node.getChildren() != null && node.getChildren().size() > 0) { |
|
|
|
|
|
|
|
TextNode text = (TextNode) node.getChildren().elementAt(0); |
|
|
|
|
|
|
|
text.setText(value); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
NodeList nodeList = new NodeList(); |
|
|
|
|
|
|
|
nodeList.add(new TextNode(value)); |
|
|
|
|
|
|
|
node.setChildren(nodeList); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (tag instanceof SelectTag) { |
|
|
|
|
|
|
|
if (node.getChildren() != null && node.getChildren().size() > 0) { |
|
|
|
|
|
|
|
for (int i = 0; i < node.getChildren().size(); i++) { |
|
|
|
|
|
|
|
if (node.getChildren().elementAt(i) instanceof OptionTag) { |
|
|
|
|
|
|
|
TagNode optionTag = (TagNode) node.getChildren().elementAt(i); |
|
|
|
|
|
|
|
String optionValue = optionTag.getAttribute("value"); |
|
|
|
|
|
|
|
optionValue = replaceHex(optionValue); |
|
|
|
|
|
|
|
String[] values = StringUtil.split(value, StringPool.COMMA); |
|
|
|
|
|
|
|
for (String v : values) { |
|
|
|
|
|
|
|
if (StringUtil.trim(v).equals(optionValue)) { |
|
|
|
|
|
|
|
optionTag.setAttribute("selected", "selected"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
String type = tag.getAttribute("type"); |
|
|
|
|
|
|
|
if (type.equals("checkbox")) { |
|
|
|
|
|
|
|
value = parameters.get( |
|
|
|
|
|
|
|
StringUtil.replace(name, "Checkbox", StringPool.BLANK)).toString(); |
|
|
|
|
|
|
|
if (value.equalsIgnoreCase("true")) { |
|
|
|
|
|
|
|
tag.setAttribute("checked", "checked"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (type.equals("radio")) { |
|
|
|
|
|
|
|
String valueInput = tag.getAttribute("value"); |
|
|
|
|
|
|
|
valueInput = replaceHex(valueInput); |
|
|
|
|
|
|
|
if (value.equals(valueInput)) { |
|
|
|
|
|
|
|
tag.setAttribute("checked", "checked"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
tag.setAttribute("value", value, '"'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// select singolo o multiplo senza opzioni fisse |
|
|
|
|
|
|
|
if (tag instanceof SelectTag) { |
|
|
|
|
|
|
|
List<Map<String, Serializable>> options = fieldNameOptions.get(name); |
|
|
|
|
|
|
|
if (options != null && !options.isEmpty()) { |
|
|
|
|
|
|
|
NodeList optionsTag = new NodeList(); |
|
|
|
|
|
|
|
for (Map<String, Serializable> option : options) { |
|
|
|
|
|
|
|
String label = MapUtil.getString(option, "label"); |
|
|
|
|
|
|
|
String valueOption = MapUtil.getString(option, "value"); |
|
|
|
|
|
|
|
boolean defaultValue = MapUtil.getBoolean(option, "default"); |
|
|
|
|
|
|
|
// new option |
|
|
|
|
|
|
|
OptionTag optionTag = new OptionTag(); |
|
|
|
|
|
|
|
optionTag.setAttribute("value", valueOption, '"'); |
|
|
|
|
|
|
|
if (defaultValue && !parameters.containsKey(name)) { |
|
|
|
|
|
|
|
optionTag.setAttribute("selected", "selected"); |
|
|
|
|
|
|
|
} else if (Validator.isNotNull(value) && value.equals(valueOption)) { |
|
|
|
|
|
|
|
optionTag.setAttribute("selected", "selected"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
TextNode textNode = new TextNode(label); |
|
|
|
|
|
|
|
NodeList nodeList = new NodeList(); |
|
|
|
|
|
|
|
nodeList.add(textNode); |
|
|
|
|
|
|
|
optionTag.setChildren(nodeList); |
|
|
|
|
|
|
|
optionsTag.add(optionTag); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tag.setChildren(optionsTag); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if ("radio".equals(tag.getAttribute("type"))) { |
|
|
|
|
|
|
|
List<Map<String, Serializable>> options = fieldNameOptions.get(name); |
|
|
|
|
|
|
|
if(options!=null){ |
|
|
|
|
|
|
|
for (Map<String, Serializable> option : options) { |
|
|
|
|
|
|
|
String label = MapUtil.getString(option, "label"); |
|
|
|
|
|
|
|
String valueOption = MapUtil.getString(option, "value"); |
|
|
|
|
|
|
|
boolean defaultValue = MapUtil.getBoolean(option, "default"); |
|
|
|
|
|
|
|
if(tag.getAttribute("value").equals(valueOption)){ |
|
|
|
|
|
|
|
tag.getNextSibling().setText(label); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (node.getChildren() != null) { |
|
|
|
|
|
|
|
for (int i = 0; i < node.getChildren().size(); i++) { |
|
|
|
|
|
|
|
filter(node.getChildren().elementAt(i), parameters, fieldNameOptions, prefix, suffix); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getNamespace(Node node) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String namespace = null; |
|
|
|
|
|
|
|
boolean trovato = false; |
|
|
|
|
|
|
|
Node parent = node.getParent(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (!trovato && parent != null) { |
|
|
|
|
|
|
|
if (parent instanceof TagNode) { |
|
|
|
|
|
|
|
TagNode tag = (TagNode) parent; |
|
|
|
|
|
|
|
String dataFieldNamespace = tag.getAttribute("data-fieldnamespace"); |
|
|
|
|
|
|
|
if (Validator.isNotNull(dataFieldNamespace)) { |
|
|
|
|
|
|
|
trovato = true; |
|
|
|
|
|
|
|
namespace = dataFieldNamespace; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!trovato) { |
|
|
|
|
|
|
|
parent = parent.getParent(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return namespace; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String replaceHex(String s) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final String prefix = "&#x"; |
|
|
|
|
|
|
|
final String suffix = ";"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int index = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (true) { |
|
|
|
|
|
|
|
int i = s.indexOf(prefix, index); |
|
|
|
|
|
|
|
if (i < 0) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
int j = s.indexOf(suffix, i); |
|
|
|
|
|
|
|
if (j < 0) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
String hexCode = s.substring(i, (j + 1)); |
|
|
|
|
|
|
|
String hex = hexCode.substring(prefix.length(), hexCode.length() - 1); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
s = StringUtil.replace(s, hexCode, |
|
|
|
|
|
|
|
new String(Hex.decodeHex(hex.toCharArray()), StringPool.UTF8)); |
|
|
|
|
|
|
|
} catch (Exception e) {} |
|
|
|
|
|
|
|
index = i; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return s; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
%> |
|
|
|
%> |
|
|
|
|
|
|
|
<%= html %> |
|
|
|