Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
doerj-caderno-dxp-7.2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
diogo.souza
doerj-caderno-dxp-7.2
Commits
97c74c28
Commit
97c74c28
authored
Oct 22, 2020
by
Diogo Fellipe De Melo Souza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Versão com a implementação da classe estilos
parent
27bb600a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
220 additions
and
10 deletions
+220
-10
.gitignore
bin/main/.gitignore
+1
-0
MprjDoerjCadernoPortlet.class
.../mprj/doerj/caderno/portlet/MprjDoerjCadernoPortlet.class
+0
-0
GeraCaderno.class
bin/main/mprj/doerj/caderno/util/GeraCaderno.class
+0
-0
MprjDoerjCadernoPortlet.java
...a/mprj/doerj/caderno/portlet/MprjDoerjCadernoPortlet.java
+3
-3
Estilos.java
src/main/java/mprj/doerj/caderno/util/Estilos.java
+209
-0
GeraCaderno.java
src/main/java/mprj/doerj/caderno/util/GeraCaderno.java
+7
-7
No files found.
bin/main/.gitignore
0 → 100644
View file @
97c74c28
/mprj/
bin/main/mprj/doerj/caderno/portlet/MprjDoerjCadernoPortlet.class
View file @
97c74c28
No preview for this file type
bin/main/mprj/doerj/caderno/util/GeraCaderno.class
View file @
97c74c28
No preview for this file type
src/main/java/mprj/doerj/caderno/portlet/MprjDoerjCadernoPortlet.java
View file @
97c74c28
...
@@ -64,9 +64,9 @@ import mprj.doerj.caderno.util.GeraCaderno;
...
@@ -64,9 +64,9 @@ import mprj.doerj.caderno.util.GeraCaderno;
"javax.portlet.expiration-cache=0"
,
"javax.portlet.expiration-cache=0"
,
"javax.portlet.init-param.portlet-title-based-navigation=true"
,
"javax.portlet.init-param.portlet-title-based-navigation=true"
,
"javax.portlet.init-param.template-path=/"
,
"javax.portlet.init-param.template-path=/"
,
"javax.portlet.info.title=Caderno do Di
á
rio Oficial"
,
"javax.portlet.info.title=Caderno do Dirio Oficial"
,
"javax.portlet.info.short-title=Caderno do Di
á
rio Oficial"
,
"javax.portlet.info.short-title=Caderno do Dirio Oficial"
,
"javax.portlet.info.keywords=Caderno do Di
á
rio Oficial"
,
"javax.portlet.info.keywords=Caderno do Dirio Oficial"
,
"javax.portlet.init-param.template-path=/"
,
"javax.portlet.init-param.template-path=/"
,
"javax.portlet.init-param.view-template=/view.jsp"
,
"javax.portlet.init-param.view-template=/view.jsp"
,
"javax.portlet.init-param.config-template=/configuration.jsp"
,
"javax.portlet.init-param.config-template=/configuration.jsp"
,
...
...
src/main/java/mprj/doerj/caderno/util/Estilos.java
0 → 100644
View file @
97c74c28
package
mprj
.
doerj
.
caderno
.
util
;
import
java.math.BigInteger
;
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.HpsMeasure
;
import
org.docx4j.wml.RFonts
;
import
org.docx4j.wml.RPr
;
import
org.docx4j.wml.Style
;
import
org.docx4j.wml.Styles
;
import
org.docx4j.wml.U
;
import
org.docx4j.wml.UnderlineEnumeration
;
public
class
Estilos
{
private
static
WordprocessingMLPackage
wordMLPackage
;
/**
* First we create the package, then we alter the style sheet and add some
* styled paragraphs. Finally we save the package.
*/
public
static
void
main
(
String
[]
args
)
throws
Docx4JException
{
wordMLPackage
=
WordprocessingMLPackage
.
createPackage
();
alterStyleSheet
();
wordMLPackage
.
getMainDocumentPart
().
addStyledParagraphOfText
(
"Title"
,
"Hello World! This title is now in Arial."
);
wordMLPackage
.
getMainDocumentPart
().
addStyledParagraphOfText
(
"Subtitle"
,
"Subtitle, this subtitle is now Arial too"
);
wordMLPackage
.
getMainDocumentPart
().
addStyledParagraphOfText
(
"Heading1"
,
"As is Heading1"
);
wordMLPackage
.
getMainDocumentPart
().
addStyledParagraphOfText
(
"Heading2"
,
"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"
,
"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"
)
);
}
/**
* This method alters the default style sheet that is part of each document.
*
* To do this, we first retrieve the style sheet from the package and then
* get the Styles object from it. From this object, we get the list of actual
* styles and iterate over them.
* We check against all styles we want to alter and apply the alterations if
* applicable.
*
* @param wordMLPackage
*/
public
static
void
alterStyleSheet
()
{
StyleDefinitionsPart
styleDefinitionsPart
=
wordMLPackage
.
getMainDocumentPart
().
getStyleDefinitionsPart
();
Styles
styles
=
styleDefinitionsPart
.
getJaxbElement
();
List
<
Style
>
stylesList
=
styles
.
getStyle
();
for
(
Style
style
:
stylesList
)
{
if
(
style
.
getStyleId
().
equals
(
"Normal"
))
{
alterNormalStyle
(
style
);
}
else
if
(
style
.
getStyleId
().
equals
(
"Heading2"
))
{
alterHeading2Style
(
style
);
}
else
if
(
style
.
getStyleId
().
equals
(
"Heading1"
)
||
style
.
getStyleId
().
equals
(
"Heading3"
)
||
style
.
getStyleId
().
equals
(
"Title"
)
||
style
.
getStyleId
().
equals
(
"Subtitle"
))
{
getRunPropertiesAndRemoveThemeInfo
(
style
);
}
}
}
public
static
void
alterStyleSheet
(
WordprocessingMLPackage
wordPackage
)
{
StyleDefinitionsPart
styleDefinitionsPart
=
wordPackage
.
getMainDocumentPart
().
getStyleDefinitionsPart
();
Styles
styles
=
styleDefinitionsPart
.
getJaxbElement
();
List
<
Style
>
stylesList
=
styles
.
getStyle
();
for
(
Style
style
:
stylesList
)
{
if
(
style
.
getStyleId
().
equals
(
"Normal"
))
{
alterNormalStyle
(
style
);
}
else
if
(
style
.
getStyleId
().
equals
(
"Heading2"
))
{
alterHeading2Style
(
style
);
}
else
if
(
style
.
getStyleId
().
equals
(
"Heading1"
)){
alterHeading1Style
(
style
);
}
else
if
(
style
.
getStyleId
().
equals
(
"Heading3"
)
||
style
.
getStyleId
().
equals
(
"Title"
)
||
style
.
getStyleId
().
equals
(
"Subtitle"
)){
getRunPropertiesAndRemoveThemeInfo
(
style
);
}
}
}
/**
* First we create a run properties object as we want to remove nearly all of
* the existing styling. Then we change the font and font size and set the
* run properties on the given style. As in previous examples, the font size
* is defined to be in half-point size.
*/
private
static
void
alterNormalStyle
(
Style
style
)
{
// we want to change (or remove) almost all the run properties of the
// normal style, so we create a new one.
RPr
rpr
=
new
RPr
();
changeFontToSpranq
(
rpr
);
changeFontSize
(
rpr
,
20
);
style
.
setRPr
(
rpr
);
}
/**
* For this style, we get the existing run properties from the style and
* remove the theme font information from them. Then we also remove the bold
* styling, change the font size (half-points) and add an underline.
*/
private
static
void
alterHeading2Style
(
Style
style
)
{
RPr
rpr
=
getRunPropertiesAndRemoveThemeInfo
(
style
);
removeBoldStyle
(
rpr
);
changeFontSize
(
rpr
,
24
);
// addUnderline(rpr);
}
private
static
void
alterHeading1Style
(
Style
style
)
{
RPr
rpr
=
getRunPropertiesAndRemoveThemeInfo
(
style
);
removeBoldStyle
(
rpr
);
changeFontSize
(
rpr
,
28
);
// addUnderline(rpr);
}
private
static
RPr
getRunPropertiesAndRemoveThemeInfo
(
Style
style
)
{
// We only want to change some settings, so we get the existing run
// properties from the style.
RPr
rpr
=
style
.
getRPr
();
removeThemeFontInformation
(
rpr
);
return
rpr
;
}
/**
* Change the font of the given run properties to Arial.
*
* A run font specifies the fonts which shall be used to display the contents
* of the run. Of the four possible types of content, we change the styling of
* two of them: ASCII and High ANSI.
* Finally we add the run font to the run properties.
*
* @param runProperties
*/
private
static
void
changeFontToSpranq
(
RPr
runProperties
)
{
RFonts
runFont
=
new
RFonts
();
runFont
.
setAscii
(
"Spranq eco sans"
);
runFont
.
setHAnsi
(
"Spranq eco sans"
);
runProperties
.
setRFonts
(
runFont
);
}
/**
* Change the font size of the given run properties to the given value.
*
* @param runProperties
* @param fontSize Twice the size needed, as it is specified as half-point value
*/
private
static
void
changeFontSize
(
RPr
runProperties
,
int
fontSize
)
{
HpsMeasure
size
=
new
HpsMeasure
();
size
.
setVal
(
BigInteger
.
valueOf
(
fontSize
));
runProperties
.
setSz
(
size
);
runProperties
.
setColor
(
null
);
RFonts
runFont
=
new
RFonts
();
runFont
.
setAscii
(
"Spranq eco sans"
);
runFont
.
setHAnsi
(
"Spranq eco sans"
);
runProperties
.
setRFonts
(
runFont
);
}
/**
* Removes the theme font information from the run properties.
* If this is not removed then the styles based on the normal style won't
* inherit the Arial font from the normal style.
*
* @param runProperties
*/
private
static
void
removeThemeFontInformation
(
RPr
runProperties
)
{
runProperties
.
getRFonts
().
setAsciiTheme
(
null
);
runProperties
.
getRFonts
().
setHAnsiTheme
(
null
);
}
/**
* Removes the Bold styling from the run properties.
*
* @param runProperties
*/
private
static
void
removeBoldStyle
(
RPr
runProperties
)
{
runProperties
.
getB
().
setVal
(
false
);
}
/**
* Adds a single underline to the run properties.
*
* @param runProperties
*/
private
static
void
addUnderline
(
RPr
runProperties
)
{
U
underline
=
new
U
();
underline
.
setVal
(
UnderlineEnumeration
.
SINGLE
);
runProperties
.
setU
(
underline
);
}
}
src/main/java/mprj/doerj/caderno/util/GeraCaderno.java
View file @
97c74c28
...
@@ -64,7 +64,7 @@ public class GeraCaderno {
...
@@ -64,7 +64,7 @@ public class GeraCaderno {
//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 cabe
ç
alho
//Preenche os dados do cabealho
MainDocumentPart
headerDocumentPart
=
templatePackage
.
getMainDocumentPart
();
MainDocumentPart
headerDocumentPart
=
templatePackage
.
getMainDocumentPart
();
...
@@ -83,7 +83,7 @@ public class GeraCaderno {
...
@@ -83,7 +83,7 @@ public class GeraCaderno {
//Cria o hash map com as vari
áveis para substuição dos dados dos cabeç
alhos e expediente
//Cria o hash map com as vari
veis para substuio dos dados dos cabe
alhos e expediente
HashMap
<
String
,
String
>
variables
=
new
HashMap
<
String
,
String
>();
HashMap
<
String
,
String
>
variables
=
new
HashMap
<
String
,
String
>();
variables
.
put
(
"edicao"
,
edicao
);
variables
.
put
(
"edicao"
,
edicao
);
variables
.
put
(
"disponibilizacao"
,
disponibilizacao
);
variables
.
put
(
"disponibilizacao"
,
disponibilizacao
);
...
@@ -171,13 +171,13 @@ public class GeraCaderno {
...
@@ -171,13 +171,13 @@ public class GeraCaderno {
mainPart
.
variableReplace
(
variables
);
mainPart
.
variableReplace
(
variables
);
//AINDA FALTA IMPLEMENTAR A CLASSE
Estilos estilo = new Estilos();
Estilos
estilo
=
new
Estilos
();
//AINDA FALTA IMPLEMENTAR A CLASSE
estilo.alterStyleSheet(acumuladoPackage);
estilo
.
alterStyleSheet
(
acumuladoPackage
);
WordprocessingMLPackage
firstPagePackage
=
WordprocessingMLPackage
.
createPackage
();
WordprocessingMLPackage
firstPagePackage
=
WordprocessingMLPackage
.
createPackage
();
boolean
firstPage
=
true
;
boolean
firstPage
=
true
;
//faz a leitura da listagem de todos os conte
údos recebidos pelo serviç
o Rest
//faz a leitura da listagem de todos os conte
dos recebidos pelo servi
o Rest
for
(
int
i
=
0
;
i
<
listaConteudos
.
length
();
i
++){
for
(
int
i
=
0
;
i
<
listaConteudos
.
length
();
i
++){
WordprocessingMLPackage
wordCurrentPackage
=
WordprocessingMLPackage
.
createPackage
();
WordprocessingMLPackage
wordCurrentPackage
=
WordprocessingMLPackage
.
createPackage
();
...
@@ -207,7 +207,7 @@ public class GeraCaderno {
...
@@ -207,7 +207,7 @@ public class GeraCaderno {
MainDocumentPart
acumuladoDocumentPart
=
acumuladoPackage
.
getMainDocumentPart
();
MainDocumentPart
acumuladoDocumentPart
=
acumuladoPackage
.
getMainDocumentPart
();
//AINDA FALTA IMPLEMANTAR A CLASSE
estilo.alterStyleSheet(templatePackage);
estilo
.
alterStyleSheet
(
templatePackage
);
templatePackage
.
getMainDocumentPart
().
getContent
().
addAll
(
acumuladoDocumentPart
.
getContent
());
templatePackage
.
getMainDocumentPart
().
getContent
().
addAll
(
acumuladoDocumentPart
.
getContent
());
...
@@ -220,7 +220,7 @@ public class GeraCaderno {
...
@@ -220,7 +220,7 @@ public class GeraCaderno {
// InputStream nomeArquivoInputStream = getClass().getResourceAsStream("/META-INF/resources/template/"+nomeArquivo);
// InputStream nomeArquivoInputStream = getClass().getResourceAsStream("/META-INF/resources/template/"+nomeArquivo);
// File exportFile = new File(nomeArquivoInputStream.toString());
// File exportFile = new File(nomeArquivoInputStream.toString());
//cria o arquivo tempor
ário que será utilizado na resposta da requisiçã
o
//cria o arquivo tempor
rio que ser utilizado na resposta da requisi
o
File
exportFile
=
File
.
createTempFile
(
"caderno_doerj_tmp_"
,
".docx"
);
File
exportFile
=
File
.
createTempFile
(
"caderno_doerj_tmp_"
,
".docx"
);
try
{
try
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment