Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GoikLectures
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Goik Martin
GoikLectures
Commits
ba3c93e2
Commit
ba3c93e2
authored
5 years ago
by
Goik Martin
Browse files
Options
Downloads
Patches
Plain Diff
Use parameterized XPath query
parent
23b2d885
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Klausuren/Sda1/2016Summer/Solve/src/main/java/de/hdm_stuttgart/mi/sda1/exam/movie_by_actor/Moviedb2MovieByActor.java
+41
-37
41 additions, 37 deletions
...art/mi/sda1/exam/movie_by_actor/Moviedb2MovieByActor.java
with
41 additions
and
37 deletions
Klausuren/Sda1/2016Summer/Solve/src/main/java/de/hdm_stuttgart/mi/sda1/exam/movie_by_actor/Moviedb2MovieByActor.java
+
41
−
37
View file @
ba3c93e2
package
de.hdm_stuttgart.mi.sda1.exam.movie_by_actor
;
package
de.hdm_stuttgart.mi.sda1.exam.movie_by_actor
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.jdom2.Document
;
import
org.jdom2.Document
;
import
org.jdom2.Element
;
import
org.jdom2.Element
;
import
org.jdom2.filter.Filters
;
import
org.jdom2.filter.Filters
;
...
@@ -14,57 +14,61 @@ import org.jdom2.xpath.XPathFactory;
...
@@ -14,57 +14,61 @@ import org.jdom2.xpath.XPathFactory;
import
de.hdm_stuttgart.mi.unitmarking.jdom.DomFilter
;
import
de.hdm_stuttgart.mi.unitmarking.jdom.DomFilter
;
public
class
Moviedb2MovieByActor
implements
DomFilter
{
public
class
Moviedb2MovieByActor
implements
DomFilter
{
final
Logger
log
=
LogManager
.
getLogger
(
Moviedb2MovieByActor
.
class
);
static
private
final
String
SEARCH_BY_ID_KEY
=
"searchById"
;
Element
movieDb
;
static
{
// Initialize static parameterized Xpath query object,
// see https://freedocs.mi.hdm-stuttgart.de/__slidedom.html#/sda1_dom_fig_domXpathVariables.
final
Map
<
String
,
Object
>
xpathVarsNamespacePrefix
=
new
HashMap
<>();
xpathVarsNamespacePrefix
.
put
(
SEARCH_BY_ID_KEY
,
null
/* default namespace */
);
searchMovieByActorId
=
XPathFactory
.
instance
().
compile
(
"/movieDb/movies/movie[cast/actor[@ref=$"
+
SEARCH_BY_ID_KEY
+
"]]"
,
Filters
.
element
(),
xpathVarsNamespacePrefix
);
}
static
private
final
XPathExpression
<
Element
>
searchMovieByActorId
;
@Override
@Override
public
Document
process
(
final
Document
input
)
{
public
Document
process
(
final
Document
input
)
{
final
Element
html
=
new
Element
(
"html"
);
final
Element
html
=
new
Element
(
"html"
);
final
Document
htmlDoc
=
new
Document
(
html
);
final
Document
htmlDoc
=
new
Document
(
html
);
final
Element
body
=
new
Element
(
"body"
);
final
Element
body
=
new
Element
(
"body"
);
html
.
addContent
(
body
);
html
.
addContent
(
body
);
final
Element
dl
=
new
Element
(
"dl"
);
final
Element
dl
=
new
Element
(
"dl"
);
body
.
addContent
(
new
Element
(
"h1"
)
body
.
addContent
(
new
Element
(
"h1"
)
.
addContent
(
"List of actors among with their corresponding films"
))
.
addContent
(
"List of actors among with their corresponding films"
))
.
addContent
(
dl
);
.
addContent
(
dl
);
movieDb
=
input
.
getRootElement
();
input
.
getRootElement
().
getChild
(
"persons"
).
getChildren
().
forEach
(
movieDb
.
getChild
(
"persons"
).
getChildren
().
stream
().
forEach
(
p
->
addFilmsToActor
(
dl
,
p
)
p
->
addFilmsToActor
(
dl
,
p
)
);
);
return
htmlDoc
;
return
htmlDoc
;
}
}
void
addFilmsToActor
(
final
Element
dl
,
final
Element
person
)
{
private
void
addFilmsToActor
(
final
Element
dl
,
final
Element
person
)
{
final
String
movies2actorId
=
"movie[cast/actor[@ref='"
searchMovieByActorId
.
setVariable
(
SEARCH_BY_ID_KEY
,
person
.
getAttributeValue
(
"id"
));
+
person
.
getAttributeValue
(
"id"
)
+
"']]"
;
final
List
<
Element
>
movies
=
searchMovieByActorId
.
evaluate
(
person
);
final
XPathExpression
<
Element
>
xpath
=
XPathFactory
.
instance
().
compile
(
movies2actorId
,
Filters
.
element
());
if
(
0
<
movies
.
size
())
{
final
List
<
Element
>
titles
=
xpath
.
evaluate
(
movieDb
.
getChild
(
"movies"
));
if
(
0
<
titles
.
size
())
{
final
Element
dt
=
new
Element
(
"dt"
),
final
Element
dt
=
new
Element
(
"dt"
),
dd
=
new
Element
(
"dd"
);
dd
=
new
Element
(
"dd"
);
dl
.
addContent
(
dt
).
addContent
(
dd
);
dl
.
addContent
(
dt
).
addContent
(
dd
);
dt
.
addContent
(
person
.
getChild
(
"name"
).
getText
());
dt
.
addContent
(
person
.
getChild
(
"name"
).
getText
());
titles
.
stream
()
movies
.
stream
()
.
map
(
t
->
t
.
getChild
(
"title"
).
getText
())
.
map
(
t
->
t
.
getChild
(
"title"
).
getText
())
.
forEach
(
s
->
{
.
forEach
(
s
->
dd
.
addContent
(
new
Element
(
"p"
).
addContent
(
s
)));
dd
.
addContent
(
new
Element
(
"p"
).
addContent
(
s
));
});
}
}
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment