@Override public void writeTo(final OutputStream out, final String encoding) throws Exception { // Marshal the PLIST playlist. final StringWriter writer = new StringWriter(); final XmlSerializer serializer = XmlSerializer.getMapping("chameleon/plist"); // May throw Exception. // Specifies whether XML documents (as generated at marshalling) should use indentation or not. Default is false. serializer.getMarshaller().setProperty("org.exolab.castor.indent", "true"); serializer.marshal(_plist, writer, false); // May throw Exception. String enc = encoding; if (enc == null) { enc = "UTF-8"; } final byte[] bytes = writer.toString().getBytes(enc); // May throw UnsupportedEncodingException. out.write(bytes); // Throws NullPointerException if out is null. May throw IOException. out.flush(); // May throw IOException. }
/** * Unmarshalls an object from an input URL, according to the underlying mapping. * @param url an URL. * @throws MappingException an exception indicating an invalid mapping error. * @throws IOException if an I/O exception occurs. * @throws org.exolab.castor.xml.MarshalException when there is an error during the unmarshalling process. * @throws org.exolab.castor.xml.ValidationException when there is a validation error. * @throws NullPointerException if <code>url</code> is <code>null</code>. * @see #unmarshal(InputStream) * @see Mapping */ public Object unmarshal(final URL url) throws Exception { return unmarshal(url.openStream()); // Throws NullPointerException if url is null. May throw MappingException, IOException, MarshalException, ValidationException. }
@Override public SpecificPlaylist readFrom(final InputStream in, final String encoding, final Log logger) throws Exception { String enc = encoding; if (enc == null) { enc = "UTF-8"; } String str = IOUtils.toString(in, enc); // May throw IOException. Throws NullPointerException if in is null. // Replace all occurrences of a single '&' with "&" (or leave this construct as is). // First replace blindly all '&' to its corresponding character reference. str = str.replace("&", "&"); // Then restore any existing character reference. str = str.replaceAll("&([a-zA-Z0-9#]+;)", "&$1"); // Shall not throw PatternSyntaxException. // Unmarshal the B4S playlist. final XmlSerializer serializer = XmlSerializer.getMapping("chameleon/playlist/b4s"); // May throw Exception. serializer.getUnmarshaller().setIgnoreExtraElements(false); // Force an error if unknown elements are found. final StringReader reader = new StringReader(str); final SpecificPlaylist ret = (SpecificPlaylist) serializer.unmarshal(reader); // May throw Exception. ret.setProvider(this); return ret; }
/** * Writes the specified object as an XML stream to an output file. * @param o the object to serialize. * @param fileName an XML file name. * @param asDocument if <code>true</code>, indicates to marshal as a complete XML document, which includes the XML declaration, and if necessary the DOCTYPE declaration. * @throws IOException if the named file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason. * @throws IOException if any I/O error occurred. * @throws MappingException an exception indicating an invalid mapping error. * @throws org.exolab.castor.xml.MarshalException a marshalling exception. * @throws org.exolab.castor.xml.ValidationException an XML validation error occurred. * @throws NullPointerException if <code>o</code> is <code>null</code>. * @throws NullPointerException if <code>fileName</code> is <code>null</code>. * @see #marshal(Object,Writer,boolean) * @see Mapping */ public void marshal(final Object o, final String fileName, final boolean asDocument) throws Exception { final FileWriter out = new FileWriter(fileName, false); // May throw IOException. marshal(o, out, asDocument); // May throw MappingException, MarshalException, ValidationException. out.flush(); // May throw IOException. out.close(); // May throw IOException. }
@Override public SpecificPlaylist readFrom(final InputStream in, final String encoding, final Log logger) throws Exception { String enc = encoding; if (enc == null) { enc = "UTF-8"; } String str = IOUtils.toString(in, enc); // May throw IOException. Throws NullPointerException if in is null. // Replace all occurrences of a single '&' with "&" (or leave this construct as is). // First replace blindly all '&' to its corresponding character reference. str = str.replace("&", "&"); // Then restore any existing character reference. str = str.replaceAll("&([a-zA-Z0-9#]+;)", "&$1"); // Shall not throw PatternSyntaxException. // Unmarshal the WPL playlist. final XmlSerializer serializer = XmlSerializer.getMapping("chameleon/playlist/xspf"); // May throw Exception. serializer.getUnmarshaller().setIgnoreExtraElements(true); final StringReader reader = new StringReader(str); final SpecificPlaylist ret = (SpecificPlaylist) serializer.unmarshal(reader); // May throw Exception. ret.setProvider(this); return ret; }
/** * Writes the specified object as an XML stream to an output file. * @param o the object to serialize. * @param file an XML file. * @param asDocument if <code>true</code>, indicates to marshal as a complete XML document, which includes the XML declaration, and if necessary the DOCTYPE declaration. * @throws IOException if the named file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason. * @throws IOException if any I/O error occurred. * @throws MappingException an exception indicating an invalid mapping error. * @throws org.exolab.castor.xml.MarshalException a marshalling exception. * @throws org.exolab.castor.xml.ValidationException an XML validation error occurred. * @throws NullPointerException if <code>o</code> is <code>null</code>. * @throws NullPointerException if <code>file</code> is <code>null</code>. * @see #marshal(Object,Writer,boolean) * @see Mapping */ public void marshal(final Object o, final File file, final boolean asDocument) throws Exception { final FileWriter out = new FileWriter(file, false); // May throw IOException. marshal(o, out, asDocument); // May throw MappingException, MarshalException, ValidationException. out.flush(); // May throw IOException. out.close(); // May throw IOException. }
@Override public void writeTo(final OutputStream out, final String encoding) throws Exception { // Marshal the SMIL playlist. final StringWriter writer = new StringWriter(); final XmlSerializer serializer = XmlSerializer.getMapping("chameleon/playlist/wpl"); // May throw Exception. // Specifies whether XML documents (as generated at marshalling) should use indentation or not. Default is false. serializer.getMarshaller().setProperty("org.exolab.castor.indent", "true"); serializer.marshal(this, writer, false); // May throw Exception. String enc = encoding; if (enc == null) { enc = "UTF-8"; } final byte[] bytes = writer.toString().getBytes(enc); // May throw UnsupportedEncodingException. out.write(bytes); // Throws NullPointerException if out is null. May throw IOException. out.flush(); // May throw IOException. }
@Override public SpecificPlaylist readFrom(final InputStream in, final String encoding, final Log logger) throws Exception { String enc = encoding; if (enc == null) { enc = "UTF-8"; } String str = IOUtils.toString(in, enc); // May throw IOException. Throws NullPointerException if in is null. // Replace all occurrences of a single '&' with "&" (or leave this construct as is). // First replace blindly all '&' to its corresponding character reference. str = str.replace("&", "&"); // Then restore any existing character reference. str = str.replaceAll("&([a-zA-Z0-9#]+;)", "&$1"); // Shall not throw PatternSyntaxException. // Unmarshal the WPL playlist. final XmlSerializer serializer = XmlSerializer.getMapping("chameleon/playlist/wpl"); // May throw Exception. serializer.getUnmarshaller().setIgnoreExtraElements(false); // Force an error if unknown elements are found. final StringReader reader = new StringReader(str); final SpecificPlaylist ret = (SpecificPlaylist) serializer.unmarshal(reader); // May throw Exception. ret.setProvider(this); return ret; }
/** * Unmarshalls an object from an input file, according to the underlying mapping. * @param file an XML file. * @throws MappingException an exception indicating an invalid mapping error. * @throws FileNotFoundException if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading. * @throws SecurityException if a security manager exists and its <code>checkRead</code> method denies read access to the file. * @throws org.exolab.castor.xml.MarshalException when there is an error during the unmarshalling process. * @throws org.exolab.castor.xml.ValidationException when there is a validation error. * @throws NullPointerException if <code>file</code> is <code>null</code>. * @see #unmarshal(InputStream) * @see Mapping */ public Object unmarshal(final File file) throws Exception { return unmarshal(new FileInputStream(file)); // Throws NullPointerException if file is null. May throw MappingException, MarshalException, ValidationException, FileNotFoundException, SecurityException. }
@Override public void writeTo(final OutputStream out, final String encoding) throws Exception { // Marshal the playlist. final StringWriter writer = new StringWriter(); final XmlSerializer serializer = XmlSerializer.getMapping("chameleon/playlist/xspf"); // May throw Exception. // Specifies whether XML documents (as generated at marshalling) should use indentation or not. Default is false. serializer.getMarshaller().setProperty("org.exolab.castor.indent", "true"); serializer.marshal(this, writer, false); // May throw Exception. String enc = encoding; if (enc == null) { enc = "UTF-8"; } final byte[] bytes = writer.toString().getBytes(enc); // May throw UnsupportedEncodingException. out.write(bytes); // Throws NullPointerException if out is null. May throw IOException. out.flush(); // May throw IOException. }
@Override public SpecificPlaylist readFrom(final InputStream in, final String encoding, final Log logger) throws Exception { String enc = encoding; if (enc == null) { enc = "UTF-8"; } String str = IOUtils.toString(in, enc); // May throw IOException. Throws NullPointerException if in is null. // Replace all occurrences of a single '&' with "&" (or leave this construct as is). // First replace blindly all '&' to its corresponding character reference. str = str.replace("&", "&"); // Then restore any existing character reference. str = str.replaceAll("&([a-zA-Z0-9#]+;)", "&$1"); // Shall not throw PatternSyntaxException. // Unmarshal the SMIL playlist. final XmlSerializer serializer = XmlSerializer.getMapping("chameleon/playlist/smil"); // May throw Exception. serializer.getUnmarshaller().setIgnoreExtraElements(true); // Many SMIL elements are not implemented yet. final StringReader reader = new StringReader(str); final SpecificPlaylist ret = (SpecificPlaylist) serializer.unmarshal(reader); // May throw Exception. ret.setProvider(this); return ret; }
/** * Unmarshalls an object from an input file, according to the underlying mapping. * @param fileName an XML file name. Shall not be <code>null</code>. * @throws MappingException an exception indicating an invalid mapping error. * @throws FileNotFoundException if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading. * @throws SecurityException if a security manager exists and its <code>checkRead</code> method denies read access to the file. * @throws org.exolab.castor.xml.MarshalException when there is an error during the unmarshalling process. * @throws org.exolab.castor.xml.ValidationException when there is a validation error. * @throws NullPointerException if <code>fileName</code> is <code>null</code>. * @see #unmarshal(InputStream) * @see Mapping */ public Object unmarshal(final String fileName) throws Exception { return unmarshal(new FileInputStream(fileName)); // Throws NullPointerException if fileName is null. May throw MappingException, MarshalException, ValidationException, FileNotFoundException, SecurityException. }
@Override public void writeTo(final OutputStream out, final String encoding) throws Exception { // Marshal the ASX playlist. final StringWriter writer = new StringWriter(); final XmlSerializer serializer = XmlSerializer.getMapping("chameleon/playlist/asx"); // May throw Exception. // Specifies whether XML documents (as generated at marshalling) should use indentation or not. Default is false. serializer.getMarshaller().setProperty("org.exolab.castor.indent", "true"); serializer.marshal(this, writer, false); // May throw Exception. String enc = encoding; if (enc == null) { enc = "UTF-8"; // FIXME US-ASCII? } final byte[] bytes = writer.toString().getBytes(enc); // May throw UnsupportedEncodingException. out.write(bytes); // Throws NullPointerException if out is null. May throw IOException. out.flush(); // May throw IOException. }
@Override public SpecificPlaylist readFrom(final InputStream in, final String encoding, final Log logger) throws Exception { String enc = encoding; if (enc == null) { enc = "UTF-8"; } String str = IOUtils.toString(in, enc); // May throw IOException. Throws NullPointerException if in is null. // Replace all occurrences of a single '&' with "&" (or leave this construct as is). // First replace blindly all '&' to its corresponding character reference. str = str.replace("&", "&"); // Then restore any existing character reference. str = str.replaceAll("&([a-zA-Z0-9#]+;)", "&$1"); // Shall not throw PatternSyntaxException. // Unmarshal the WPL playlist. final XmlSerializer serializer = XmlSerializer.getMapping( "chameleon/playlist/hypetape"); // May throw Exception. serializer.getUnmarshaller().setIgnoreExtraElements(false); final StringReader reader = new StringReader(str); final SpecificPlaylist ret = (SpecificPlaylist) serializer.unmarshal(reader); // May throw Exception. ret.setProvider(this); return ret; }
@Override public void writeTo(final OutputStream out, final String encoding) throws Exception { // Marshal the B4S playlist. final StringWriter writer = new StringWriter(); final XmlSerializer serializer = XmlSerializer.getMapping("chameleon/playlist/b4s"); // May throw Exception. // Specifies whether XML documents (as generated at marshalling) should use indentation or not. Default is false. serializer.getMarshaller().setProperty("org.exolab.castor.indent", "true"); serializer.marshal(this, writer, false); // May throw Exception. String enc = encoding; if (enc == null) { enc = "UTF-8"; } final byte[] bytes = writer.toString().getBytes(enc); // May throw UnsupportedEncodingException. out.write(bytes); // Throws NullPointerException if out is null. May throw IOException. out.flush(); // May throw IOException. }
@Override public SpecificPlaylist readFrom(final InputStream in, final String encoding, final Log logger) throws Exception { String enc = encoding; if (enc == null) { enc = "UTF-8"; } String str = IOUtils.toString(in, enc); // May throw IOException. Throws NullPointerException if in is null. // Replace all occurrences of a single '&' with "&" (or leave this construct as is). // First replace blindly all '&' to its corresponding character reference. str = str.replace("&", "&"); // Then restore any existing character reference. str = str.replaceAll("&([a-zA-Z0-9#]+;)", "&$1"); // Shall not throw PatternSyntaxException. // Workaround Castor bug 2521: str = str.replace("xmlns=\"http://www.w3.org/2005/Atom\"", ""); // Unmarshal the SMIL playlist. final XmlSerializer serializer = XmlSerializer.getMapping("chameleon/atom"); // May throw Exception. serializer.getUnmarshaller().setIgnoreExtraElements(true); final StringReader reader = new StringReader(str); // TODO Allow also an Entry. final Feed feed = (Feed) serializer.unmarshal(reader); // May throw Exception. final AtomPlaylist ret = new AtomPlaylist(); ret.setProvider(this); ret.setFeed(feed); return ret; }
@Override public void writeTo(final OutputStream out, final String encoding) throws Exception { // Marshal the SMIL playlist. final StringWriter writer = new StringWriter(); final XmlSerializer serializer = XmlSerializer.getMapping("chameleon/playlist/smil"); // May throw Exception. // Specifies whether XML documents (as generated at marshalling) should use indentation or not. Default is false. serializer.getMarshaller().setProperty("org.exolab.castor.indent", "true"); serializer.marshal(this, writer, false); // May throw Exception. String enc = encoding; if (enc == null) { enc = "UTF-8"; } final byte[] bytes = writer.toString().getBytes(enc); // May throw UnsupportedEncodingException. out.write(bytes); // Throws NullPointerException if out is null. May throw IOException. out.flush(); // May throw IOException. }
@Override public SpecificPlaylist readFrom(final InputStream in, final String encoding, final Log logger) throws Exception { String enc = encoding; if (enc == null) { enc = "UTF-8"; } String str = IOUtils.toString(in, enc); // May throw IOException. Throws NullPointerException if in is null. // Replace all occurrences of a single '&' with "&" (or leave this construct as is). // First replace blindly all '&' to its corresponding character reference. str = str.replace("&", "&"); // Then restore any existing character reference. str = str.replaceAll("&([a-zA-Z0-9#]+;)", "&$1"); // Shall not throw PatternSyntaxException. // Unmarshal the playlist. final XmlSerializer serializer = XmlSerializer.getMapping("chameleon/plist"); // May throw Exception. serializer.getUnmarshaller().setIgnoreExtraElements(false); // Force an error if unknown elements are found. final StringReader reader = new StringReader(str); final Plist plist = (Plist) serializer.unmarshal(reader); // May throw Exception. final PlistPlaylist ret = new PlistPlaylist(); ret.setProvider(this); ret.setPlist(plist); return ret; }
@Override public void writeTo(final OutputStream out, final String encoding) throws Exception { // Marshal the playlist. final StringWriter writer = new StringWriter(); final XmlSerializer serializer = XmlSerializer.getMapping( "chameleon/playlist/hypetape"); // May throw Exception. // Specifies whether XML documents (as generated at marshalling) should use indentation or not. Default is false. serializer.getMarshaller().setProperty("org.exolab.castor.indent", "true"); serializer.marshal(this, writer, false); // May throw Exception. String enc = encoding; if (enc == null) { enc = "UTF-8"; } final byte[] bytes = writer.toString().getBytes(enc); // May throw UnsupportedEncodingException. out.write(bytes); // Throws NullPointerException if out is null. May throw IOException. out.flush(); // May throw IOException. }
@Override public SpecificPlaylist readFrom(final InputStream in, final String encoding, final Log logger) throws Exception { String enc = encoding; if (enc == null) { enc = "UTF-8"; } String str = IOUtils.toString(in, enc); // May throw IOException. Throws NullPointerException if in is null. // Replace all occurrences of a single '&' with "&" (or leave this construct as is). // First replace blindly all '&' to its corresponding character reference. str = str.replace("&", "&"); // Then restore any existing character reference. str = str.replaceAll("&([a-zA-Z0-9#]+;)", "&$1"); // Shall not throw PatternSyntaxException. // Unmarshal the SMIL playlist. final XmlSerializer serializer = XmlSerializer.getMapping("chameleon/rss"); // May throw Exception. serializer.getUnmarshaller().setIgnoreExtraElements(true); final StringReader reader = new StringReader(str); final RSS rss = (RSS) serializer.unmarshal(reader); // May throw Exception. final RSSPlaylist ret = new RSSPlaylist(); ret.setProvider(this); ret.setRSS(rss); return ret; }