Ajustes na formatação das listas(ol e ul)

parent ef4723f8
eclipse.preferences.version=1
encoding//src/main/java/mprj/doerj/caderno/util/CadernoUtil.java=UTF-8
encoding/build.gradle=UTF-8
......@@ -73,6 +73,8 @@
</div>
<liferay-ui:error key="erroDataNula" message="Uma data deve ser selecionada." />
</div>
<input type="checkbox" name="delimitador" id="delimitador" label="" />
<span style="font-weight: bold;">Inserir delimitador entre as matrias.</span>
<aui:button-row>
<aui:button type="reset" id="limparFormDO" name="limparFormDO" value="Limpar" />
<aui:button type="submit" id="enviarFormDO" name="enviarFormDO" value="Gerar Caderno"/>
......
package mprj.doerj.caderno.application.model;
public class Lista {
private Long posicaoOl;
private Long ilvl;
public Long getPosicaoOl() {
return posicaoOl;
}
public void setPosicaoOl(Long posicaoOl) {
this.posicaoOl = posicaoOl;
}
public Long getIlvl() {
return ilvl;
}
public void setIlvl(Long ilvl) {
this.ilvl = ilvl;
}
}
......@@ -132,6 +132,7 @@ public class MprjDoerjCadernoPortlet extends MVCPortlet {
String dataDivulgacao = ParamUtil.getString(actionRequest, "dataP");
String idStatus = ParamUtil.getString(actionRequest, "situacao");
String delimitador = ParamUtil.getString(actionRequest, "delimitador");
JSONArray listaConteudos = new JSONArray();
RestServices rest = new RestServices();
......@@ -142,7 +143,7 @@ public class MprjDoerjCadernoPortlet extends MVCPortlet {
if(!mensagensDeErro(listaConteudos, dataDivulgacao, actionRequest)){
GeraCaderno caderno = new GeraCaderno();
caderno.processaCaderno(actionRequest, actionResponse,listaConteudos,dataDivulgacao);
caderno.processaCaderno(actionRequest, actionResponse,listaConteudos,dataDivulgacao,delimitador);
//SessionMessages.add(actionRequest, "sucessoMessage");
......
......@@ -2,28 +2,49 @@ package mprj.doerj.caderno.util;
import com.liferay.portal.kernel.exception.SystemException;
import java.io.InputStream;
import java.math.BigInteger;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import javax.portlet.ActionRequest;
import javax.portlet.PortletContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.docx4j.XmlUtils;
import org.docx4j.convert.in.xhtml.XHTMLImporterImpl;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.exceptions.InvalidFormatException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.DocumentPart;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart;
import org.docx4j.org.xhtmlrenderer.util.XRLog;
import org.docx4j.wml.ContentAccessor;
import org.docx4j.wml.Lvl;
import org.docx4j.wml.NumFmt;
import org.docx4j.wml.P;
import org.docx4j.wml.PPr;
import org.docx4j.wml.PPrBase;
import org.docx4j.wml.PPrBase.NumPr;
import org.docx4j.wml.PPrBase.NumPr.Ilvl;
import org.docx4j.wml.PPrBase.NumPr.NumId;
import org.docx4j.wml.R;
import mprj.doerj.caderno.application.model.Lista;
public class CadernoUtil {
public static String ORGAO="";
public static String TITULO="";
public static Long QTD_LISTAS=0L;
public static String getDatasCadastradas() throws SystemException, ParseException{
String datas = " ";
......@@ -50,6 +71,9 @@ public class CadernoUtil {
textoHtml = tratarTagsHtml(textoHtml,"div","manterTags");
textoHtml = tratarTagsHtml(textoHtml,"sup","manterTags");
textoHtml = tratarTagsHtml(textoHtml,"blockquote","manterTags");
textoHtml = tratarTagsHtml(textoHtml,"ol","manterTags");
textoHtml = tratarTagsHtml(textoHtml,"ul","manterTags");
textoHtml = tratarTagsHtml(textoHtml,"li","manterTags");
textoHtml = textoHtml.replaceAll("data:image=&quot;&quot;", "");
......@@ -58,10 +82,30 @@ public class CadernoUtil {
textoHtml = textoHtml.replaceAll("<p>&nbsp;</p>", "");
textoHtml = textoHtml.replaceAll("&nbsp;", " ");
textoHtml = textoHtml.replaceAll("&quot;", "'");
textoHtml = textoHtml.replaceAll("h2", "p");
textoHtml = textoHtml.replaceAll("h5", "p");
textoHtml = textoHtml.replaceAll("h1", "p");
textoHtml = textoHtml.replaceAll("<h2>", "<p>");
textoHtml = textoHtml.replaceAll("</h2>", "</p>");
textoHtml = textoHtml.replaceAll("<h5>", "<p>");
textoHtml = textoHtml.replaceAll("</h5>", "</p>");
textoHtml = textoHtml.replaceAll("<h1>", "<p>");
textoHtml = textoHtml.replaceAll("</h1>", "</p>");
textoHtml = textoHtml.replaceAll("o:p", "p");
textoHtml = textoHtml.replace("&nspace;"," ");
textoHtml = textoHtml.replace("&nspace2;"," ");
textoHtml = textoHtml.replace("&ndash2;","-");
textoHtml = textoHtml.replace("&ndash3;","˜");
textoHtml = textoHtml.replace("&ndash4;","™");
textoHtml = textoHtml.replace("&ndash5;","š");
textoHtml = textoHtml.replace("&ndash6;","›");
textoHtml = textoHtml.replace("&ndash7;","œ");
textoHtml = textoHtml.replace("&ndash8;","ž");
textoHtml = textoHtml.replace("&ndash9;","Ÿ");
textoHtml = textoHtml.replace("&ndash10;","-");
textoHtml = textoHtml.replace("&ndash11;","-");
textoHtml = textoHtml.replace("&ndash12;","-");
textoHtml = textoHtml.replace("&ndash13;","’");
textoHtml = textoHtml.replace("&ndash14;","‘");
//"<p>&nbsp;</p>"
String primeirosChar="";
......@@ -76,8 +120,9 @@ public class CadernoUtil {
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;} </style></head>" + textoHtml + "</body>";
textoHtml = "<body><head><style type='" + "text/css'" + ">p{font-family:Spranq eco sans;font-size:12px;margin-left:-4px;} ul {list-style-type: circle;} </style></head>" + textoHtml + "</body>";
//textoHtml = "<body><head></head>" + textoHtml + "</body>";
}
}
......@@ -179,6 +224,30 @@ public class CadernoUtil {
}
if (tag.equals("ol")){
tagAberta="<ol ";
tagFechada="<ol>";
tamanhoTag=4;
}
if (tag.equals("ul")){
tagAberta="<ul ";
tagFechada="<ul>";
tamanhoTag=4;
}
if (tag.equals("li")){
tagAberta="<li ";
tagFechada="<li>";
tamanhoTag=4;
}
int len = conteudoHtml.length();
String tagP = "";
......@@ -258,47 +327,67 @@ public class CadernoUtil {
return conteudoHtml;
}
public WordprocessingMLPackage ConverterHTML(String stringFromFile,String orgao,String titulo, ActionRequest actionRequest){
public WordprocessingMLPackage ConverterHTML(String stringFromFile,String orgao,String titulo, String idMateria,String delimitador,ActionRequest actionRequest) throws Docx4JException{
PortletContext context = actionRequest.getPortletSession().getPortletContext();
//String baseURL = "file:///" + context.getRealPath("/template");
String baseURL = "file:///" + getClass().getResourceAsStream("/META-INF/resources/template");
//XRLog.setLoggingEnabled(false);
String unescaped = stringFromFile;
InputStream templateEstilos = getClass().getResourceAsStream("/META-INF/resources/template/TemplateEstilos.docx");
WordprocessingMLPackage templatePackageEstilos = WordprocessingMLPackage.load(templateEstilos);
// Create an empty docx package
WordprocessingMLPackage wordMLPackage=null;
// System.out.println(XmlUtils.marshaltoString(templatePackageEstilos.getMainDocumentPart().getJaxbElement(), true, true));
//WordprocessingMLPackage wordMLPackage=null;
WordprocessingMLPackage wordMLPackage = templatePackageEstilos;
try {
wordMLPackage = WordprocessingMLPackage.createPackage();
//wordMLPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart DocumentPart = wordMLPackage.getMainDocumentPart();
String marcadorMateriaInicio = "##MATERIA##INICIO##ID: " + idMateria;
String marcadorMateriaFim = "##MATERIA##FIM##ID: " + idMateria;
if(delimitador.equals("on")) {
DocumentPart.addStyledParagraphOfText("MarcadorMateria",marcadorMateriaInicio);
}
if(!orgao.equals(ORGAO)){
DocumentPart.addStyledParagraphOfText("Heading1",orgao);
//TituloDoeMPRJ
DocumentPart.addStyledParagraphOfText("TituloDoeMPRJ",orgao);
ORGAO=orgao;
DocumentPart.addStyledParagraphOfText("Heading2",titulo);
DocumentPart.addStyledParagraphOfText("SubtituloDOe-MPRJ",titulo);
TITULO=titulo;
}
if(!titulo.equals(TITULO) && orgao.equals(ORGAO)){
DocumentPart.addStyledParagraphOfText("Heading2",titulo);
DocumentPart.addStyledParagraphOfText("SubtituloDOe-MPRJ",titulo);
TITULO=titulo;
}
NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
/*NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
ndp.unmarshalDefaultNumbering();
ndp.unmarshalDefaultNumbering();
ndp.restart(1, 0, 1);
ndp.restart(numId, ilvl, val)*/
// Convert the XHTML, and add it into the empty docx we made
XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
XHTMLImporter.setHyperlinkStyle("Heading1");
wordMLPackage.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert(unescaped, baseURL) );
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) );
if(delimitador.equals("on")) {
DocumentPart.addStyledParagraphOfText("MarcadorMateria",marcadorMateriaFim);
}
//System.out.println( XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
......@@ -332,7 +421,7 @@ public static String gerarDataCabecalho(String data) throws ParseException{
}
if (diaSemana == 3){
diaSemanaStr = "Tera-feira";
diaSemanaStr = "Ter\u00E7a-feira";
}
......@@ -352,7 +441,7 @@ public static String gerarDataCabecalho(String data) throws ParseException{
if (diaSemana == 7){
diaSemanaStr = "Sbado";
diaSemanaStr = "S\u00e1bado";
}
......@@ -367,7 +456,7 @@ public static String gerarDataCabecalho(String data) throws ParseException{
}
if(mes.equals("03")){
mesStr="maro";
mesStr="mar\u00E7o";
}
......@@ -421,4 +510,288 @@ public static String gerarDataCabecalho(String data) throws ParseException{
return resultado;
}
public static List<Object> getAllElementFromObject(Object obj, Class<?> toSearch) {
List<Object> result = new ArrayList<Object>();
if (obj instanceof JAXBElement) obj = ((JAXBElement<?>) obj).getValue();
if (obj.getClass().equals(toSearch))
result.add(obj);
else if (obj instanceof ContentAccessor) {
List<?> children = ((ContentAccessor) obj).getContent();
for (Object child : children) {
result.addAll(getAllElementFromObject(child, toSearch));
}
}
return result;
}
public static WordprocessingMLPackage formatarListas(WordprocessingMLPackage wordPackage,List<Lista>listaUl) throws InvalidFormatException, JAXBException {
DocumentPart parte = wordPackage.getMainDocumentPart();
Long indiceLista=0L;
Boolean eLista = false;
Boolean itemAnterior=false;
Boolean formatar;
Long numero=0L;
CadernoUtil caderno = new CadernoUtil();
List<Object> paragraphs = getAllElementFromObject(parte,P.class);
for(Object par : paragraphs){
System.out.println(numero);
P p = (P) par;
List<Object> Rs = getAllElementFromObject(p, R.class);
for(Object r : Rs){
R objetoR = (R)r;
List<Object> Rs2 = getAllElementFromObject(objetoR, R.class);
for(Object r2:Rs2) {
R objetoR2 = (R)r2;
Object objetoParent = objetoR2.getParent();
if (objetoR2.getParent() instanceof P) {
P parent = (P) objetoParent;
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();
if(numPr!=null) {
eLista=true;
//if(itemAnterior==false) {
indiceLista++;
//}
formatar=false;
Long ilvlValor=0L;
for(int i=0;i<listaUl.size();i++) {
if(indiceLista==listaUl.get(i).getPosicaoOl()) {
formatar=true;
Lista itemLista = listaUl.get(i);
ilvlValor = itemLista.getIlvl();
}
}
if(formatar==true) {
Ilvl ilvl = numPr.getIlvl();
//ilvl.setVal(BigInteger.ZERO);
ilvl.setVal(BigInteger.valueOf(ilvlValor));
numPr.setIlvl(ilvl);
NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
wordPackage.getMainDocumentPart().addTargetPart(ndp);
NumId numId = numPr.getNumId();
numId.setVal(BigInteger.ZERO);
numPr.setNumId(numId);
}else {
org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();
PPrBase.PStyle pprBaseStyle = wmlObjectFactory.createPPrBasePStyle();
Ilvl ilvl = numPr.getIlvl();
ilvl.setVal(BigInteger.ZERO);
NumId numId = numPr.getNumId();
numId.setVal(BigInteger.ZERO);
ppr.setPStyle(pprBaseStyle);
pprBaseStyle.setVal("marcadorBullet");
}
}else {
eLista=false;
}
}
}
}
itemAnterior = eLista;
numero++;
}
return wordPackage;
}
public static List<Lista> retornarOls(String conteudoHtml){
List<Lista> listaOls = new ArrayList<Lista>();
Boolean tagOl=false;
Boolean primeiroItem = true;
Long qtdListasAbertas=0L;
String tagAberta = "";
String tagFechada = "";
int tamanhoTag = 0;
tamanhoTag = 4;
int len = conteudoHtml.length();
String tagP = "";
for (int i = 0; i < len; i++) {
if (i + tamanhoTag < len) {
tagP = conteudoHtml.substring(i, i + tamanhoTag);
} else {
tagP = conteudoHtml.substring(i, len);
}
if (tagP.equals("<ol>")|| tagP.equals("<ul>") ) {
if(primeiroItem==true) {
primeiroItem=false;
}else {
qtdListasAbertas++;
}
if (tagP.equals("<ol>")) {
tagOl=true;
}else {
tagOl=false;
}
}
if (tagP.equals("</ol") || tagP.equals("</ul")) {
qtdListasAbertas--;
}
if (tagP.equals("<li>")) {
QTD_LISTAS++;
if (tagP.equals("<li>") && tagOl==true) {
//posicaoItemOl=QTD_LISTAS;
Lista lista = new Lista();
lista.setPosicaoOl(QTD_LISTAS);
lista.setIlvl(qtdListasAbertas);
listaOls.add(lista);
}
}
}
return listaOls;
}
public static String tratarLista(String conteudoHtml){
List<Integer> listaOls = new ArrayList<Integer>();
int indiceListaAtual=-1;
Boolean tagOl=false;
int margem=0;
int item=0;
int tamanhoTag = 0;
String marcador="";
String newTagP="";
String dezEspacos=" ";
String noveEspacos=" ";
tamanhoTag = 4;
int len = conteudoHtml.length();
String tagP = "";
for (int i = 0; i < len; i++) {
if (i + tamanhoTag < len) {
tagP = conteudoHtml.substring(i, i + tamanhoTag);
} else {
tagP = conteudoHtml.substring(i, len);
}
if (tagP.equals("<ol>")|| tagP.equals("<ul>") ) {
if (tagP.equals("<ol>")) {
tagOl=true;
item=1;
indiceListaAtual++;
listaOls.add(item);
}else {
tagOl=false;
}
}
if (tagP.equals("<li>")) {
if (tagP.equals("<li>")) {
if (tagOl==true) {
margem=(indiceListaAtual)*20;
newTagP = "<p style='margin-left:"+margem+"px'>";
if (item<=9) {
marcador = newTagP+String.valueOf(listaOls.get(indiceListaAtual))+"."+dezEspacos;
}else {
marcador = newTagP+String.valueOf(listaOls.get(indiceListaAtual))+"."+noveEspacos;
}
item=listaOls.get(indiceListaAtual)+1;
listaOls.set(indiceListaAtual, item);
conteudoHtml = conteudoHtml.substring(0,i ) + marcador + conteudoHtml.substring(i + tamanhoTag,conteudoHtml.length());
len = conteudoHtml.length();
}else {
marcador = "\u2022 ";
conteudoHtml = conteudoHtml.substring(0,i+tamanhoTag ) + marcador + conteudoHtml.substring(i + tamanhoTag,conteudoHtml.length());
len = conteudoHtml.length();
}
//posicaoItemOl=QTD_LISTAS;
//conteudoHtml = conteudoHtml.replace(tagP, tagP+marcador);
len = conteudoHtml.length();
}
}
if (tagP.equals("</ol")) {
indiceListaAtual--;
}
}
conteudoHtml = conteudoHtml.replaceAll("<ol>", "<p>");
conteudoHtml = conteudoHtml.replaceAll("<ul>", "<p>");
conteudoHtml = conteudoHtml.replaceAll("<li>", "<p>");
conteudoHtml = conteudoHtml.replaceAll("</li>", "</p>");
conteudoHtml = conteudoHtml.replaceAll("</ol>", "</p>");
conteudoHtml = conteudoHtml.replaceAll("</ul>", "</p>");
return conteudoHtml;
}
}
......@@ -6,6 +6,7 @@ import java.util.List;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart;
import org.docx4j.wml.CTLanguage;
import org.docx4j.wml.HpsMeasure;
import org.docx4j.wml.RFonts;
import org.docx4j.wml.RPr;
......@@ -30,14 +31,14 @@ public class Estilos {
"Hello World! This title is now in Arial.");
wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("Subtitle",
"Subtitle, this subtitle is now Arial too");
wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("Heading1",
wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("TituloDoeMPRJ",
"As is Heading1");
wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("Heading2",
wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("SubtituloDOe-MPRJ",
"Heading2 is now Arial, no longer bold and has an underline " +
"and fontsize 12");
wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("Heading3",
"Heading3 is now Arial");
wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("Normal",
wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("CorpoDoeMPRJ-Materia",
"And normal text has changed to Arial and fontsize 10");
wordMLPackage.save(new java.io.File("C:/Users/diogo.souza/Documents/Caderno DO/HelloWord12.docx") );
......@@ -61,11 +62,11 @@ public class Estilos {
List<Style> stylesList = styles.getStyle();
for (Style style : stylesList) {
if (style.getStyleId().equals("Normal")) {
if (style.getStyleId().equals("CorpoDoeMPRJ-Materia")) {
alterNormalStyle(style);
} else if (style.getStyleId().equals("Heading2")) {
} else if (style.getStyleId().equals("SubtituloDOe-MPRJ")) {
alterHeading2Style(style);
} else if (style.getStyleId().equals("Heading1") ||
} else if (style.getStyleId().equals("TituloDoeMPRJ") ||
style.getStyleId().equals("Heading3") ||
style.getStyleId().equals("Title") ||
style.getStyleId().equals("Subtitle")) {
......@@ -108,6 +109,9 @@ public class Estilos {
RPr rpr = new RPr();
changeFontToSpranq(rpr);
changeFontSize(rpr, 20);
CTLanguage lang = new CTLanguage();
lang.setVal("pt-BR");
rpr.setLang(lang);
style.setRPr(rpr);
}
......
package mprj.doerj.caderno.util;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.ContentTypes;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.WebKeys;
......@@ -16,7 +12,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
......@@ -27,17 +25,23 @@ import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import org.docx4j.XmlUtils;
import org.docx4j.convert.in.xhtml.FormattingOption;
import org.docx4j.convert.in.xhtml.XHTMLImporterImpl;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart;
import org.json.JSONArray;
import org.json.JSONObject;
import mprj.doerj.caderno.application.model.Lista;
public class GeraCaderno {
public void processaCaderno(ActionRequest actionRequest,ActionResponse actionResponse,JSONArray listaConteudos,String dataDivulgacao) throws Docx4JException, JAXBException, IOException, ParseException, PortalException{
public void processaCaderno(ActionRequest actionRequest,ActionResponse actionResponse,JSONArray listaConteudos,String dataDivulgacao,String delimitador) throws Docx4JException, JAXBException, IOException, ParseException, PortalException{
......@@ -53,6 +57,7 @@ public class GeraCaderno {
String conteudo="";
String orgao="";
String titulo="";
String idMateria="";
PortletPreferences prefs = actionRequest.getPreferences();
CadernoUtil util = new CadernoUtil();
MainDocumentPart currentDocumentPart = null;
......@@ -89,9 +94,9 @@ public class GeraCaderno {
//Cria o hash map com as variveis para substuio dos dados dos cabealhos e expediente
HashMap<String, String> variables = new HashMap<String, String>();
variables.put("edicao", edicao);
variables.put("disponibilizacao", disponibilizacao);
variables.put("publicacao", publicacao);
variables.put("edi", edicao);
variables.put("dis", disponibilizacao);
variables.put("pub", publicacao);
String PGJ = prefs.getValue("PGJConfig", "");
variables.put("PGJ", PGJ);
......@@ -175,12 +180,12 @@ public class GeraCaderno {
mainPart.variableReplace(variables);
Estilos estilo = new Estilos();
estilo.alterStyleSheet(acumuladoPackage);
// Estilos estilo = new Estilos();
//estilo.alterStyleSheet(acumuladoPackage);
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++){
......@@ -195,13 +200,15 @@ public class GeraCaderno {
titulo = obj.get("NOME").toString();
titulo = util.tratarString(titulo,"titulo");
conteudo = obj.get("CONTEUDO").toString();
idMateria=obj.get("IDMATERIA").toString();
conteudo=util.tratarString(conteudo,"conteudo");
wordCurrentPackage = util.ConverterHTML(conteudo,orgao,titulo,actionRequest);
conteudo=util.tratarLista(conteudo);
//listaOls.addAll(util.retornarOls(conteudo));
wordCurrentPackage = util.ConverterHTML(conteudo,orgao,titulo,idMateria,delimitador,actionRequest);
currentDocumentPart = wordCurrentPackage.getMainDocumentPart();
acumuladoPackage.getMainDocumentPart().getContent().addAll(currentDocumentPart.getContent());
wordCurrentPackage = null;
......@@ -211,15 +218,24 @@ public class GeraCaderno {
MainDocumentPart acumuladoDocumentPart = acumuladoPackage.getMainDocumentPart();
estilo.alterStyleSheet(templatePackage);
// estilo.alterStyleSheet(templatePackage);
/*XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(templatePackage);
XHTMLImporter.setParagraphFormatting(FormattingOption.CLASS_PLUS_OTHER);*/
templatePackage.getMainDocumentPart().getContent().addAll(acumuladoDocumentPart.getContent());
util.ORGAO="";
util.TITULO="";
//File exportFile = new File("C:/Users/diogo.souza/Documents/Caderno DO/testeDoc4JNovo.docx");
String dataNomeArquivo = dataDivulgacao.replace("/", "-");
String nomeArquivo="caderno_doerj_" + dataNomeArquivo + ".docx";
String nomeArquivo="";
if (delimitador.equals("on")) {
nomeArquivo="caderno_doerj_" + dataNomeArquivo + "_materia_delimitada.docx";
}else {
nomeArquivo="caderno_doerj_" + dataNomeArquivo + ".docx";
}
// InputStream nomeArquivoInputStream = getClass().getResourceAsStream("/META-INF/resources/template/"+nomeArquivo);
// File exportFile = new File(nomeArquivoInputStream.toString());
......@@ -228,11 +244,20 @@ public class GeraCaderno {
File exportFile = File.createTempFile("caderno_doerj_tmp_", ".docx");
try {
CadernoUtil caderno = new CadernoUtil();
//templatePackage = caderno.formatarListas(templatePackage,listaOls);
//acumuladoPackage = caderno.formatarListas(acumuladoPackage,listaOls);
//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);
//acumuladoPackage.save(exportFile);
PortletResponse pResponse = PortalUtil.getLiferayPortletResponse(actionResponse);
HttpServletResponse res = PortalUtil.getHttpServletResponse(pResponse);
......@@ -259,11 +284,23 @@ public class GeraCaderno {
}
}
catch (Exception e) {
e.printStackTrace();
exportFile.delete();
CadernoUtil caderno = new CadernoUtil();
caderno.QTD_LISTAS=0L;
}
finally {
exportFile.delete();
CadernoUtil caderno = new CadernoUtil();
caderno.QTD_LISTAS=0L;
}
}
}
......@@ -73,6 +73,8 @@
</div>
<liferay-ui:error key="erroDataNula" message="Uma data deve ser selecionada." />
</div>
<input type="checkbox" name="delimitador" id="delimitador" label="" />
<span style="font-weight: bold;">Inserir delimitador entre as matrias.</span>
<aui:button-row>
<aui:button type="reset" id="limparFormDO" name="limparFormDO" value="Limpar" />
<aui:button type="submit" id="enviarFormDO" name="enviarFormDO" value="Gerar Caderno"/>
......
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