Sfoglia il codice sorgente

Fix manipolazione html di kaleo

master
Salvatore La Manna 4 anni fa
parent
commit
aba93f657b
  1. 2
      liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/bo/service/impl/AvvisoServiceImpl.java
  2. 16
      liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/bo/service/impl/ControlloPraticaLocalServiceImpl.java
  3. 4
      liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/service.properties
  4. 273
      liferay-plugins-sdk-6.2/webs/portos-kaleo-web/docroot/META-INF/custom_jsps/html/portlet/workflow_tasks/render_form_task.jsp
  5. BIN
      liferay-plugins-sdk-6.2/webs/portos-kaleo-web/docroot/WEB-INF/lib/htmlparser.jar

2
liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/bo/service/impl/AvvisoServiceImpl.java

@ -13,6 +13,7 @@
package it.tref.liferay.portos.bo.service.impl;
import it.tref.liferay.portos.bo.model.Avviso;
import it.tref.liferay.portos.bo.service.ComuneLocalServiceUtil;
import it.tref.liferay.portos.bo.service.base.AvvisoServiceBaseImpl;
import it.tref.liferay.portos.bo.shared.util.Constants;
@ -48,6 +49,7 @@ public class AvvisoServiceImpl extends AvvisoServiceBaseImpl {
public Avviso rilasciaFirma(long avvisoId, String cf) throws SystemException, PortalException {
Avviso avviso = avvisoPersistence.fetchByPrimaryKey(avvisoId);
if (!avviso.getUserCodiceFiscalePrimaFirma().equalsIgnoreCase(getUser().getScreenName())) {
throw new SystemException("assegnazione non possibile perche' non assengato a " + cf);
}

16
liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/bo/service/impl/ControlloPraticaLocalServiceImpl.java

@ -112,11 +112,6 @@ public class ControlloPraticaLocalServiceImpl extends ControlloPraticaLocalServi
throws PortalException, SystemException {
User user = userPersistence.findByPrimaryKey(userId);
// In creazione del sito viene avviato il workflow sul sito principale
// mentre in update di una
// issue viene avviato
// sul sito specifico per ovviare a bug
// long groupId = serviceContext.getScopeGroupId();
Date now = new Date();
@ -551,17 +546,17 @@ public class ControlloPraticaLocalServiceImpl extends ControlloPraticaLocalServi
jsonArray.put(etichette);
} else if (AzioniPraticheUtil.isAutorizzazione(controlloPratica.getIntPraticaId())) {
JSONObject etichette = JSONFactoryUtil.createJSONObject();
etichette.put("label", "AUTORIZZATA");
etichette.put("label", "Autorizzata");
etichette.put("value", "AU");
etichette.put("default", false);
jsonArray.put(etichette);
etichette = JSONFactoryUtil.createJSONObject();
etichette.put("label", "NON AUTORIZZATA");
etichette.put("label", "Non autorizzata");
etichette.put("value", "AN");
etichette.put("default", false);
jsonArray.put(etichette);
etichette = JSONFactoryUtil.createJSONObject();
etichette.put("label", "RICHIESTA INTEGRAZIONE");
etichette.put("label", "Richiesta integrazione");
etichette.put("value", "IN");
etichette.put("default", false);
jsonArray.put(etichette);
@ -571,12 +566,11 @@ public class ControlloPraticaLocalServiceImpl extends ControlloPraticaLocalServi
etichette.put("default", false);
jsonArray.put(etichette);
etichette = JSONFactoryUtil.createJSONObject();
etichette.put("label", "ANNULLATA");
etichette.put("value", "AL");
etichette.put("label", "Non si rilascia parere");
etichette.put("value", "NP");
etichette.put("default", false);
jsonArray.put(etichette);
}
return jsonObject.toString();
}

4
liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/service.properties

@ -13,8 +13,8 @@
##
build.namespace=portos_bo
build.number=2753
build.date=1606474724182
build.number=2756
build.date=1606726892312
build.auto.upgrade=true
##

273
liferay-plugins-sdk-6.2/webs/portos-kaleo-web/docroot/META-INF/custom_jsps/html/portlet/workflow_tasks/render_form_task.jsp

@ -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 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.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="com.liferay.portal.kernel.util.LocaleUtil"%>
<%@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.Locale"%>
<%@page import="com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil"%>
<%@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.portal.kernel.bean.BeanParamUtil"%>
<%@page import="com.liferay.portlet.dynamicdatalists.model.DDLRecord"%>
@ -44,7 +17,6 @@
<%@ include file="/html/portlet/workflow_tasks/init.jsp" %>
<!-- ADT BUG BO ID=27 -->
<%
String classPkForCarichiLavoro = (String) renderRequest.getAttribute("classPkForCarichiLavoro");
%>
@ -57,7 +29,6 @@
<span>Visualizza Carichi di Lavoro Istruttori</span>
</div>
</c:if>
<!-- ************ -->
<%
long ddmTemplateId = (Long) renderRequest.getAttribute("ddmTemplateId");
@ -128,7 +99,6 @@ if (ddmTemplateId > 0) {
classPK = ddmTemplateId;
}
%>
<liferay-util:buffer var="html">
<liferay-ddm:html
classNameId="<%= classNameId %>"
@ -138,232 +108,21 @@ if (ddmTemplateId > 0) {
requestedLocale="<%= LocaleUtil.fromLanguageId(languageId) %>"
/>
</liferay-util:buffer>
<% salva("inizio.html", html); %>
<%=
normalize(html, parameters, fieldNameOptions, renderResponse, prefix, suffix)
Log _log = LogFactoryUtil.getLog("render_form_task_jsp_salva");
for (Map.Entry<String, List<Map<String, Serializable>>> entry : fieldNameOptions.entrySet()) {
<%
for (Entry<String, List<Map<String, Serializable>>> entry : fieldNameOptions.entrySet()) {
String base = "(?s)\\sname=\"" + renderResponse.getNamespace() + entry.getKey()
+ "_INSTANCE_[^\"]*\"(.*?)value=\"Value";
int counter = 1;
for (Map<String, Serializable> option : entry.getValue()) {
String regex = base + counter + "\"(.*?)Label" + counter;
String replace = " name=\"" + entry.getKey() + "\"$1value=\"" + option.get("value") + "\"";
if (MapUtil.getBoolean(option, "default")) {
replace += " checked=\"checked\"";
}
replace += "$2" + option.get("label");
html = html.replaceAll(regex, replace);
counter++;
}
}
/* html.replaceAll(
"\\sname=\"" + renderResponse.getNamespace() + "(.*?)_INSTANCE_[^\"]*",
" name=\"" + prefix + "$1" + suffix
)*/
%>
<%!
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 %>

BIN
liferay-plugins-sdk-6.2/webs/portos-kaleo-web/docroot/WEB-INF/lib/htmlparser.jar

File binario non mostrato.
Caricamento…
Annulla
Salva