Ajustes para homologação

parent ce6d0e34
...@@ -62,21 +62,8 @@ ...@@ -62,21 +62,8 @@
String SGMPConfig = portletInstanceConfig.SGMPConfig(); String SGMPConfig = portletInstanceConfig.SGMPConfig();
String AAOMCConfig = portletInstanceConfig.AAOMCConfig();
String ARCCConfig = portletInstanceConfig.ARCCConfig();
String GAOMCConfig = portletInstanceConfig.GAOMCConfig();
String ARCCRIConfig = portletInstanceConfig.ARCCRIConfig();
String ACConfig = portletInstanceConfig.ACConfig();
String ADHMConfig = portletInstanceConfig.ADHMConfig();
String AAPConfig = portletInstanceConfig.AAPConfig(); String AAPConfig = portletInstanceConfig.AAPConfig();
String AIConfig = portletInstanceConfig.AIConfig();
%> %>
<liferay-portlet:actionURL portletConfiguration="<%= true %>" <liferay-portlet:actionURL portletConfiguration="<%= true %>"
...@@ -127,7 +114,7 @@ ...@@ -127,7 +114,7 @@
value="<%=SGJAConfig%>" /> value="<%=SGJAConfig%>" />
<aui:input name="SGJPIConfig" <aui:input name="SGJPIConfig"
label="SUBPROCURADORIA GERAL DE JUSTIA DE PLANEJAMENTO INSTITUCIONAL: " label="SUBPROCURADORIA GERAL DE JUSTIA DE PLANEJAMENTO E POLTICAS INSTITUCIONAIS: "
style="width:500px; display:block;" type="text" style="width:500px; display:block;" type="text"
value="<%=SGJPIConfig%>" /> value="<%=SGJPIConfig%>" />
...@@ -137,7 +124,7 @@ ...@@ -137,7 +124,7 @@
value="<%=SGJACIConfig%>" /> value="<%=SGJACIConfig%>" />
<aui:input name="SGJACDHConfig" <aui:input name="SGJACDHConfig"
label="SUBPROCURADORIA GERAL DE JUSTIA DE ASSUNTOS CRIMINAIS E DE DIREITOS HUMANOS: " label="SUBPROCURADORIA GERAL DE JUSTIA DE ASSUNTOS CRIMINAIS: "
style="width:500px; display:block;" type="text" style="width:500px; display:block;" type="text"
value="<%=SGJACDHConfig%>" /> value="<%=SGJACDHConfig%>" />
...@@ -187,43 +174,10 @@ ...@@ -187,43 +174,10 @@
style="width:500px; display:block;" type="text" style="width:500px; display:block;" type="text"
value="<%=SGMPConfig%>" /> value="<%=SGMPConfig%>" />
<aui:input name="AAOMCConfig"
label="ASSESSORIA DE ATRIBUIO ORIGINRIA EM MATRIA CVEL: "
style="width:500px; display:block;" type="text"
value="<%=AAOMCConfig%>" />
<aui:input name="ARCCConfig"
label="ASSESSORIA DE RECURSOS CONSTITUCIONAIS CVEIS: "
style="width:500px; display:block;" type="text"
value="<%=ARCCConfig%>" />
<aui:input name="GAOMCConfig"
label="GRUPO DE ATRIBUIO ORIGINRIA EM MATRIA CRIMINAL: "
style="width:500px; display:block;" type="text"
value="<%=GAOMCConfig%>" />
<aui:input name="ARCCRIConfig"
label="ASSESSORIA DE RECURSOS CONSTITUCIONAIS CRIMINAIS: "
style="width:500px; display:block;" type="text"
value="<%=ARCCRIConfig%>" />
<aui:input name="ACConfig" label="ASSESSORIA CRIMINAL: "
style="width:500px; display:block;" type="text"
value="<%=ACConfig%>" />
<aui:input name="ADHMConfig"
label="ASSESSORIA DE DIRETOS HUMANOS E DE MINORIAS: "
style="width:500px; display:block;" type="text"
value="<%=ADHMConfig%>" />
<aui:input name="AAPConfig" <aui:input name="AAPConfig"
label="ASSESSORIA DE ASSUNTOS PARLAMENTARES: " label="ASSESSORIA DE ASSUNTOS PARLAMENTARES: "
style="width:500px; display:block;" type="text" style="width:500px; display:block;" type="text"
value="<%=AAPConfig%>" /> value="<%=AAPConfig%>" />
<aui:input name="AIConfig" label="ASSESSORIA INTERNACIONAL: "
style="width:500px; display:block;" type="text"
value="<%=AIConfig%>" />
</aui:fieldset> </aui:fieldset>
......
...@@ -68,26 +68,5 @@ public interface DoerjCadernoPortletConfiguration { ...@@ -68,26 +68,5 @@ public interface DoerjCadernoPortletConfiguration {
public String SGMPConfig(); public String SGMPConfig();
@Meta.AD(required = false) @Meta.AD(required = false)
public String AAOMCConfig();
@Meta.AD(required = false)
public String ARCCConfig();
@Meta.AD(required = false)
public String GAOMCConfig();
@Meta.AD(required = false)
public String ARCCRIConfig();
@Meta.AD(required = false)
public String ACConfig();
@Meta.AD(required = false)
public String ADHMConfig();
@Meta.AD(required = false)
public String AAPConfig(); public String AAPConfig();
@Meta.AD(required = false)
public String AIConfig();
} }
...@@ -80,14 +80,7 @@ public class DoerjCadernoPortletConfigurationAction extends DefaultConfiguration ...@@ -80,14 +80,7 @@ public class DoerjCadernoPortletConfigurationAction extends DefaultConfiguration
setPreference(actionRequest, "CEAFConfig", ParamUtil.getString(actionRequest, "CEAFConfig")); setPreference(actionRequest, "CEAFConfig", ParamUtil.getString(actionRequest, "CEAFConfig"));
setPreference(actionRequest, "OUVIConfig", ParamUtil.getString(actionRequest, "OUVIConfig")); setPreference(actionRequest, "OUVIConfig", ParamUtil.getString(actionRequest, "OUVIConfig"));
setPreference(actionRequest, "SGMPConfig", ParamUtil.getString(actionRequest, "SGMPConfig")); setPreference(actionRequest, "SGMPConfig", ParamUtil.getString(actionRequest, "SGMPConfig"));
setPreference(actionRequest, "AAOMCConfig", ParamUtil.getString(actionRequest, "AAOMCConfig"));
setPreference(actionRequest, "ARCCConfig", ParamUtil.getString(actionRequest, "ARCCConfig"));
setPreference(actionRequest, "GAOMCConfig", ParamUtil.getString(actionRequest, "GAOMCConfig"));
setPreference(actionRequest, "ARCCRIConfig", ParamUtil.getString(actionRequest, "ARCCRIConfig"));
setPreference(actionRequest, "ACConfig", ParamUtil.getString(actionRequest, "ACConfig"));
setPreference(actionRequest, "ADHMConfig", ParamUtil.getString(actionRequest, "ADHMConfig"));
setPreference(actionRequest, "AAPConfig", ParamUtil.getString(actionRequest, "AAPConfig")); setPreference(actionRequest, "AAPConfig", ParamUtil.getString(actionRequest, "AAPConfig"));
setPreference(actionRequest, "AIConfig", ParamUtil.getString(actionRequest, "AIConfig"));
SessionMessages.add(actionRequest, "servico.sucesso.gravar.config"); SessionMessages.add(actionRequest, "servico.sucesso.gravar.config");
......
...@@ -18,7 +18,6 @@ import javax.xml.bind.JAXBElement; ...@@ -18,7 +18,6 @@ import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateFormatUtils;
import org.docx4j.XmlUtils;
import org.docx4j.convert.in.xhtml.XHTMLImporterImpl; import org.docx4j.convert.in.xhtml.XHTMLImporterImpl;
import org.docx4j.openpackaging.exceptions.Docx4JException; import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.exceptions.InvalidFormatException; import org.docx4j.openpackaging.exceptions.InvalidFormatException;
...@@ -26,18 +25,19 @@ import org.docx4j.openpackaging.packages.WordprocessingMLPackage; ...@@ -26,18 +25,19 @@ import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.DocumentPart; import org.docx4j.openpackaging.parts.WordprocessingML.DocumentPart;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart; import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart; import org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart;
import org.docx4j.wml.BooleanDefaultTrue;
import org.docx4j.wml.ContentAccessor; import org.docx4j.wml.ContentAccessor;
import org.docx4j.wml.Lvl;
import org.docx4j.wml.NumFmt;
import org.docx4j.wml.P; import org.docx4j.wml.P;
import org.docx4j.wml.PPr; import org.docx4j.wml.PPr;
import org.docx4j.wml.PPrBase; import org.docx4j.wml.PPrBase;
import org.docx4j.wml.PPrBase.NumPr; import org.docx4j.wml.PPrBase.NumPr;
import org.docx4j.wml.PPrBase.NumPr.Ilvl; import org.docx4j.wml.PPrBase.NumPr.Ilvl;
import org.docx4j.wml.PPrBase.NumPr.NumId; import org.docx4j.wml.PPrBase.NumPr.NumId;
import org.docx4j.wml.R;
import org.docx4j.wml.RPr;
import org.docx4j.wml.Text;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.docx4j.wml.R;
import mprj.doerj.caderno.application.model.Lista; import mprj.doerj.caderno.application.model.Lista;
...@@ -65,8 +65,6 @@ public class CadernoUtil { ...@@ -65,8 +65,6 @@ public class CadernoUtil {
if(tipo.equals("conteudo")||tipo.equals("conteudoPrimeiraPagina")){ if(tipo.equals("conteudo")||tipo.equals("conteudoPrimeiraPagina")){
textoHtml = tratarTagsHtml(textoHtml,"p","manterTags"); textoHtml = tratarTagsHtml(textoHtml,"p","manterTags");
textoHtml = tratarTagsHtml(textoHtml,"o:p","manterTags"); textoHtml = tratarTagsHtml(textoHtml,"o:p","manterTags");
textoHtml = tratarTagsHtml(textoHtml,"b","manterTags"); textoHtml = tratarTagsHtml(textoHtml,"b","manterTags");
...@@ -87,12 +85,23 @@ public class CadernoUtil { ...@@ -87,12 +85,23 @@ public class CadernoUtil {
textoHtml = textoHtml.replaceAll("&ndash;", "-"); textoHtml = textoHtml.replaceAll("&ndash;", "-");
textoHtml = textoHtml.replaceAll("&nbsp;", " "); textoHtml = textoHtml.replaceAll("&nbsp;", " ");
textoHtml = textoHtml.replaceAll("&quot;", "'"); textoHtml = textoHtml.replaceAll("&quot;", "'");
textoHtml = textoHtml.replaceAll("<h1>", "<p>");
textoHtml = textoHtml.replaceAll("</h1>", "</p>");
textoHtml = textoHtml.replaceAll("<h2>", "<p>"); textoHtml = textoHtml.replaceAll("<h2>", "<p>");
textoHtml = textoHtml.replaceAll("</h2>", "</p>"); textoHtml = textoHtml.replaceAll("</h2>", "</p>");
textoHtml = textoHtml.replaceAll("<h3>", "<p>");
textoHtml = textoHtml.replaceAll("</h3>", "</p>");
textoHtml = textoHtml.replaceAll("<h4>", "<p>");
textoHtml = textoHtml.replaceAll("</h4>", "</p>");
textoHtml = textoHtml.replaceAll("<h5>", "<p>"); textoHtml = textoHtml.replaceAll("<h5>", "<p>");
textoHtml = textoHtml.replaceAll("</h5>", "</p>"); textoHtml = textoHtml.replaceAll("</h5>", "</p>");
textoHtml = textoHtml.replaceAll("<h1>", "<p>"); textoHtml = textoHtml.replaceAll("<h6>", "<p>");
textoHtml = textoHtml.replaceAll("</h1>", "</p>"); textoHtml = textoHtml.replaceAll("</h6>", "</p>");
textoHtml = textoHtml.replaceAll("<div>", "");
textoHtml = textoHtml.replaceAll("</div>", "");
textoHtml = textoHtml.replaceAll("\n", "");
textoHtml = textoHtml.replaceAll("\r", "");
textoHtml = textoHtml.replaceAll("o:p", "p"); textoHtml = textoHtml.replaceAll("o:p", "p");
textoHtml = textoHtml.replace("&nspace;"," "); textoHtml = textoHtml.replace("&nspace;"," ");
...@@ -111,22 +120,19 @@ public class CadernoUtil { ...@@ -111,22 +120,19 @@ public class CadernoUtil {
textoHtml = textoHtml.replace("&ndash13;","'"); textoHtml = textoHtml.replace("&ndash13;","'");
textoHtml = textoHtml.replace("&ndash14;","'"); textoHtml = textoHtml.replace("&ndash14;","'");
//"<p>&nbsp;</p>"
String primeirosChar=""; String primeirosChar="";
primeirosChar = textoHtml.substring(1, 3); primeirosChar = textoHtml.substring(0, 3);
/*if (!primeirosChar.equals("<p>")&& !tipo.equals("conteudoPrimeiraPagina")){ if (!primeirosChar.equals("<p>")&& !tipo.equals("conteudoPrimeiraPagina")){
//textoHtml = "<p align='JUSTIFY'>" + textoHtml + "</p>"; //textoHtml = "<p align='JUSTIFY'>" + textoHtml + "</p>";
textoHtml = "<p>" + textoHtml + "</p>"; textoHtml = "<p>" + textoHtml + "</p>";
}*/ }
if(tipo.equals("conteudo")){ if(tipo.equals("conteudo")){
//textoHtml = "<body><head><style type='" + "text/css'" + ">p{font-family:Spranq eco sans;font-size:12px;} </style></head>" + textoHtml + "<p></p></body>"; textoHtml = "<body><head><style type='" + "text/css'" + ">p{font-family:Spranq eco sans;font-size:12px;text-align:justify;margin-left:-8px;margin-top:0px;margin-bottom:0px;} ul {list-style-type: circle;} </style></head>" + textoHtml + "</body>";
textoHtml = "<body><head><style type='" + "text/css'" + ">p{font-family:Spranq eco sans;font-size:12px;margin-left:-4px;text-align:justify;margin-top:0px;margin-bottom:0px;} ul {list-style-type: circle;} </style></head>" + textoHtml + "</body>";
//textoHtml = "<body><head></head>" + textoHtml + "</body>";
} }
} }
...@@ -255,7 +261,7 @@ public class CadernoUtil { ...@@ -255,7 +261,7 @@ public class CadernoUtil {
if (tag.equals("o:p")){ if (tag.equals("o:p")){
tagAberta="<o:p "; tagAberta="<o:p>";
tagFechada="<o:p>"; tagFechada="<o:p>";
tamanhoTag=5; tamanhoTag=5;
...@@ -360,18 +366,13 @@ public class CadernoUtil { ...@@ -360,18 +366,13 @@ public class CadernoUtil {
public WordprocessingMLPackage ConverterHTML(String stringFromFile,String orgao,String titulo, String idMateria,String delimitador,ActionRequest actionRequest) throws Docx4JException{ public WordprocessingMLPackage ConverterHTML(String stringFromFile,String orgao,String titulo, String idMateria,String delimitador,ActionRequest actionRequest) throws Docx4JException{
PortletContext context = actionRequest.getPortletSession().getPortletContext(); PortletContext context = actionRequest.getPortletSession().getPortletContext();
//String baseURL = "file:///" + context.getRealPath("/template");
String baseURL = "file:///" + getClass().getResourceAsStream("/META-INF/resources/template"); String baseURL = "file:///" + getClass().getResourceAsStream("/META-INF/resources/template");
//XRLog.setLoggingEnabled(false); String unescaped = stringFromFile;
String unescaped = stringFromFile;
InputStream templateEstilos = getClass().getResourceAsStream("/META-INF/resources/template/TemplateEstilos.docx"); InputStream templateEstilos = getClass().getResourceAsStream("/META-INF/resources/template/TemplateEstilos.docx");
WordprocessingMLPackage templatePackageEstilos = WordprocessingMLPackage.load(templateEstilos); WordprocessingMLPackage templatePackageEstilos = WordprocessingMLPackage.load(templateEstilos);
// Create an empty docx package // Create an empty docx package
// System.out.println(XmlUtils.marshaltoString(templatePackageEstilos.getMainDocumentPart().getJaxbElement(), true, true));
//WordprocessingMLPackage wordMLPackage=null;
WordprocessingMLPackage wordMLPackage = templatePackageEstilos; WordprocessingMLPackage wordMLPackage = templatePackageEstilos;
try { try {
//wordMLPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart DocumentPart = wordMLPackage.getMainDocumentPart(); MainDocumentPart DocumentPart = wordMLPackage.getMainDocumentPart();
String marcadorMateriaInicio = "##MATERIA##INICIO##ID: " + idMateria; String marcadorMateriaInicio = "##MATERIA##INICIO##ID: " + idMateria;
...@@ -382,7 +383,6 @@ public class CadernoUtil { ...@@ -382,7 +383,6 @@ public class CadernoUtil {
} }
if(!orgao.equals(ORGAO)){ if(!orgao.equals(ORGAO)){
//TituloDoeMPRJ
DocumentPart.addStyledParagraphOfText("TituloDoeMPRJ",orgao); DocumentPart.addStyledParagraphOfText("TituloDoeMPRJ",orgao);
ORGAO=orgao; ORGAO=orgao;
...@@ -395,23 +395,12 @@ public class CadernoUtil { ...@@ -395,23 +395,12 @@ public class CadernoUtil {
DocumentPart.addStyledParagraphOfText("SubtituloDOe-MPRJ",titulo); DocumentPart.addStyledParagraphOfText("SubtituloDOe-MPRJ",titulo);
TITULO=titulo; TITULO=titulo;
} }
/*NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
ndp.unmarshalDefaultNumbering();
ndp.restart(1, 0, 1);
ndp.restart(numId, ilvl, val)*/
// Convert the XHTML, and add it into the empty docx we made // Convert the XHTML, and add it into the empty docx we made
XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackage); XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
XHTMLImporter.setHyperlinkStyle("Hyperlink"); XHTMLImporter.setHyperlinkStyle("Hyperlink");
//XHTMLImporter.setRunFormatting(FormattingOption.CLASS_PLUS_OTHER );
// XHTMLImporter.setParagraphFormatting(FormattingOption.CLASS_PLUS_OTHER);
//XHTMLImporter.setParagraphFormatting(FormattingOption.CLASS_TO_STYLE_ONLY);
//XHTMLImporter.setTableFormatting(FormattingOption.IGNORE_CLASS);
wordMLPackage.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert(unescaped, baseURL) ); wordMLPackage.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert(unescaped, baseURL) );
if(delimitador.equals("on")) { if(delimitador.equals("on")) {
...@@ -422,6 +411,8 @@ public class CadernoUtil { ...@@ -422,6 +411,8 @@ public class CadernoUtil {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
wordMLPackage = removerParagrafosVazios(wordMLPackage);
return wordMLPackage; return wordMLPackage;
} }
...@@ -587,23 +578,13 @@ public static WordprocessingMLPackage formatarListas(WordprocessingMLPackage wor ...@@ -587,23 +578,13 @@ public static WordprocessingMLPackage formatarListas(WordprocessingMLPackage wor
P parent = (P) objetoParent; P parent = (P) objetoParent;
PPr ppr = parent.getPPr(); PPr ppr = parent.getPPr();
/*org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();
Lvl lvl = wmlObjectFactory.createLvl();
NumFmt numfmt = wmlObjectFactory.createNumFmt();
lvl.setNumFmt(numfmt);
numfmt.setVal(org.docx4j.wml.NumberFormat.BULLET);
lvl.setPPr(ppr);*/
NumPr numPr = ppr.getNumPr(); NumPr numPr = ppr.getNumPr();
if(numPr!=null) { if(numPr!=null) {
eLista=true; eLista=true;
//if(itemAnterior==false) {
indiceLista++; indiceLista++;
//}
formatar=false; formatar=false;
Long ilvlValor=0L; Long ilvlValor=0L;
...@@ -617,7 +598,6 @@ public static WordprocessingMLPackage formatarListas(WordprocessingMLPackage wor ...@@ -617,7 +598,6 @@ public static WordprocessingMLPackage formatarListas(WordprocessingMLPackage wor
if(formatar==true) { if(formatar==true) {
Ilvl ilvl = numPr.getIlvl(); Ilvl ilvl = numPr.getIlvl();
//ilvl.setVal(BigInteger.ZERO);
ilvl.setVal(BigInteger.valueOf(ilvlValor)); ilvl.setVal(BigInteger.valueOf(ilvlValor));
numPr.setIlvl(ilvl); numPr.setIlvl(ilvl);
...@@ -627,9 +607,6 @@ public static WordprocessingMLPackage formatarListas(WordprocessingMLPackage wor ...@@ -627,9 +607,6 @@ public static WordprocessingMLPackage formatarListas(WordprocessingMLPackage wor
NumId numId = numPr.getNumId(); NumId numId = numPr.getNumId();
numId.setVal(BigInteger.ZERO); numId.setVal(BigInteger.ZERO);
numPr.setNumId(numId); numPr.setNumId(numId);
}else { }else {
org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory(); org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();
...@@ -823,9 +800,7 @@ public static String tratarLista(String conteudoHtml){ ...@@ -823,9 +800,7 @@ public static String tratarLista(String conteudoHtml){
conteudoHtml = conteudoHtml.substring(0,i ) + marcador + conteudoHtml.substring(i + tamanhoTag,conteudoHtml.length()); conteudoHtml = conteudoHtml.substring(0,i ) + marcador + conteudoHtml.substring(i + tamanhoTag,conteudoHtml.length());
len = conteudoHtml.length(); len = conteudoHtml.length();
} }
//posicaoItemOl=QTD_LISTAS;
//conteudoHtml = conteudoHtml.replace(tagP, tagP+marcador);
len = conteudoHtml.length(); len = conteudoHtml.length();
} }
...@@ -882,4 +857,73 @@ public String trataNome(JSONArray listaConteudos,String titulo) { ...@@ -882,4 +857,73 @@ public String trataNome(JSONArray listaConteudos,String titulo) {
} }
public WordprocessingMLPackage removerParagrafosVazios(WordprocessingMLPackage wordPackage) {
DocumentPart parte = wordPackage.getMainDocumentPart();
List<Object> paragraphs = getAllElementFromObject(parte, P.class);
for (Object par : paragraphs) {
P p = (P) par;
List<Object> listaP = p.getContent();
if (listaP.size() == 0) {
wordPackage.getMainDocumentPart().getContent().remove(p);
}
}
return wordPackage;
}
public WordprocessingMLPackage tratarExpedienteVago(WordprocessingMLPackage wordPackage) {
DocumentPart parte = wordPackage.getMainDocumentPart();
List<Object> paragraphs = getAllElementFromObject(parte, P.class);
for (Object par : paragraphs) {
P p = (P) par;
List<Object> listaP = p.getContent();
if (listaP.size() > 0) {
for (Object obj : listaP) {
R r = (R)obj;
List<Object> listaR = r.getContent();
if (listaR.size() > 0) {
for (Object objR : listaR) {
JAXBElement jaxb = (JAXBElement)objR;
Object textoValue = jaxb.getValue();
Text texto = (Text)textoValue;
String textoStr=texto.getValue().toString();
if (textoStr.equals("(Vago)") || textoStr.equals("Vago")) {
Object objR2 = texto.getParent();
R r2 = (R)objR2;
RPr rpr=null;
if(r2.getRPr()==null) {
rpr = new RPr();
}else {
rpr = r2.getRPr();
}
BooleanDefaultTrue italico = new BooleanDefaultTrue();
italico.setVal(true);
rpr.setI(italico);
r2.setRPr(rpr);
}
}
}
}
}
}
return wordPackage;
}
} }
...@@ -39,268 +39,279 @@ import org.json.JSONObject; ...@@ -39,268 +39,279 @@ import org.json.JSONObject;
import mprj.doerj.caderno.application.model.Lista; import mprj.doerj.caderno.application.model.Lista;
public class GeraCaderno { public class GeraCaderno {
public void processaCaderno(ActionRequest actionRequest, ActionResponse actionResponse, JSONArray listaConteudos,
public void processaCaderno(ActionRequest actionRequest,ActionResponse actionResponse,JSONArray listaConteudos,String dataDivulgacao,String delimitador) throws Docx4JException, JAXBException, IOException, ParseException, PortalException{ String dataDivulgacao, String delimitador)
throws Docx4JException, JAXBException, IOException, ParseException, PortalException {
PortletContext context = actionRequest.getPortletSession().getPortletContext(); PortletContext context = actionRequest.getPortletSession().getPortletContext();
//String pathTemplate = context.getRealPath(""); InputStream templateCaderno = getClass()
.getResourceAsStream("/META-INF/resources/template/TemplateCaderno.docx");
//InputStream templateCaderno = GeraCaderno.class.getClass().getResourceAsStream("/META-INF/resources/template/TemplateCaderno.docx");
InputStream templateCaderno = getClass().getResourceAsStream("/META-INF/resources/template/TemplateCaderno.docx");
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
//String templateCaderno = PortalUtil.getPortalURL(themeDisplay) + "/o/mprj.doerj.caderno/template/TemplateCaderno.docx";
String conteudo = "";
String conteudo=""; String orgao = "";
String orgao=""; String titulo = "";
String titulo=""; String idMateria = "";
String idMateria=""; Boolean expedienteVago = false;
PortletPreferences prefs = actionRequest.getPreferences(); PortletPreferences prefs = actionRequest.getPreferences();
CadernoUtil util = new CadernoUtil(); CadernoUtil util = new CadernoUtil();
MainDocumentPart currentDocumentPart = null; MainDocumentPart currentDocumentPart = null;
System.out.println("Iniciando teste do JAXBContext..."); System.out.println("Iniciando teste do JAXBContext...");
JAXBContext.newInstance("org.docx4j.openpackaging.contenttype"); JAXBContext.newInstance("org.docx4j.openpackaging.contenttype");
System.out.println("Finalizado teste do JAXBContext."); System.out.println("Finalizado teste do JAXBContext.");
//WordprocessingMLPackage templatePackage = WordprocessingMLPackage.load(new File(templateCaderno.toString())); WordprocessingMLPackage templatePackage = WordprocessingMLPackage.load(templateCaderno);
//WordprocessingMLPackage templatePackage = WordprocessingMLPackage.load(new File(templateCaderno));
WordprocessingMLPackage templatePackage = WordprocessingMLPackage.load(templateCaderno); // System.out.println(XmlUtils.marshaltoString(templatePackage.getMainDocumentPart().getJaxbElement(),
// true, true));
//System.out.println(XmlUtils.marshaltoString(templatePackage.getMainDocumentPart().getJaxbElement(), true, true)); WordprocessingMLPackage acumuladoPackage = WordprocessingMLPackage.createPackage();
WordprocessingMLPackage acumuladoPackage = WordprocessingMLPackage.createPackage();
//Preenche os dados do cabealho //Preenche os dados do cabealho
MainDocumentPart headerDocumentPart = templatePackage.getMainDocumentPart(); MainDocumentPart headerDocumentPart = templatePackage.getMainDocumentPart();
MainDocumentPart mainPart = templatePackage.getMainDocumentPart();
MainDocumentPart mainPart = templatePackage.getMainDocumentPart(); HeaderPart headerPart = templatePackage.getHeaderFooterPolicy().getDefaultHeader();
HeaderPart headerPart = templatePackage.getHeaderFooterPolicy().getDefaultHeader(); HeaderPart firstPageHeaderPart = templatePackage.getHeaderFooterPolicy().getFirstHeader();
HeaderPart firstPageHeaderPart = templatePackage.getHeaderFooterPolicy().getFirstHeader();
JSONObject cabecalho = new JSONObject(listaConteudos.getJSONObject(0).toString());
// VariablePrepare.prepare(templatePackage);
String edicao = "--";
JSONObject cabecalho = new JSONObject(listaConteudos.getJSONObject(0).toString()); String disponibilizacao = util.gerarDataCabecalho(dataDivulgacao);
String publicacao = "--";
String edicao = "--";
String disponibilizacao = util.gerarDataCabecalho(dataDivulgacao);
String publicacao = "--";
//Cria o hash map com as variveis para substuio dos dados dos cabealhos e expediente //Cria o hash map com as variveis para substuio dos dados dos cabealhos e expediente
HashMap<String, String> variables = new HashMap<String, String>(); HashMap<String, String> variables = new HashMap<String, String>();
variables.put("edi", edicao); variables.put("edi", edicao);
variables.put("dis", disponibilizacao); variables.put("dis", disponibilizacao);
variables.put("pub", publicacao); variables.put("pub", publicacao);
String PGJ = prefs.getValue("PGJConfig", ""); String PGJ = prefs.getValue("PGJConfig", "");
variables.put("PGJ", PGJ); variables.put("PGJ", PGJ);
if (PGJ.equals("(Vago)") || PGJ.equals("Vago")) {
String CGMP = prefs.getValue("CGMPConfig", ""); expedienteVago = true;
variables.put("CGMP", CGMP); }
String SGJA = prefs.getValue("SGJAConfig", ""); String CGMP = prefs.getValue("CGMPConfig", "");
variables.put("SGJA", SGJA); variables.put("CGMP", CGMP);
String SGJPI = prefs.getValue("SGJPIConfig", ""); if (CGMP.equals("(Vago)") || CGMP.equals("Vago")) {
variables.put("SGJPI", SGJPI); expedienteVago = true;
}
String SGJACI = prefs.getValue("SGJACIConfig", "");
variables.put("SGJACI", SGJACI); String SGJA = prefs.getValue("SGJAConfig", "");
variables.put("SGJA", SGJA);
String SGJACDH = prefs.getValue("SGJACDHConfig", "");
variables.put("SGJACDH", SGJACDH); if (SGJA.equals("(Vago)") || SGJA.equals("Vago")) {
expedienteVago = true;
String SGJRIDP = prefs.getValue("SGJRIDPConfig", ""); }
variables.put("SGJRIDP", SGJRIDP);
String SGJPI = prefs.getValue("SGJPIConfig", "");
String CG = prefs.getValue("CGConfig", ""); variables.put("SGJPI", SGJPI);
variables.put("CG", CG);
if (SGJPI.equals("(Vago)") || SGJPI.equals("Vago")) {
String CJ = prefs.getValue("CJConfig", ""); expedienteVago = true;
variables.put("CJ", CJ); }
String AE = prefs.getValue("AEConfig", ""); String SGJACI = prefs.getValue("SGJACIConfig", "");
variables.put("AE", AE); variables.put("SGJACI", SGJACI);
String CMPROCJ = prefs.getValue("CMPROCJConfig", ""); if (SGJACI.equals("(Vago)") || SGJACI.equals("Vago")) {
variables.put("CMPROCJ", CMPROCJ); expedienteVago = true;
}
String CMPROMJ = prefs.getValue("CMPROMJConfig", "");
variables.put("CMPROMJ", CMPROMJ); String SGJACDH = prefs.getValue("SGJACDHConfig", "");
variables.put("SGJACDH", SGJACDH);
String CSI = prefs.getValue("CSIConfig", "");
variables.put("CSI", CSI); if (SGJACDH.equals("(Vago)") || SGJACDH.equals("Vago")) {
expedienteVago = true;
String CEAF = prefs.getValue("CEAFConfig", ""); }
variables.put("CEAF", CEAF);
String SGJRIDP = prefs.getValue("SGJRIDPConfig", "");
String OUVI = prefs.getValue("OUVIConfig", ""); variables.put("SGJRIDP", SGJRIDP);
variables.put("OUVI", OUVI);
if (SGJRIDP.equals("(Vago)") || SGJRIDP.equals("Vago")) {
String SGMP = prefs.getValue("SGMPConfig", ""); expedienteVago = true;
variables.put("SGMP", SGMP); }
String AAOMC = prefs.getValue("AAOMCConfig", ""); String CG = prefs.getValue("CGConfig", "");
variables.put("AAOMC", AAOMC); variables.put("CG", CG);
String ARCC = prefs.getValue("ARCCConfig", ""); if (CG.equals("(Vago)") || CG.equals("Vago")) {
variables.put("ARCC", ARCC); expedienteVago = true;
}
String GAOMC = prefs.getValue("GAOMCConfig", "");
variables.put("GAOMC", GAOMC); String CJ = prefs.getValue("CJConfig", "");
variables.put("CJ", CJ);
String ARCCRI = prefs.getValue("ARCCRIConfig", "");
variables.put("ARCCRI", ARCCRI); if (CJ.equals("(Vago)") || CJ.equals("Vago")) {
expedienteVago = true;
String AC = prefs.getValue("ACConfig", ""); }
variables.put("AC", AC);
String AE = prefs.getValue("AEConfig", "");
String ADHM = prefs.getValue("ADHMConfig", ""); variables.put("AE", AE);
variables.put("ADHM", ADHM);
if (AE.equals("(Vago)") || AE.equals("Vago")) {
String ARIDP = prefs.getValue("ARIDPConfig", ""); expedienteVago = true;
variables.put("ARIDP", ARIDP); }
String AI = prefs.getValue("AIConfig", ""); String CMPROCJ = prefs.getValue("CMPROCJConfig", "");
variables.put("AI", AI); variables.put("CMPROCJ", CMPROCJ);
String AAP = prefs.getValue("AAPConfig", ""); if (CMPROCJ.equals("(Vago)") || CMPROCJ.equals("Vago")) {
variables.put("AAP", AAP); expedienteVago = true;
}
firstPageHeaderPart.variableReplace(variables); String CMPROMJ = prefs.getValue("CMPROMJConfig", "");
headerPart.variableReplace(variables); variables.put("CMPROMJ", CMPROMJ);
mainPart.variableReplace(variables);
if (CMPROMJ.equals("(Vago)") || CMPROMJ.equals("Vago")) {
expedienteVago = true;
// Estilos estilo = new Estilos(); }
//estilo.alterStyleSheet(acumuladoPackage);
WordprocessingMLPackage firstPagePackage = WordprocessingMLPackage.createPackage(); String CSI = prefs.getValue("CSIConfig", "");
variables.put("CSI", CSI);
boolean firstPage=true;
List<Lista> listaOls = new ArrayList<Lista>(); if (CSI.equals("(Vago)") || CSI.equals("Vago")) {
//faz a leitura da listagem de todos os contedos recebidos pelo servio Rest expedienteVago = true;
for(int i=0;i<listaConteudos.length();i++){ }
String CEAF = prefs.getValue("CEAFConfig", "");
variables.put("CEAF", CEAF);
if (CEAF.equals("(Vago)") || CEAF.equals("Vago")) {
expedienteVago = true;
}
String OUVI = prefs.getValue("OUVIConfig", "");
variables.put("OUVI", OUVI);
if (OUVI.equals("(Vago)") || OUVI.equals("Vago")) {
expedienteVago = true;
}
String SGMP = prefs.getValue("SGMPConfig", "");
variables.put("SGMP", SGMP);
if (SGMP.equals("(Vago)") || SGMP.equals("Vago")) {
expedienteVago = true;
}
String ARIDP = prefs.getValue("ARIDPConfig", "");
variables.put("ARIDP", ARIDP);
if (ARIDP.equals("(Vago)") || ARIDP.equals("Vago")) {
expedienteVago = true;
}
String AAP = prefs.getValue("AAPConfig", "");
variables.put("AAP", AAP);
if (AAP.equals("(Vago)") || AAP.equals("Vago")) {
expedienteVago = true;
}
firstPageHeaderPart.variableReplace(variables);
headerPart.variableReplace(variables);
mainPart.variableReplace(variables);
WordprocessingMLPackage firstPagePackage = WordprocessingMLPackage.createPackage();
boolean firstPage = true;
List<Lista> listaOls = new ArrayList<Lista>();
// faz a leitura da listagem de todos os contedos recebidos pelo servio Rest
for (int i = 0; i < listaConteudos.length(); i++) {
WordprocessingMLPackage wordCurrentPackage = WordprocessingMLPackage.createPackage(); WordprocessingMLPackage wordCurrentPackage = WordprocessingMLPackage.createPackage();
JSONObject obj = new JSONObject(listaConteudos.get(i).toString()); JSONObject obj = new JSONObject(listaConteudos.get(i).toString());
orgao = obj.get("ORGAO").toString();
orgao = obj.get("ORGAO").toString(); orgao = util.tratarString(orgao, "titulo");
orgao = util.tratarString(orgao,"titulo");
titulo = util.trataNome(listaConteudos, obj.get("NOME").toString());
titulo = util.tratarString(titulo, "titulo");
titulo = util.trataNome(listaConteudos, obj.get("NOME").toString());
titulo = util.tratarString(titulo,"titulo"); conteudo = obj.get("CONTEUDO").toString();
idMateria = obj.get("IDMATERIA").toString();
conteudo = obj.get("CONTEUDO").toString();
idMateria=obj.get("IDMATERIA").toString(); conteudo = util.tratarString(conteudo, "conteudo");
conteudo = util.tratarLista(conteudo);
conteudo=util.tratarString(conteudo,"conteudo");
conteudo=util.tratarLista(conteudo); wordCurrentPackage = util.ConverterHTML(conteudo, orgao, titulo, idMateria, delimitador, actionRequest);
//listaOls.addAll(util.retornarOls(conteudo));
currentDocumentPart = wordCurrentPackage.getMainDocumentPart();
wordCurrentPackage = util.ConverterHTML(conteudo,orgao,titulo,idMateria,delimitador,actionRequest); acumuladoPackage.getMainDocumentPart().getContent().addAll(currentDocumentPart.getContent());
wordCurrentPackage = null;
currentDocumentPart = wordCurrentPackage.getMainDocumentPart(); currentDocumentPart = null;
acumuladoPackage.getMainDocumentPart().getContent().addAll(currentDocumentPart.getContent());
wordCurrentPackage = null;
currentDocumentPart =null;
} }
MainDocumentPart acumuladoDocumentPart = acumuladoPackage.getMainDocumentPart(); MainDocumentPart acumuladoDocumentPart = acumuladoPackage.getMainDocumentPart();
// estilo.alterStyleSheet(templatePackage); if (expedienteVago == true) {
templatePackage = util.tratarExpedienteVago(templatePackage);
/*XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(templatePackage); }
XHTMLImporter.setParagraphFormatting(FormattingOption.CLASS_PLUS_OTHER);*/
templatePackage.getMainDocumentPart().getContent().addAll(acumuladoDocumentPart.getContent()); templatePackage.getMainDocumentPart().getContent().addAll(acumuladoDocumentPart.getContent());
util.ORGAO=""; util.ORGAO = "";
util.TITULO=""; util.TITULO = "";
//File exportFile = new File("C:/Users/diogo.souza/Documents/Caderno DO/testeDoc4JNovo.docx");
String dataNomeArquivo = dataDivulgacao.replace("/", "-"); String dataNomeArquivo = dataDivulgacao.replace("/", "-");
String nomeArquivo=""; String nomeArquivo = "";
if (delimitador.equals("on")) { if (delimitador.equals("on")) {
nomeArquivo="caderno_doerj_" + dataNomeArquivo + "_materia_delimitada.docx"; nomeArquivo = "caderno_doerj_" + dataNomeArquivo + "_materia_delimitada.docx";
}else { } else {
nomeArquivo="caderno_doerj_" + dataNomeArquivo + ".docx"; nomeArquivo = "caderno_doerj_" + dataNomeArquivo + ".docx";
} }
// InputStream nomeArquivoInputStream = getClass().getResourceAsStream("/META-INF/resources/template/"+nomeArquivo); // cria o arquivo temporrio que ser utilizado na resposta da requisio
// File exportFile = new File(nomeArquivoInputStream.toString());
//cria o arquivo temporrio que ser utilizado na resposta da requisio
File exportFile = File.createTempFile("caderno_doerj_tmp_", ".docx"); File exportFile = File.createTempFile("caderno_doerj_tmp_", ".docx");
try { try {
CadernoUtil caderno = new CadernoUtil(); CadernoUtil caderno = new CadernoUtil();
//templatePackage = caderno.formatarListas(templatePackage,listaOls); // System.out.println(XmlUtils.marshaltoString(templatePackage.getMainDocumentPart().getJaxbElement(),
//acumuladoPackage = caderno.formatarListas(acumuladoPackage,listaOls); // true, true));
//NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
//templatePackage.getMainDocumentPart().addTargetPart(ndp);
//ndp.getInd(String.valueOf(10),String.valueOf(0));
//ndp.unmarshalDefaultNumbering();
//ndp.restart(1, 0, 1);
System.out.println(XmlUtils.marshaltoString(templatePackage.getMainDocumentPart().getJaxbElement(), true, true));
templatePackage.save(exportFile); templatePackage.save(exportFile);
//acumuladoPackage.save(exportFile);
PortletResponse pResponse = PortalUtil.getLiferayPortletResponse(actionResponse); PortletResponse pResponse = PortalUtil.getLiferayPortletResponse(actionResponse);
HttpServletResponse res = PortalUtil.getHttpServletResponse(pResponse);
HttpServletResponse res = PortalUtil.getHttpServletResponse(pResponse); res.setHeader("Content-Disposition", "attachment; filename=" + nomeArquivo);//
res.setHeader("Content-Disposition", "attachment; filename=" + nomeArquivo);// res.setContentType(ContentTypes.APPLICATION_MSWORD);
res.setContentType(ContentTypes.APPLICATION_MSWORD);
try (FileInputStream in = new FileInputStream(exportFile);) {
/*String redirectURL = ParamUtil.getString(actionRequest, "/view-admin.jsp"); OutputStream out = res.getOutputStream();
actionResponse.sendRedirect(redirectURL);*/
byte[] buffer = new byte[4096];
try (FileInputStream in = new FileInputStream(exportFile);) { int numBytesRead;
OutputStream out = res.getOutputStream();
while ((numBytesRead = in.read(buffer)) > 0) {
byte[] buffer = new byte[4096]; out.write(buffer, 0, numBytesRead);
}
int numBytesRead;
out.flush();
while ((numBytesRead = in.read(buffer)) > 0) { res.flushBuffer();
out.write(buffer, 0, numBytesRead); }
}
} catch (Exception e) {
out.flush();
res.flushBuffer();
}
}
catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
exportFile.delete(); exportFile.delete();
CadernoUtil caderno = new CadernoUtil(); CadernoUtil caderno = new CadernoUtil();
caderno.QTD_LISTAS=0L; caderno.QTD_LISTAS = 0L;
} } finally {
finally {
exportFile.delete(); exportFile.delete();
CadernoUtil caderno = new CadernoUtil(); CadernoUtil caderno = new CadernoUtil();
caderno.QTD_LISTAS=0L; caderno.QTD_LISTAS = 0L;
} }
}
}
} }
...@@ -62,21 +62,8 @@ ...@@ -62,21 +62,8 @@
String SGMPConfig = portletInstanceConfig.SGMPConfig(); String SGMPConfig = portletInstanceConfig.SGMPConfig();
String AAOMCConfig = portletInstanceConfig.AAOMCConfig();
String ARCCConfig = portletInstanceConfig.ARCCConfig();
String GAOMCConfig = portletInstanceConfig.GAOMCConfig();
String ARCCRIConfig = portletInstanceConfig.ARCCRIConfig();
String ACConfig = portletInstanceConfig.ACConfig();
String ADHMConfig = portletInstanceConfig.ADHMConfig();
String AAPConfig = portletInstanceConfig.AAPConfig(); String AAPConfig = portletInstanceConfig.AAPConfig();
String AIConfig = portletInstanceConfig.AIConfig();
%> %>
<liferay-portlet:actionURL portletConfiguration="<%= true %>" <liferay-portlet:actionURL portletConfiguration="<%= true %>"
...@@ -127,7 +114,7 @@ ...@@ -127,7 +114,7 @@
value="<%=SGJAConfig%>" /> value="<%=SGJAConfig%>" />
<aui:input name="SGJPIConfig" <aui:input name="SGJPIConfig"
label="SUBPROCURADORIA GERAL DE JUSTIA DE PLANEJAMENTO INSTITUCIONAL: " label="SUBPROCURADORIA GERAL DE JUSTIA DE PLANEJAMENTO E POLTICAS INSTITUCIONAIS: "
style="width:500px; display:block;" type="text" style="width:500px; display:block;" type="text"
value="<%=SGJPIConfig%>" /> value="<%=SGJPIConfig%>" />
...@@ -137,7 +124,7 @@ ...@@ -137,7 +124,7 @@
value="<%=SGJACIConfig%>" /> value="<%=SGJACIConfig%>" />
<aui:input name="SGJACDHConfig" <aui:input name="SGJACDHConfig"
label="SUBPROCURADORIA GERAL DE JUSTIA DE ASSUNTOS CRIMINAIS E DE DIREITOS HUMANOS: " label="SUBPROCURADORIA GERAL DE JUSTIA DE ASSUNTOS CRIMINAIS: "
style="width:500px; display:block;" type="text" style="width:500px; display:block;" type="text"
value="<%=SGJACDHConfig%>" /> value="<%=SGJACDHConfig%>" />
...@@ -187,43 +174,10 @@ ...@@ -187,43 +174,10 @@
style="width:500px; display:block;" type="text" style="width:500px; display:block;" type="text"
value="<%=SGMPConfig%>" /> value="<%=SGMPConfig%>" />
<aui:input name="AAOMCConfig"
label="ASSESSORIA DE ATRIBUIO ORIGINRIA EM MATRIA CVEL: "
style="width:500px; display:block;" type="text"
value="<%=AAOMCConfig%>" />
<aui:input name="ARCCConfig"
label="ASSESSORIA DE RECURSOS CONSTITUCIONAIS CVEIS: "
style="width:500px; display:block;" type="text"
value="<%=ARCCConfig%>" />
<aui:input name="GAOMCConfig"
label="GRUPO DE ATRIBUIO ORIGINRIA EM MATRIA CRIMINAL: "
style="width:500px; display:block;" type="text"
value="<%=GAOMCConfig%>" />
<aui:input name="ARCCRIConfig"
label="ASSESSORIA DE RECURSOS CONSTITUCIONAIS CRIMINAIS: "
style="width:500px; display:block;" type="text"
value="<%=ARCCRIConfig%>" />
<aui:input name="ACConfig" label="ASSESSORIA CRIMINAL: "
style="width:500px; display:block;" type="text"
value="<%=ACConfig%>" />
<aui:input name="ADHMConfig"
label="ASSESSORIA DE DIRETOS HUMANOS E DE MINORIAS: "
style="width:500px; display:block;" type="text"
value="<%=ADHMConfig%>" />
<aui:input name="AAPConfig" <aui:input name="AAPConfig"
label="ASSESSORIA DE ASSUNTOS PARLAMENTARES: " label="ASSESSORIA DE ASSUNTOS PARLAMENTARES: "
style="width:500px; display:block;" type="text" style="width:500px; display:block;" type="text"
value="<%=AAPConfig%>" /> value="<%=AAPConfig%>" />
<aui:input name="AIConfig" label="ASSESSORIA INTERNACIONAL: "
style="width:500px; display:block;" type="text"
value="<%=AIConfig%>" />
</aui:fieldset> </aui:fieldset>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment