Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
97262196
Commit
97262196
authored
6 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
no-jira: make xstream static and more try with resources
parent
e827107b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/org/olat/repository/RepositoryEntryImportExport.java
+18
-31
18 additions, 31 deletions
...java/org/olat/repository/RepositoryEntryImportExport.java
with
18 additions
and
31 deletions
src/main/java/org/olat/repository/RepositoryEntryImportExport.java
+
18
−
31
View file @
97262196
...
...
@@ -84,6 +84,20 @@ public class RepositoryEntryImportExport {
private
static
final
String
PROP_DISPLAYNAME
=
"DisplayName"
;
private
static
final
String
PROP_DECRIPTION
=
"Description"
;
private
static
final
String
PROP_INITIALAUTHOR
=
"InitialAuthor"
;
private
static
final
XStream
xstream
=
XStreamHelper
.
createXStreamInstance
();
static
{
xstream
.
alias
(
PROP_ROOT
,
RepositoryEntryImport
.
class
);
xstream
.
aliasField
(
PROP_SOFTKEY
,
RepositoryEntryImport
.
class
,
"softkey"
);
xstream
.
aliasField
(
PROP_RESOURCENAME
,
RepositoryEntryImport
.
class
,
"resourcename"
);
xstream
.
aliasField
(
PROP_DISPLAYNAME
,
RepositoryEntryImport
.
class
,
"displayname"
);
xstream
.
aliasField
(
PROP_DECRIPTION
,
RepositoryEntryImport
.
class
,
"description"
);
xstream
.
aliasField
(
PROP_INITIALAUTHOR
,
RepositoryEntryImport
.
class
,
"initialAuthor"
);
xstream
.
omitField
(
RepositoryEntryImport
.
class
,
"outer-class"
);
xstream
.
ignoreUnknownElements
();
}
private
boolean
propertiesLoaded
=
false
;
private
RepositoryEntry
re
;
...
...
@@ -134,11 +148,7 @@ public class RepositoryEntryImportExport {
*/
public
void
exportDoExportProperties
()
{
// save repository entry properties
FileOutputStream
fOut
=
null
;
try
{
fOut
=
new
FileOutputStream
(
new
File
(
baseDirectory
,
PROPERTIES_FILE
));
XStream
xstream
=
getXStream
();
try
(
FileOutputStream
fOut
=
new
FileOutputStream
(
new
File
(
baseDirectory
,
PROPERTIES_FILE
)))
{
RepositoryEntryImport
imp
=
new
RepositoryEntryImport
(
re
);
RepositoryManager
rm
=
RepositoryManager
.
getInstance
();
VFSLeaf
image
=
rm
.
getImage
(
re
);
...
...
@@ -160,8 +170,6 @@ public class RepositoryEntryImportExport {
xstream
.
toXML
(
imp
,
fOut
);
}
catch
(
IOException
ioe
)
{
throw
new
OLATRuntimeException
(
"Error writing repo properties."
,
ioe
);
}
finally
{
FileUtils
.
closeSafely
(
fOut
);
}
}
...
...
@@ -208,7 +216,7 @@ public class RepositoryEntryImportExport {
zout
.
putNextEntry
(
new
ZipEntry
(
PROPERTIES_FILE
));
try
(
OutputStream
out
=
new
ShieldOutputStream
(
zout
))
{
getXS
tream
()
.
toXML
(
imp
,
out
);
xs
tream
.
toXML
(
imp
,
out
);
}
catch
(
IOException
e
)
{
log
.
error
(
""
,
e
);
}
...
...
@@ -329,14 +337,14 @@ public class RepositoryEntryImportExport {
try
(
FileSystem
fs
=
FileSystems
.
newFileSystem
(
baseDirectory
.
toPath
(),
null
))
{
Path
fPath
=
fs
.
getPath
(
"/"
);
Path
manifestPath
=
fPath
.
resolve
(
"export"
).
resolve
(
PROPERTIES_FILE
);
repositoryProperties
=
(
RepositoryEntryImport
)
XStreamHelper
.
readObject
(
getXS
tream
()
,
manifestPath
);
repositoryProperties
=
(
RepositoryEntryImport
)
XStreamHelper
.
readObject
(
xs
tream
,
manifestPath
);
}
catch
(
Exception
e
)
{
log
.
error
(
""
,
e
);
}
}
else
{
File
inputFile
=
new
File
(
baseDirectory
,
PROPERTIES_FILE
);
if
(
inputFile
.
exists
())
{
repositoryProperties
=
(
RepositoryEntryImport
)
XStreamHelper
.
readObject
(
getXS
tream
()
,
inputFile
);
repositoryProperties
=
(
RepositoryEntryImport
)
XStreamHelper
.
readObject
(
xs
tream
,
inputFile
);
}
else
{
repositoryProperties
=
new
RepositoryEntryImport
();
}
...
...
@@ -356,7 +364,6 @@ public class RepositoryEntryImportExport {
*/
public
static
RepositoryEntryImport
getConfiguration
(
Path
repoXmlPath
)
{
try
(
InputStream
in
=
Files
.
newInputStream
(
repoXmlPath
))
{
XStream
xstream
=
getXStream
();
return
(
RepositoryEntryImport
)
xstream
.
fromXML
(
in
);
}
catch
(
IOException
e
)
{
log
.
error
(
""
,
e
);
...
...
@@ -372,28 +379,8 @@ public class RepositoryEntryImportExport {
* @return The RepositoryEntryImport or NULL
*/
public
static
RepositoryEntryImport
getConfiguration
(
InputStream
repoMetaFileInputStream
)
{
XStream
xstream
=
getXStream
();
return
(
RepositoryEntryImport
)
xstream
.
fromXML
(
repoMetaFileInputStream
);
}
/**
* Helper to load the xstream instances with all the aliases for the
* RepositoryEntryImport class
*
* @return
*/
private
static
XStream
getXStream
()
{
XStream
xStream
=
XStreamHelper
.
createXStreamInstance
();
xStream
.
alias
(
PROP_ROOT
,
RepositoryEntryImport
.
class
);
xStream
.
aliasField
(
PROP_SOFTKEY
,
RepositoryEntryImport
.
class
,
"softkey"
);
xStream
.
aliasField
(
PROP_RESOURCENAME
,
RepositoryEntryImport
.
class
,
"resourcename"
);
xStream
.
aliasField
(
PROP_DISPLAYNAME
,
RepositoryEntryImport
.
class
,
"displayname"
);
xStream
.
aliasField
(
PROP_DECRIPTION
,
RepositoryEntryImport
.
class
,
"description"
);
xStream
.
aliasField
(
PROP_INITIALAUTHOR
,
RepositoryEntryImport
.
class
,
"initialAuthor"
);
xStream
.
omitField
(
RepositoryEntryImport
.
class
,
"outer-class"
);
xStream
.
ignoreUnknownElements
();
return
xStream
;
}
/**
* @return The softkey
...
...
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