11package edu .cmu .oli .content .resource .builders ;
22
3- import edu .cmu .oli .content .models .persistance .entities .ContentPackage ;
4- import edu .cmu .oli .content .models .persistance .entities .WebContent ;
3+ import java .io .FileOutputStream ;
4+ import java .io .IOException ;
5+ import java .io .OutputStream ;
6+
57import org .jdom2 .DocType ;
68import org .jdom2 .Document ;
79import org .jdom2 .Element ;
1113import org .slf4j .Logger ;
1214import org .slf4j .LoggerFactory ;
1315
14- import java .io .FileOutputStream ;
15- import java .io .IOException ;
16- import java .io .OutputStream ;
16+ import edu .cmu .oli .content .models .persistance .entities .ContentPackage ;
17+ import edu .cmu .oli .content .models .persistance .entities .WebContent ;
1718
1819/**
1920 * Methods for generating content package manifest XML.
@@ -26,11 +27,11 @@ public final class ContentPkgXmlWriter {
2627 private static final String _SYSTEM_ID = "http://oli.cmu.edu/dtd/oli_content_package_simple_2_0.dtd" ;
2728 // Metadata and preference namespaces
2829
29- private static final Namespace _METADATA_NS
30- = Namespace . getNamespace ( "cmd" , "http://oli.web.cmu.edu/content/metadata/" );
30+ private static final Namespace _METADATA_NS = Namespace . getNamespace ( "cmd" ,
31+ "http://oli.web.cmu.edu/content/metadata/" );
3132
32- private static final Namespace _PREFERENCES_NS
33- = Namespace . getNamespace ( "pref" , "http://oli.web.cmu.edu/preferences/" );
33+ private static final Namespace _PREFERENCES_NS = Namespace . getNamespace ( "pref" ,
34+ "http://oli.web.cmu.edu/preferences/" );
3435
3536 private static final Logger log = LoggerFactory .getLogger (ContentPkgXmlWriter .class );
3637
@@ -46,39 +47,37 @@ private ContentPkgXmlWriter() {
4647
4748 /**
4849 * <p>
49- * Converts the given content package manifest to an XML document and writes
50- * the document to the specified file. The resulting XML will validate to
51- * the OLI content package DTD, provided the package was constructed in
52- * accordance with the general contract of said DTD.
50+ * Converts the given content package manifest to an XML document and writes the
51+ * document to the specified file. The resulting XML will validate to the OLI
52+ * content package DTD, provided the package was constructed in accordance with
53+ * the general contract of said DTD.
5354 *
5455 * @param mnfst content package manifest
5556 * @param dstFile destination file
5657 * @throws NullPointerException if either argument is <tt>null</tt>
5758 * @throws IOException if an error occurs while outputting the document
5859 */
59- public static void manifestToFile (ContentPackage mnfst , java .io .File dstFile )
60- throws IOException {
60+ public static void manifestToFile (ContentPackage mnfst , java .io .File dstFile ) throws IOException {
6161
6262 try ( // Convert package and output document
63- FileOutputStream fos = new FileOutputStream (dstFile )) {
63+ FileOutputStream fos = new FileOutputStream (dstFile )) {
6464 manifestToStream (mnfst , fos );
6565 }
6666 }
6767
6868 /**
6969 * <p>
70- * Converts the given content package manifest to an XML document and writes
71- * the document to the specified output stream. The resulting XML will
72- * validate to the OLI content package DTD, provided the package was
73- * constructed in accordance with the general contract of said DTD.
70+ * Converts the given content package manifest to an XML document and writes the
71+ * document to the specified output stream. The resulting XML will validate to
72+ * the OLI content package DTD, provided the package was constructed in
73+ * accordance with the general contract of said DTD.
7474 *
7575 * @param mnfst content package manifest
7676 * @param os output stream
7777 * @throws NullPointerException if either argument is <tt>null</tt>
7878 * @throws IOException if an error occurs while outputting the document
7979 */
80- public static void manifestToStream (ContentPackage mnfst , OutputStream os )
81- throws IOException {
80+ public static void manifestToStream (ContentPackage mnfst , OutputStream os ) throws IOException {
8281
8382 if (mnfst == null ) {
8483 throw (new NullPointerException ("'mnfst' cannot be null" ));
@@ -97,10 +96,9 @@ public static void manifestToStream(ContentPackage mnfst, OutputStream os)
9796
9897 /**
9998 * <p>
100- * Converts the given content package manifest to an XML document. The
101- * resulting XML will validate to the OLI content package DTD, provided the
102- * package was constructed in accordance with the general contract of said
103- * DTD.
99+ * Converts the given content package manifest to an XML document. The resulting
100+ * XML will validate to the OLI content package DTD, provided the package was
101+ * constructed in accordance with the general contract of said DTD.
104102 *
105103 * @param contentPkg content package manifest
106104 * @return XML document representation of the content package manifest
@@ -128,9 +126,9 @@ public static Document manifestToDocument(ContentPackage contentPkg) {
128126 // =======================================================================
129127 private static Element manifestToElement (ContentPackage contentPkg ) {
130128
131- Element pkgElmnt = new Element ("package" );//mnfstDoc.getRootElement();
129+ Element pkgElmnt = new Element ("package" );// mnfstDoc.getRootElement();
132130
133- //ContentPackage mnfst = parsePackageJson(pkgElmnt);
131+ // ContentPackage mnfst = parsePackageJson(pkgElmnt);
134132
135133 // Package ID and version
136134 pkgElmnt .setAttribute ("id" , contentPkg .getId ());
@@ -152,7 +150,8 @@ private static Element manifestToElement(ContentPackage contentPkg) {
152150
153151 // Metadata
154152 if (contentPkg .getMetadata () != null ) {
155- Element pkgMdElmnt = MetadataWriter .metadataToElement (contentPkg .getMetadata ().getJsonObject (), _METADATA_NS );
153+ Element pkgMdElmnt = MetadataWriter .metadataToElement (contentPkg .getMetadata ().getJsonObject (),
154+ _METADATA_NS );
156155 if (pkgMdElmnt != null ) {
157156 pkgElmnt .addContent (pkgMdElmnt );
158157 }
@@ -167,12 +166,20 @@ private static Element manifestToElement(ContentPackage contentPkg) {
167166
168167 // Preferences
169168 if (contentPkg .getOptions () != null ) {
170- Element prefsElmnt = OptionsWriter .preferenceSetToElement (contentPkg .getOptions ().getJsonObject (), _PREFERENCES_NS );
169+ Element prefsElmnt = OptionsWriter .preferenceSetToElement (contentPkg .getOptions ().getJsonObject (),
170+ _PREFERENCES_NS );
171171 if (prefsElmnt != null ) {
172172 pkgElmnt .addContent (prefsElmnt );
173173 }
174174 }
175175
176+ // Language
177+ if (contentPkg .getLanguage () != null ) {
178+ Element pkgLanguageElmnt = new Element ("langauge" );
179+ pkgLanguageElmnt .setText (contentPkg .getLanguage ());
180+ pkgElmnt .addContent (pkgLanguageElmnt );
181+ }
182+
176183 return pkgElmnt ;
177184 }
178185}
0 commit comments