From c447eda87bd41e1fd0ee22a9df47ddfe864a48f6 Mon Sep 17 00:00:00 2001 From: Patrick Gotthard Date: Sat, 20 Feb 2016 18:35:57 +0100 Subject: [PATCH] #244 Update iTunes module --- .../modules/itunes/AbstractITunesObject.java | 541 +++++++++--------- .../modules/itunes/EntryInformation.java | 161 +++--- .../modules/itunes/EntryInformationImpl.java | 355 ++++++------ .../modules/itunes/FeedInformation.java | 20 +- .../modules/itunes/FeedInformationImpl.java | 455 ++++++++------- .../com/rometools/modules/itunes/ITunes.java | 307 +++++----- .../modules/itunes/io/ITunesGenerator.java | 416 +++++++------- .../modules/itunes/io/ITunesParser.java | 487 ++++++++-------- .../itunes/io/ITunesParserOldNamespace.java | 5 +- .../modules/itunes/ITunesParserTest.java | 365 ++++++++---- .../src/test/resources/xml/leshow.xml | 272 +++------ 11 files changed, 1719 insertions(+), 1665 deletions(-) diff --git a/rome-modules/src/main/java/com/rometools/modules/itunes/AbstractITunesObject.java b/rome-modules/src/main/java/com/rometools/modules/itunes/AbstractITunesObject.java index 948d47e..691d32c 100644 --- a/rome-modules/src/main/java/com/rometools/modules/itunes/AbstractITunesObject.java +++ b/rome-modules/src/main/java/com/rometools/modules/itunes/AbstractITunesObject.java @@ -1,273 +1,268 @@ -/* - * AbstractITunesObject.java - * - * Created on August 1, 2005, 7:37 PM - * - * This library is provided under dual licenses. - * You may choose the terms of the Lesser General Public License or the Apache - * License at your discretion. - * - * Copyright (C) 2005 Robert Cooper, Temple of the Screaming Penguin - * - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package com.rometools.modules.itunes; - -import java.net.URL; - -/** - * This is an abstract object that implements the attributes common across Feeds or Items in an - * iTunes compatible RSS feed. - * - * @version $Revision: 1.4 $ - * @author Robert "kebernet" Cooper - */ -public abstract class AbstractITunesObject implements ITunes, java.lang.Cloneable { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * The URI that iTunes used for its custom tags. - *

- * What is up with using a versioned DTD anyway? - *

- * \ - */ - public static final String URI = "http://www.itunes.com/dtds/podcast-1.0.dtd"; - - /** - * The RDF namespace URI. - */ - public static final String RDF_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; - - /** - * A default prefix to use for itunes tags. - */ - public static final String PREFIX = "itunes"; - private String author; - private boolean block; - private boolean explicit; - private URL image; - private String[] keywords; - private String subtitle; - private String summary; - - /** - * Defined by the ROME API - * - * @return Class of the Interface for this module. - */ - @Override - public Class getInterface() { - return getClass(); - } - - /** - * The URI this module implements - * - * @return "http://www.itunes.com/dtds/podcast-1.0.dtd" - */ - @Override - public String getUri() { - return AbstractITunesObject.URI; - } - - /** - * Required by the ROME API - * - * @return A clone of this module object - */ - @Override - public abstract Object clone(); - - /** - * Returns the author string for this feed or entry - * - * @return Returns the author string for this feed or entry - */ - @Override - public String getAuthor() { - return author; - } - - /** - * Sets the author string for this feed or entry - * - * @param author Sets the author string for this feed or entry - */ - @Override - public void setAuthor(final String author) { - this.author = author; - } - - /** - * Boolean as to whether to block this feed or entry - * - * @return Boolean as to whether to block this feed or entry - */ - @Override - public boolean getBlock() { - return block; - } - - /** - * Boolean as to whether to block this feed or entry - * - * @param block Boolean as to whether to block this feed or entry - */ - @Override - public void setBlock(final boolean block) { - this.block = block; - } - - /** - * Boolean as to whether this feed or entry contains adult content - * - * @return Boolean as to whether this feed or entry contains adult content - */ - @Override - public boolean getExplicit() { - return explicit; - } - - /** - * Boolean as to whether this feed or entry contains adult content - * - * @param explicit Boolean as to whether this feed or entry contains adult content - */ - @Override - public void setExplicit(final boolean explicit) { - this.explicit = explicit; - } - - @Override - public URL getImage() { - return image; - } - - @Override - public void setImage(final URL image) { - this.image = image; - } - - /** - * A list of keywords for this feed or entry - * - * Must not contain spaces - * - * @return A list of keywords for this feed or entry - */ - @Override - public String[] getKeywords() { - return keywords == null ? new String[0] : keywords; - } - - /** - * A list of keywords for this feed or entry - * - * Must not contain spaces - * - * @param keywords A list of keywords for this feed or enty - */ - @Override - public void setKeywords(final String[] keywords) { - this.keywords = keywords; - } - - /** - * A subtitle for this feed or entry - * - * @return A subtitle for this feed or entry - */ - @Override - public String getSubtitle() { - return subtitle; - } - - /** - * A subtitle for this feed or entry - * - * @param subtitle A subtitle for this feed or entry - */ - @Override - public void setSubtitle(final String subtitle) { - this.subtitle = subtitle; - } - - /** - * A subtitle for this feed or entry - * - * @return A subtitle for this feed or entry - */ - @Override - public String getSummary() { - return summary; - } - - /** - * A subtitle for this feed or entry - * - * @param summary A subtitle for this feed or entry - */ - @Override - public void setSummary(final String summary) { - this.summary = summary; - } - - @Override - public String toString() { - final StringBuffer sb = new StringBuffer("["); - sb.append(" Author: "); - sb.append(getAuthor()); - sb.append(" Block: "); - sb.append(getBlock()); - sb.append(" Explicit: "); - sb.append(getExplicit()); - sb.append(" Image: "); - sb.append(getImage()); - sb.append(" Keywords: "); - - if (getKeywords() != null) { - for (int i = 0; i < keywords.length; i++) { - sb.append("'" + getKeywords()[i] + "'"); - } - } - - sb.append(" Subtitle: "); - sb.append(getSubtitle()); - sb.append(" Summary: "); - sb.append(getSummary()); - sb.append("]"); - - return sb.toString(); - } -} +/* + * AbstractITunesObject.java + * + * Created on August 1, 2005, 7:37 PM + * + * This library is provided under dual licenses. + * You may choose the terms of the Lesser General Public License or the Apache + * License at your discretion. + * + * Copyright (C) 2005 Robert Cooper, Temple of the Screaming Penguin + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.rometools.modules.itunes; + +import java.net.URL; +import java.util.Arrays; + +/** + * This is an abstract object that implements the attributes common across Feeds or Items in an + * iTunes compatible RSS feed. + * + * @version $Revision: 1.4 $ + * @author Robert "kebernet" Cooper + */ +public abstract class AbstractITunesObject implements ITunes, java.lang.Cloneable { + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * The URI that iTunes used for its custom tags. + *

+ * What is up with using a versioned DTD anyway? + *

+ * \ + */ + public static final String URI = "http://www.itunes.com/dtds/podcast-1.0.dtd"; + + /** + * The RDF namespace URI. + */ + public static final String RDF_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; + + /** + * A default prefix to use for itunes tags. + */ + public static final String PREFIX = "itunes"; + private String author; + private boolean block; + private Explicit explicit; + private URL image; + private String[] keywords; + private String subtitle; + private String summary; + + /** + * Defined by the ROME API + * + * @return Class of the Interface for this module. + */ + @Override + public Class getInterface() { + return getClass(); + } + + /** + * The URI this module implements + * + * @return "http://www.itunes.com/dtds/podcast-1.0.dtd" + */ + @Override + public String getUri() { + return AbstractITunesObject.URI; + } + + /** + * Required by the ROME API + * + * @return A clone of this module object + */ + @Override + public abstract Object clone(); + + /** + * Returns the author string for this feed or entry + * + * @return Returns the author string for this feed or entry + */ + @Override + public String getAuthor() { + return author; + } + + /** + * Sets the author string for this feed or entry + * + * @param author Sets the author string for this feed or entry + */ + @Override + public void setAuthor(final String author) { + this.author = author; + } + + /** + * Boolean as to whether to block this feed or entry + * + * @return Boolean as to whether to block this feed or entry + */ + @Override + public boolean getBlock() { + return block; + } + + /** + * Boolean as to whether to block this feed or entry + * + * @param block Boolean as to whether to block this feed or entry + */ + @Override + public void setBlock(final boolean block) { + this.block = block; + } + + /** + * Boolean as to whether this feed or entry contains adult content + * + * @return Boolean as to whether this feed or entry contains adult content + */ + @Override + public Explicit getExplicit() { + return explicit; + } + + /** + * Boolean as to whether this feed or entry contains adult content + * + * @param explicit Boolean as to whether this feed or entry contains adult content + */ + @Override + public void setExplicit(final Explicit explicit) { + this.explicit = explicit; + } + + @Override + public URL getImage() { + return image; + } + + @Override + public void setImage(final URL image) { + this.image = image; + } + + /** + * A list of keywords for this feed or entry + * + * Must not contain spaces + * + * @return A list of keywords for this feed or entry + */ + @Override + public String[] getKeywords() { + return keywords == null ? new String[0] : keywords; + } + + /** + * A list of keywords for this feed or entry + * + * Must not contain spaces + * + * @param keywords A list of keywords for this feed or enty + */ + @Override + public void setKeywords(final String[] keywords) { + this.keywords = keywords; + } + + /** + * A subtitle for this feed or entry + * + * @return A subtitle for this feed or entry + */ + @Override + public String getSubtitle() { + return subtitle; + } + + /** + * A subtitle for this feed or entry + * + * @param subtitle A subtitle for this feed or entry + */ + @Override + public void setSubtitle(final String subtitle) { + this.subtitle = subtitle; + } + + /** + * A subtitle for this feed or entry + * + * @return A subtitle for this feed or entry + */ + @Override + public String getSummary() { + return summary; + } + + /** + * A subtitle for this feed or entry + * + * @param summary A subtitle for this feed or entry + */ + @Override + public void setSummary(final String summary) { + this.summary = summary; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("AbstractITunesObject [author="); + builder.append(author); + builder.append(", block="); + builder.append(block); + builder.append(", explicit="); + builder.append(explicit); + builder.append(", image="); + builder.append(image); + builder.append(", keywords="); + builder.append(Arrays.toString(keywords)); + builder.append(", subtitle="); + builder.append(subtitle); + builder.append(", summary="); + builder.append(summary); + builder.append("]"); + return builder.toString(); + } + +} \ No newline at end of file diff --git a/rome-modules/src/main/java/com/rometools/modules/itunes/EntryInformation.java b/rome-modules/src/main/java/com/rometools/modules/itunes/EntryInformation.java index 4710a1e..7b94c55 100644 --- a/rome-modules/src/main/java/com/rometools/modules/itunes/EntryInformation.java +++ b/rome-modules/src/main/java/com/rometools/modules/itunes/EntryInformation.java @@ -1,76 +1,85 @@ -/* - * EntryInformation.java - * - * Created on November 19, 2005, 10:56 PM - * - * This library is provided under dual licenses. - * You may choose the terms of the Lesser General Public License or the Apache - * License at your discretion. - * - * Copyright (C) 2005 Robert Cooper, Temple of the Screaming Penguin - * - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package com.rometools.modules.itunes; - -import com.rometools.modules.itunes.types.Duration; - -/** - * This class contains information for iTunes podcast feeds that exist at the Item level. - * - * @author Robert "kebernet" Cooper - * @version $Revision: 1.2 $ - * - */ -public interface EntryInformation extends ITunes { - - /** - * Returns the Duration object for this Item - * - * @return Returns the Duration object for this Item - */ - public Duration getDuration(); - - /** - * Sets the Duration object for this Item - * - * @param duration Sets the Duration object for this Item - */ - public void setDuration(Duration duration); - - public boolean getClosedCaptioned(); - - public void setClosedCaptioned(boolean closedCaptioned); - - public Integer getOrder(); - - public void setOrder(Integer order); -} +/* + * EntryInformation.java + * + * Created on November 19, 2005, 10:56 PM + * + * This library is provided under dual licenses. + * You may choose the terms of the Lesser General Public License or the Apache + * License at your discretion. + * + * Copyright (C) 2005 Robert Cooper, Temple of the Screaming Penguin + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.rometools.modules.itunes; + +import com.rometools.modules.itunes.types.Duration; + +/** + * This class contains information for iTunes podcast feeds that exist at the Item level. + * + * @author Robert "kebernet" Cooper + * @version $Revision: 1.2 $ + * + */ +public interface EntryInformation extends ITunes { + + /** + * marker for closed captioning support on video. + * + * @see http://www.apple.com/itunes/podcasts/specs.html#isClosedCaptioned + */ + enum ClosedCaptioned { + yes, no + } + + /** + * Returns the Duration object for this Item + * + * @return Returns the Duration object for this Item + */ + public Duration getDuration(); + + /** + * Sets the Duration object for this Item + * + * @param duration Sets the Duration object for this Item + */ + public void setDuration(Duration duration); + + public ClosedCaptioned getClosedCaptioned(); + + public void setClosedCaptioned(ClosedCaptioned closedCaptioned); + + public Integer getOrder(); + + public void setOrder(Integer order); +} diff --git a/rome-modules/src/main/java/com/rometools/modules/itunes/EntryInformationImpl.java b/rome-modules/src/main/java/com/rometools/modules/itunes/EntryInformationImpl.java index b85449b..33dde8a 100644 --- a/rome-modules/src/main/java/com/rometools/modules/itunes/EntryInformationImpl.java +++ b/rome-modules/src/main/java/com/rometools/modules/itunes/EntryInformationImpl.java @@ -1,178 +1,177 @@ -/* - * EntryInformation.java - * - * Created on August 1, 2005, 7:37 PM - * - * This library is provided under dual licenses. - * You may choose the terms of the Lesser General Public License or the Apache - * License at your discretion. - * - * Copyright (C) 2005 Robert Cooper, Temple of the Screaming Penguin - * - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package com.rometools.modules.itunes; - -import com.rometools.modules.itunes.types.Duration; -import com.rometools.rome.feed.CopyFrom; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.net.MalformedURLException; -import java.net.URL; - -/** - * This class contains information for iTunes podcast feeds that exist at the Item level. - * - * @version $Revision: 1.2 $ - * @author Robert "kebernet" Cooper - */ -public class EntryInformationImpl extends AbstractITunesObject implements EntryInformation { - /** - * - */ - private static final long serialVersionUID = 1L; - - private static final Logger LOG = LoggerFactory.getLogger(EntryInformationImpl.class); - - private Duration duration; - private boolean closedCaptioned; - private Integer order; - - /** - * Creates a new instance of EntryInformationImpl - */ - public EntryInformationImpl() { - } - - /** - * Returns the Duration object for this Item - * - * @return Returns the Duration object for this Item - */ - @Override - public Duration getDuration() { - return duration; - } - - /** - * Sets the Duration object for this Item - * - * @param duration Sets the Duration object for this Item - */ - @Override - public void setDuration(final Duration duration) { - this.duration = duration; - } - - @Override - public boolean getClosedCaptioned() { - return closedCaptioned; - } - - @Override - public void setClosedCaptioned(boolean closedCaptioned) { - this.closedCaptioned = closedCaptioned; - } - - @Override - public Integer getOrder() { - return order; - } - - @Override - public void setOrder(Integer order) { - this.order = order; - } - - /** - * Defined by the ROME module API - * - * @param obj Object to copy from - */ - @Override - public void copyFrom(final CopyFrom obj) { - final EntryInformationImpl info = (EntryInformationImpl) obj; - setAuthor(info.getAuthor()); - setBlock(info.getBlock()); - - if (info.getDuration() != null) { - setDuration(new Duration(info.getDuration().getMilliseconds())); - } - - setExplicit(info.getExplicit()); - - try { - if (info.getImage() != null) { - setImage(new URL(info.getImage().toExternalForm())); - } - } catch (final MalformedURLException e) { - LOG.debug("Error copying URL:" + info.getImage(), e); - } - - if (info.getKeywords() != null) { - setKeywords(info.getKeywords().clone()); - } - - setSubtitle(info.getSubtitle()); - setSummary(info.getSummary()); - setClosedCaptioned(info.getClosedCaptioned()); - setOrder(info.getOrder()); - } - - /** - * Required by the ROME API - * - * @return A clone of this module object - */ - @Override - public Object clone() { - final EntryInformationImpl info = new EntryInformationImpl(); - info.copyFrom(this); - - return info; - } - - @Override - public String toString() { - final StringBuffer sb = new StringBuffer("["); - sb.append(" duration: "); - sb.append(getDuration()); - sb.append(" closedCaptioned: "); - sb.append(getClosedCaptioned()); - sb.append(" order: "); - sb.append(getOrder()); - sb.append("]"); - sb.append(super.toString()); - - return sb.toString(); - } -} +/* + * EntryInformation.java + * + * Created on August 1, 2005, 7:37 PM + * + * This library is provided under dual licenses. + * You may choose the terms of the Lesser General Public License or the Apache + * License at your discretion. + * + * Copyright (C) 2005 Robert Cooper, Temple of the Screaming Penguin + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.rometools.modules.itunes; + +import java.net.MalformedURLException; +import java.net.URL; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.rometools.modules.itunes.types.Duration; +import com.rometools.rome.feed.CopyFrom; + +/** + * This class contains information for iTunes podcast feeds that exist at the Item level. + * + * @version $Revision: 1.2 $ + * @author Robert "kebernet" Cooper + */ +public class EntryInformationImpl extends AbstractITunesObject implements EntryInformation { + /** + * + */ + private static final long serialVersionUID = 1L; + + private static final Logger LOG = LoggerFactory.getLogger(EntryInformationImpl.class); + + private Duration duration; + private ClosedCaptioned closedCaptioned; + private Integer order; + + /** + * Creates a new instance of EntryInformationImpl + */ + public EntryInformationImpl() { + } + + /** + * Returns the Duration object for this Item + * + * @return Returns the Duration object for this Item + */ + @Override + public Duration getDuration() { + return duration; + } + + /** + * Sets the Duration object for this Item + * + * @param duration Sets the Duration object for this Item + */ + @Override + public void setDuration(final Duration duration) { + this.duration = duration; + } + + @Override + public ClosedCaptioned getClosedCaptioned() { + return closedCaptioned; + } + + @Override + public void setClosedCaptioned(final ClosedCaptioned closedCaptioned) { + this.closedCaptioned = closedCaptioned; + } + + @Override + public Integer getOrder() { + return order; + } + + @Override + public void setOrder(final Integer order) { + this.order = order; + } + + /** + * Defined by the ROME module API + * + * @param obj Object to copy from + */ + @Override + public void copyFrom(final CopyFrom obj) { + final EntryInformationImpl info = (EntryInformationImpl) obj; + setAuthor(info.getAuthor()); + setBlock(info.getBlock()); + + if (info.getDuration() != null) { + setDuration(new Duration(info.getDuration().getMilliseconds())); + } + + setExplicit(info.getExplicit()); + + try { + if (info.getImage() != null) { + setImage(new URL(info.getImage().toExternalForm())); + } + } catch (final MalformedURLException e) { + LOG.debug("Error copying URL:" + info.getImage(), e); + } + + if (info.getKeywords() != null) { + setKeywords(info.getKeywords().clone()); + } + + setSubtitle(info.getSubtitle()); + setSummary(info.getSummary()); + setClosedCaptioned(info.getClosedCaptioned()); + setOrder(info.getOrder()); + } + + /** + * Required by the ROME API + * + * @return A clone of this module object + */ + @Override + public Object clone() { + final EntryInformationImpl info = new EntryInformationImpl(); + info.copyFrom(this); + + return info; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("EntryInformationImpl [duration="); + builder.append(duration); + builder.append(", closedCaptioned="); + builder.append(closedCaptioned); + builder.append(", order="); + builder.append(order); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/rome-modules/src/main/java/com/rometools/modules/itunes/FeedInformation.java b/rome-modules/src/main/java/com/rometools/modules/itunes/FeedInformation.java index 9f2965d..a443c9f 100644 --- a/rome-modules/src/main/java/com/rometools/modules/itunes/FeedInformation.java +++ b/rome-modules/src/main/java/com/rometools/modules/itunes/FeedInformation.java @@ -55,50 +55,50 @@ public interface FeedInformation extends ITunes { /** * The parent categories for this feed - * + * * @return The parent categories for this feed */ public List getCategories(); /** * The parent categories for this feed - * + * * @param categories The parent categories for this feed */ public void setCategories(List categories); - public boolean getComplete(); + public Boolean getComplete(); - public void setComplete(boolean complete); + public void setComplete(Boolean complete); - public String getNewFeedUrl(); + public URL getNewFeedUrl(); - public void setNewFeedUrl(String newFeedUrl); + public void setNewFeedUrl(URL newFeedUrl); /** * Sets the owner email address for the feed. - * + * * @param ownerEmailAddress Sets the owner email address for the feed. */ public void setOwnerEmailAddress(String ownerEmailAddress); /** * Returns the owner email address for the feed. - * + * * @return Returns the owner email address for the feed. */ public String getOwnerEmailAddress(); /** * Sets the owner name for the feed - * + * * @param ownerName Sets the owner name for the feed */ public void setOwnerName(String ownerName); /** * Returns the owner name for the feed - * + * * @return Returns the owner name for the feed */ public String getOwnerName(); diff --git a/rome-modules/src/main/java/com/rometools/modules/itunes/FeedInformationImpl.java b/rome-modules/src/main/java/com/rometools/modules/itunes/FeedInformationImpl.java index 07f584f..d4c8f2d 100644 --- a/rome-modules/src/main/java/com/rometools/modules/itunes/FeedInformationImpl.java +++ b/rome-modules/src/main/java/com/rometools/modules/itunes/FeedInformationImpl.java @@ -1,228 +1,227 @@ -/* - * FeedInformation.java - * - * Created on August 1, 2005, 7:11 PM - * - * - * This library is provided under dual licenses. - * You may choose the terms of the Lesser General Public License or the Apache - * License at your discretion. - * - * Copyright (C) 2005 Robert Cooper, Temple of the Screaming Penguin - * - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package com.rometools.modules.itunes; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.rometools.modules.itunes.types.Category; -import com.rometools.rome.feed.CopyFrom; - -/** - * This class contains information for iTunes podcast feeds that exist at the Channel level. - * - * @version $Revision: 1.2 $ - * @author Robert "kebernet" Cooper - */ -public class FeedInformationImpl extends AbstractITunesObject implements FeedInformation { - - private static final long serialVersionUID = 1L; - - private static final Logger LOG = LoggerFactory.getLogger(FeedInformationImpl.class); - - private String ownerName; - private String ownerEmailAddress; - private List categories; - private boolean complete; - private String newFeedUrl; - - /** - * Creates a new instance of FeedInformationImpl - */ - public FeedInformationImpl() { - } - - /** - * The parent categories for this feed - * - * @return The parent categories for this feed - */ - @Override - public List getCategories() { - return categories == null ? (categories = new ArrayList()) : categories; - } - - /** - * The parent categories for this feed - * - * @param categories The parent categories for this feed - */ - @Override - public void setCategories(final List categories) { - this.categories = categories; - } - - @Override - public boolean getComplete() { - return complete; - } - - @Override - public void setComplete(boolean complete) { - this.complete = complete; - } - - @Override - public String getNewFeedUrl() { - return newFeedUrl; - } - - @Override - public void setNewFeedUrl(String newFeedUrl) { - this.newFeedUrl = newFeedUrl; - } - - /** - * Returns the owner name for the feed - * - * @return Returns the owner name for the feed - */ - @Override - public String getOwnerName() { - return ownerName; - } - - /** - * Sets the owner name for the feed - * - * @param ownerName Sets the owner name for the feed - */ - @Override - public void setOwnerName(final String ownerName) { - this.ownerName = ownerName; - } - - /** - * Returns the owner email address for the feed. - * - * @return Returns the owner email address for the feed. - */ - @Override - public String getOwnerEmailAddress() { - return ownerEmailAddress; - } - - /** - * Sets the owner email address for the feed. - * - * @param ownerEmailAddress Sets the owner email address for the feed. - */ - @Override - public void setOwnerEmailAddress(final String ownerEmailAddress) { - this.ownerEmailAddress = ownerEmailAddress; - } - - /** - * Required by the ROME API - * - * @param obj object to copy property values from - */ - @Override - public void copyFrom(final CopyFrom obj) { - final FeedInformationImpl info = (FeedInformationImpl) obj; - setAuthor(info.getAuthor()); - setBlock(info.getBlock()); - - getCategories().clear(); - if (info.getCategories() != null) { - getCategories().addAll(info.getCategories()); - } - - setComplete(info.getComplete()); - setNewFeedUrl(info.getNewFeedUrl()); - setExplicit(info.getExplicit()); - - try { - if (info.getImage() != null) { - setImage(new URL(info.getImage().toExternalForm())); - } - } catch (final MalformedURLException e) { - LOG.debug("Error copying URL:" + info.getImage(), e); - } - - if (info.getKeywords() != null) { - setKeywords(info.getKeywords().clone()); - } - - setOwnerEmailAddress(info.getOwnerEmailAddress()); - setOwnerName(info.getOwnerName()); - setSubtitle(info.getSubtitle()); - setSummary(info.getSummary()); - } - - /** - * Returns a copy of this FeedInformationImpl object - * - * @return Returns a copy of this FeedInformationImpl object - */ - @Override - public Object clone() { - final FeedInformationImpl info = new FeedInformationImpl(); - info.copyFrom(this); - - return info; - } - - @Override - public String toString() { - final StringBuffer sb = new StringBuffer("["); - sb.append(" email: "); - sb.append(getOwnerEmailAddress()); - sb.append(" name: "); - sb.append(getOwnerName()); - sb.append(" categories: "); - sb.append(getCategories()); - sb.append(" complete: "); - sb.append(getComplete()); - sb.append(" newFeedUrl: "); - sb.append(getNewFeedUrl()); - sb.append("]"); - sb.append(super.toString()); - - return sb.toString(); - } -} +/* + * FeedInformation.java + * + * Created on August 1, 2005, 7:11 PM + * + * + * This library is provided under dual licenses. + * You may choose the terms of the Lesser General Public License or the Apache + * License at your discretion. + * + * Copyright (C) 2005 Robert Cooper, Temple of the Screaming Penguin + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.rometools.modules.itunes; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.rometools.modules.itunes.types.Category; +import com.rometools.rome.feed.CopyFrom; + +/** + * This class contains information for iTunes podcast feeds that exist at the Channel level. + * + * @version $Revision: 1.2 $ + * @author Robert "kebernet" Cooper + */ +public class FeedInformationImpl extends AbstractITunesObject implements FeedInformation { + + private static final long serialVersionUID = 1L; + + private static final Logger LOG = LoggerFactory.getLogger(FeedInformationImpl.class); + + private String ownerName; + private String ownerEmailAddress; + private List categories; + private Boolean complete; + private URL newFeedUrl; + + /** + * Creates a new instance of FeedInformationImpl + */ + public FeedInformationImpl() { + } + + /** + * The parent categories for this feed + * + * @return The parent categories for this feed + */ + @Override + public List getCategories() { + return categories == null ? (categories = new ArrayList()) : categories; + } + + /** + * The parent categories for this feed + * + * @param categories The parent categories for this feed + */ + @Override + public void setCategories(final List categories) { + this.categories = categories; + } + + @Override + public Boolean getComplete() { + return complete; + } + + @Override + public void setComplete(final Boolean complete) { + this.complete = complete; + } + + @Override + public URL getNewFeedUrl() { + return newFeedUrl; + } + + @Override + public void setNewFeedUrl(final URL newFeedUrl) { + this.newFeedUrl = newFeedUrl; + } + + /** + * Returns the owner name for the feed + * + * @return Returns the owner name for the feed + */ + @Override + public String getOwnerName() { + return ownerName; + } + + /** + * Sets the owner name for the feed + * + * @param ownerName Sets the owner name for the feed + */ + @Override + public void setOwnerName(final String ownerName) { + this.ownerName = ownerName; + } + + /** + * Returns the owner email address for the feed. + * + * @return Returns the owner email address for the feed. + */ + @Override + public String getOwnerEmailAddress() { + return ownerEmailAddress; + } + + /** + * Sets the owner email address for the feed. + * + * @param ownerEmailAddress Sets the owner email address for the feed. + */ + @Override + public void setOwnerEmailAddress(final String ownerEmailAddress) { + this.ownerEmailAddress = ownerEmailAddress; + } + + /** + * Required by the ROME API + * + * @param obj object to copy property values from + */ + @Override + public void copyFrom(final CopyFrom obj) { + final FeedInformationImpl info = (FeedInformationImpl) obj; + setAuthor(info.getAuthor()); + setBlock(info.getBlock()); + + getCategories().clear(); + if (info.getCategories() != null) { + getCategories().addAll(info.getCategories()); + } + + setComplete(info.getComplete()); + setNewFeedUrl(info.getNewFeedUrl()); + setExplicit(info.getExplicit()); + + try { + if (info.getImage() != null) { + setImage(new URL(info.getImage().toExternalForm())); + } + } catch (final MalformedURLException e) { + LOG.debug("Error copying URL:" + info.getImage(), e); + } + + if (info.getKeywords() != null) { + setKeywords(info.getKeywords().clone()); + } + + setOwnerEmailAddress(info.getOwnerEmailAddress()); + setOwnerName(info.getOwnerName()); + setSubtitle(info.getSubtitle()); + setSummary(info.getSummary()); + } + + /** + * Returns a copy of this FeedInformationImpl object + * + * @return Returns a copy of this FeedInformationImpl object + */ + @Override + public Object clone() { + final FeedInformationImpl info = new FeedInformationImpl(); + info.copyFrom(this); + + return info; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("FeedInformationImpl [ownerName="); + builder.append(ownerName); + builder.append(", ownerEmailAddress="); + builder.append(ownerEmailAddress); + builder.append(", categories="); + builder.append(categories); + builder.append(", complete="); + builder.append(complete); + builder.append(", newFeedUrl="); + builder.append(newFeedUrl); + builder.append("]"); + return builder.toString(); + } + +} \ No newline at end of file diff --git a/rome-modules/src/main/java/com/rometools/modules/itunes/ITunes.java b/rome-modules/src/main/java/com/rometools/modules/itunes/ITunes.java index 1451f95..0866554 100644 --- a/rome-modules/src/main/java/com/rometools/modules/itunes/ITunes.java +++ b/rome-modules/src/main/java/com/rometools/modules/itunes/ITunes.java @@ -1,149 +1,158 @@ -/* - * ITunes.java - * - * Created on November 19, 2005, 10:58 PM - * - * This library is provided under dual licenses. - * You may choose the terms of the Lesser General Public License or the Apache - * License at your discretion. - * - * Copyright (C) 2005 Robert Cooper, Temple of the Screaming Penguin - * - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.rometools.modules.itunes; - -import com.rometools.rome.feed.module.Module; - -import java.net.URL; - -/** - * This interface contains the methods common to all iTunes module points. - * - * @author Robert "kebernet" Cooper - * @version $Revision: 1.3 $ - */ -public interface ITunes extends Module { - - public static final String URI = AbstractITunesObject.URI; - - /** - * Returns the author string for this feed or entry - * - * @return Returns the author string for this feed or entry - */ - public String getAuthor(); - - /** - * Sets the author string for this feed or entry - * - * @param author Sets the author string for this feed or entry - */ - public void setAuthor(String author); - - /** - * Boolean as to whether to block this feed or entry - * - * @return Boolean as to whether to block this feed or entry - */ - public boolean getBlock(); - - /** - * Boolean as to whether to block this feed or entry - * - * @param block Boolean as to whether to block this feed or entry - */ - public void setBlock(boolean block); - - /** - * Boolean as to whether this feed or entry contains adult content - * - * @return Boolean as to whether this feed or entry contains adult content - */ - public boolean getExplicit(); - - /** - * Boolean as to whether this feed or entry contains adult content - * - * @param explicit Boolean as to whether this feed or entry contains adult content - */ - public void setExplicit(boolean explicit); - - public URL getImage(); - - public void setImage(URL image); - - /** - * A list of keywords for this feed or entry - * - * Must not contain spaces - * - * @return A list of keywords for this feed or entry - */ - public String[] getKeywords(); - - /** - * A list of keywords for this feed or entry - * - * Must not contain spaces - * - * @param keywords A list of keywords for this feed or enty - */ - public void setKeywords(String[] keywords); - - /** - * A subtitle for this feed or entry - * - * @return A subtitle for this feed or entry - */ - public String getSubtitle(); - - /** - * A subtitle for this feed or entry - * - * @param subtitle A subtitle for this feed or entry - */ - public void setSubtitle(String subtitle); - - /** - * A subtitle for this feed or entry - * - * @return A subtitle for this feed or entry - */ - public String getSummary(); - - /** - * A subtitle for this feed or entry - * - * @param summary A subtitle for this feed or entry - */ - public void setSummary(String summary); - -} +/* + * ITunes.java + * + * Created on November 19, 2005, 10:58 PM + * + * This library is provided under dual licenses. + * You may choose the terms of the Lesser General Public License or the Apache + * License at your discretion. + * + * Copyright (C) 2005 Robert Cooper, Temple of the Screaming Penguin + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.rometools.modules.itunes; + +import com.rometools.rome.feed.module.Module; + +import java.net.URL; + +/** + * This interface contains the methods common to all iTunes module points. + * + * @author Robert "kebernet" Cooper + * @version $Revision: 1.3 $ + */ +public interface ITunes extends Module { + + /** + * Marker for podcasts containing explicit material. + * + * @see http://www.apple.com/itunes/podcasts/specs.html#explicit + */ + enum Explicit { + yes, no, clean + } + + public static final String URI = AbstractITunesObject.URI; + + /** + * Returns the author string for this feed or entry + * + * @return Returns the author string for this feed or entry + */ + public String getAuthor(); + + /** + * Sets the author string for this feed or entry + * + * @param author Sets the author string for this feed or entry + */ + public void setAuthor(String author); + + /** + * Boolean as to whether to block this feed or entry + * + * @return Boolean as to whether to block this feed or entry + */ + public boolean getBlock(); + + /** + * Boolean as to whether to block this feed or entry + * + * @param block Boolean as to whether to block this feed or entry + */ + public void setBlock(boolean block); + + /** + * whether this feed or entry contains adult content or not + * + * @return explicit state as to whether this feed or entry contains adult content + */ + public Explicit getExplicit(); + + /** + * whether this feed or entry contains adult content or not + * + * @param explicit explicit state as to whether this feed or entry contains adult content + */ + public void setExplicit(Explicit explicit); + + public URL getImage(); + + public void setImage(URL image); + + /** + * A list of keywords for this feed or entry + * + * Must not contain spaces + * + * @return A list of keywords for this feed or entry + */ + public String[] getKeywords(); + + /** + * A list of keywords for this feed or entry + * + * Must not contain spaces + * + * @param keywords A list of keywords for this feed or enty + */ + public void setKeywords(String[] keywords); + + /** + * A subtitle for this feed or entry + * + * @return A subtitle for this feed or entry + */ + public String getSubtitle(); + + /** + * A subtitle for this feed or entry + * + * @param subtitle A subtitle for this feed or entry + */ + public void setSubtitle(String subtitle); + + /** + * A subtitle for this feed or entry + * + * @return A subtitle for this feed or entry + */ + public String getSummary(); + + /** + * A subtitle for this feed or entry + * + * @param summary A subtitle for this feed or entry + */ + public void setSummary(String summary); + +} diff --git a/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesGenerator.java b/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesGenerator.java index e4fc68a..1c6352a 100644 --- a/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesGenerator.java +++ b/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesGenerator.java @@ -1,207 +1,209 @@ -/* - * ITunesGenerator.java - * - * Created on August 1, 2005, 10:44 PM - * - * This library is provided under dual licenses. - * You may choose the terms of the Lesser General Public License or the Apache - * License at your discretion. - * - * Copyright (C) 2005 Robert Cooper, Temple of the Screaming Penguin - * - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package com.rometools.modules.itunes.io; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.jdom2.Element; -import org.jdom2.Namespace; - -import com.rometools.modules.itunes.AbstractITunesObject; -import com.rometools.modules.itunes.EntryInformationImpl; -import com.rometools.modules.itunes.FeedInformationImpl; -import com.rometools.modules.itunes.types.Category; -import com.rometools.rome.feed.module.Module; -import com.rometools.rome.io.ModuleGenerator; - -/** - * @version $Revision: 1.3 $ - * @author Robert "kebernet" Cooper - */ -public class ITunesGenerator implements ModuleGenerator { - - private static final HashSet NAMESPACES = new HashSet(); - private static final Namespace NAMESPACE = Namespace.getNamespace(AbstractITunesObject.PREFIX, AbstractITunesObject.URI); - - static { - NAMESPACES.add(NAMESPACE); - } - - /** Creates a new instance of ITunesGenerator */ - public ITunesGenerator() { - } - - @Override - public void generate(final Module module, final Element element) { - Element root = element; - - while (root.getParent() != null && root.getParent() instanceof Element) { - root = (Element) root.getParent(); - } - - root.addNamespaceDeclaration(NAMESPACE); - - if (!(module instanceof AbstractITunesObject)) { - return; - } - - final AbstractITunesObject itunes = (AbstractITunesObject) module; - - if (itunes instanceof FeedInformationImpl) { - // Do Channel Specific Stuff. - final FeedInformationImpl info = (FeedInformationImpl) itunes; - final Element owner = generateSimpleElement("owner", ""); - final Element email = generateSimpleElement("email", info.getOwnerEmailAddress()); - owner.addContent(email); - - final Element name = generateSimpleElement("name", info.getOwnerName()); - owner.addContent(name); - element.addContent(owner); - - final List categories = info.getCategories(); - for (final Category cat : categories) { - - final Element category = generateSimpleElement("category", ""); - category.setAttribute("text", cat.getName()); - - if (cat.getSubcategory() != null) { - final Element subcat = generateSimpleElement("category", ""); - subcat.setAttribute("text", cat.getSubcategory().getName()); - category.addContent(subcat); - } - - element.addContent(category); - } - - if (info.getComplete()) { - element.addContent(generateSimpleElement("complete", "yes")); - } - - if (info.getNewFeedUrl() != null) { - element.addContent(generateSimpleElement("new-feed-url", info.getNewFeedUrl())); - } - - } else if (itunes instanceof EntryInformationImpl) { - final EntryInformationImpl info = (EntryInformationImpl) itunes; - - if (info.getDuration() != null) { - element.addContent(generateSimpleElement("duration", info.getDuration().toString())); - } - if (info.getClosedCaptioned()) { - element.addContent(generateSimpleElement("isClosedCaptioned", "yes")); - } - if (info.getOrder() != null) { - element.addContent(generateSimpleElement("order", info.getOrder().toString())); - } - } - - if (itunes.getAuthor() != null) { - element.addContent(generateSimpleElement("author", itunes.getAuthor())); - } - - if (itunes.getBlock()) { - element.addContent(generateSimpleElement("block", "")); - } - - if (itunes.getExplicit()) { - element.addContent(generateSimpleElement("explicit", "yes")); - } else { - element.addContent(generateSimpleElement("explicit", "no")); - } - - if (itunes.getImage() != null) { - final Element image = generateSimpleElement("image", ""); - image.setAttribute("href", itunes.getImage().toExternalForm()); - element.addContent(image); - } - - if (itunes.getKeywords() != null) { - final StringBuffer sb = new StringBuffer(); - - for (int i = 0; i < itunes.getKeywords().length; i++) { - if (i != 0) { - sb.append(", "); - } - - sb.append(itunes.getKeywords()[i]); - } - - element.addContent(generateSimpleElement("keywords", sb.toString())); - } - - if (itunes.getSubtitle() != null) { - element.addContent(generateSimpleElement("subtitle", itunes.getSubtitle())); - } - - if (itunes.getSummary() != null) { - element.addContent(generateSimpleElement("summary", itunes.getSummary())); - } - } - - /** - * Returns the list of namespaces this module uses. - * - * @return set of Namespace objects. - */ - @Override - public Set getNamespaces() { - return NAMESPACES; - } - - /** - * Returns the namespace URI this module handles. - * - * @return Returns the namespace URI this module handles. - */ - @Override - public String getNamespaceUri() { - return AbstractITunesObject.URI; - } - - protected Element generateSimpleElement(final String name, final String value) { - final Element element = new Element(name, NAMESPACE); - element.addContent(value); - - return element; - } -} +/* + * ITunesGenerator.java + * + * Created on August 1, 2005, 10:44 PM + * + * This library is provided under dual licenses. + * You may choose the terms of the Lesser General Public License or the Apache + * License at your discretion. + * + * Copyright (C) 2005 Robert Cooper, Temple of the Screaming Penguin + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.rometools.modules.itunes.io; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.jdom2.Element; +import org.jdom2.Namespace; + +import com.rometools.modules.itunes.AbstractITunesObject; +import com.rometools.modules.itunes.EntryInformationImpl; +import com.rometools.modules.itunes.FeedInformationImpl; +import com.rometools.modules.itunes.types.Category; +import com.rometools.rome.feed.module.Module; +import com.rometools.rome.io.ModuleGenerator; + +/** + * @version $Revision: 1.3 $ + * @author Robert "kebernet" Cooper + */ +public class ITunesGenerator implements ModuleGenerator { + + private static final HashSet NAMESPACES = new HashSet(); + private static final Namespace NAMESPACE = Namespace.getNamespace(AbstractITunesObject.PREFIX, AbstractITunesObject.URI); + + static { + NAMESPACES.add(NAMESPACE); + } + + /** Creates a new instance of ITunesGenerator */ + public ITunesGenerator() { + } + + @Override + public void generate(final Module module, final Element element) { + Element root = element; + + while (root.getParent() != null && root.getParent() instanceof Element) { + root = (Element) root.getParent(); + } + + root.addNamespaceDeclaration(NAMESPACE); + + if (!(module instanceof AbstractITunesObject)) { + return; + } + + final AbstractITunesObject itunes = (AbstractITunesObject) module; + + if (itunes instanceof FeedInformationImpl) { + // Do Channel Specific Stuff. + final FeedInformationImpl info = (FeedInformationImpl) itunes; + + final Element owner = generateSimpleElement("owner", ""); + final Element email = generateSimpleElement("email", info.getOwnerEmailAddress()); + owner.addContent(email); + final Element name = generateSimpleElement("name", info.getOwnerName()); + owner.addContent(name); + element.addContent(owner); + + final List categories = info.getCategories(); + for (final Category cat : categories) { + + final Element category = generateSimpleElement("category", ""); + category.setAttribute("text", cat.getName()); + + if (cat.getSubcategory() != null) { + final Element subcat = generateSimpleElement("category", ""); + subcat.setAttribute("text", cat.getSubcategory().getName()); + category.addContent(subcat); + } + + element.addContent(category); + } + + if (info.getComplete() != null) { + if (info.getComplete()) { + element.addContent(generateSimpleElement("complete", "yes")); + } else { + element.addContent(generateSimpleElement("complete", "no")); + } + } + + if (info.getNewFeedUrl() != null) { + element.addContent(generateSimpleElement("new-feed-url", info.getNewFeedUrl().toExternalForm())); + } + + } else if (itunes instanceof EntryInformationImpl) { + final EntryInformationImpl info = (EntryInformationImpl) itunes; + + if (info.getDuration() != null) { + element.addContent(generateSimpleElement("duration", info.getDuration().toString())); + } + if (info.getClosedCaptioned() != null) { + element.addContent(generateSimpleElement("isClosedCaptioned", info.getClosedCaptioned().name())); + } + if (info.getOrder() != null) { + element.addContent(generateSimpleElement("order", info.getOrder().toString())); + } + } + + if (itunes.getAuthor() != null) { + element.addContent(generateSimpleElement("author", itunes.getAuthor())); + } + + if (itunes.getBlock()) { + element.addContent(generateSimpleElement("block", "")); + } + + if (itunes.getExplicit() != null) { + element.addContent(generateSimpleElement("explicit", itunes.getExplicit().name())); + } + + if (itunes.getImage() != null) { + final Element image = generateSimpleElement("image", ""); + image.setAttribute("href", itunes.getImage().toExternalForm()); + element.addContent(image); + } + + if (itunes.getKeywords() != null) { + final StringBuffer sb = new StringBuffer(); + + for (int i = 0; i < itunes.getKeywords().length; i++) { + if (i != 0) { + sb.append(", "); + } + + sb.append(itunes.getKeywords()[i]); + } + + element.addContent(generateSimpleElement("keywords", sb.toString())); + } + + if (itunes.getSubtitle() != null) { + element.addContent(generateSimpleElement("subtitle", itunes.getSubtitle())); + } + + if (itunes.getSummary() != null) { + element.addContent(generateSimpleElement("summary", itunes.getSummary())); + } + } + + /** + * Returns the list of namespaces this module uses. + * + * @return set of Namespace objects. + */ + @Override + public Set getNamespaces() { + return NAMESPACES; + } + + /** + * Returns the namespace URI this module handles. + * + * @return Returns the namespace URI this module handles. + */ + @Override + public String getNamespaceUri() { + return AbstractITunesObject.URI; + } + + protected Element generateSimpleElement(final String name, final String value) { + final Element element = new Element(name, NAMESPACE); + element.addContent(value); + + return element; + } +} diff --git a/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesParser.java b/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesParser.java index 1986df7..7058642 100644 --- a/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesParser.java +++ b/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesParser.java @@ -1,234 +1,253 @@ -/* - * ITunesParser.java - * - * Created on August 1, 2005, 8:29 PM - * - * This library is provided under dual licenses. - * You may choose the terms of the Lesser General Public License or the Apache - * License at your discretion. - * - * Copyright (C) 2005 Robert Cooper, Temple of the Screaming Penguin - * - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - - */ -package com.rometools.modules.itunes.io; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.List; -import java.util.Locale; -import java.util.StringTokenizer; - -import org.jdom2.Content; -import org.jdom2.Element; -import org.jdom2.Namespace; -import org.jdom2.output.XMLOutputter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.rometools.modules.itunes.AbstractITunesObject; -import com.rometools.modules.itunes.EntryInformationImpl; -import com.rometools.modules.itunes.FeedInformationImpl; -import com.rometools.modules.itunes.types.Category; -import com.rometools.modules.itunes.types.Duration; -import com.rometools.modules.itunes.types.Subcategory; -import com.rometools.rome.io.ModuleParser; -import com.rometools.rome.io.WireFeedParser; - -/** - * @version $Revision: 1.10 $ - * @author Robert "kebernet" Cooper - */ -public class ITunesParser implements ModuleParser { - - private static final Logger LOG = LoggerFactory.getLogger(ITunesParser.class); - - Namespace ns = Namespace.getNamespace(AbstractITunesObject.URI); - - /** Creates a new instance of ITunesParser */ - public ITunesParser() { - } - - public void setParser(final WireFeedParser feedParser) { - } - - @Override - public String getNamespaceUri() { - return AbstractITunesObject.URI; - } - - @Override - public com.rometools.rome.feed.module.Module parse(final Element element, final Locale locale) { - AbstractITunesObject module = null; - - if (element.getName().equals("channel")) { - final FeedInformationImpl feedInfo = new FeedInformationImpl(); - module = feedInfo; - - // Now I am going to get the channel specific tags - final Element owner = element.getChild("owner", ns); - - if (owner != null) { - final Element name = owner.getChild("name", ns); - - if (name != null) { - feedInfo.setOwnerName(name.getValue().trim()); - } - - final Element email = owner.getChild("email", ns); - - if (email != null) { - feedInfo.setOwnerEmailAddress(email.getValue().trim()); - } - } - - final List categories = element.getChildren("category", ns); - for (final Element element2 : categories) { - final Element category = element2; - if (category != null && category.getAttribute("text") != null) { - final Category cat = new Category(); - cat.setName(category.getAttribute("text").getValue().trim()); - - final Element subcategory = category.getChild("category", ns); - - if (subcategory != null && subcategory.getAttribute("text") != null) { - final Subcategory subcat = new Subcategory(); - subcat.setName(subcategory.getAttribute("text").getValue().trim()); - cat.setSubcategory(subcat); - } - - feedInfo.getCategories().add(cat); - } - } - - final Element complete = element.getChild("complete", ns); - if (complete != null) { - feedInfo.setComplete("yes".equals(complete.getTextTrim().toLowerCase())); - } - - final Element newFeedUrl = element.getChild("new-feed-url", ns); - if (newFeedUrl != null) { - feedInfo.setNewFeedUrl(newFeedUrl.getTextTrim()); - } - - } else if (element.getName().equals("item")) { - final EntryInformationImpl entryInfo = new EntryInformationImpl(); - module = entryInfo; - - // Now I am going to get the item specific tags - - final Element duration = element.getChild("duration", ns); - - if (duration != null && duration.getValue() != null) { - final Duration dur = new Duration(duration.getValue().trim()); - entryInfo.setDuration(dur); - } - - final Element closedCaptioned = element.getChild("isClosedCaptioned", ns); - - if (closedCaptioned != null && closedCaptioned.getValue() != null && closedCaptioned.getValue().trim().equalsIgnoreCase("yes")) { - entryInfo.setClosedCaptioned(true); - } - - final Element order = element.getChild("order", ns); - - if (order != null && order.getValue() != null) { - final Integer o = Integer.valueOf(order.getValue().trim()); - entryInfo.setOrder(o); - } - } - if (module != null) { - // All these are common to both Channel and Item - final Element author = element.getChild("author", ns); - - if (author != null && author.getText() != null) { - module.setAuthor(author.getText()); - } - - final Element block = element.getChild("block", ns); - - if (block != null) { - module.setBlock(true); - } - - final Element explicit = element.getChild("explicit", ns); - - if (explicit != null && explicit.getValue() != null && explicit.getValue().trim().equalsIgnoreCase("yes")) { - module.setExplicit(true); - } - - final Element keywords = element.getChild("keywords", ns); - - if (keywords != null) { - final StringTokenizer tok = new StringTokenizer(getXmlInnerText(keywords).trim(), ","); - final String[] keywordsArray = new String[tok.countTokens()]; - - for (int i = 0; tok.hasMoreTokens(); i++) { - keywordsArray[i] = tok.nextToken(); - } - - module.setKeywords(keywordsArray); - } - - final Element subtitle = element.getChild("subtitle", ns); - - if (subtitle != null) { - module.setSubtitle(subtitle.getTextTrim()); - } - - final Element summary = element.getChild("summary", ns); - - if (summary != null) { - module.setSummary(summary.getTextTrim()); - } - - final Element image = element.getChild("image", ns); - - if (image != null && image.getAttributeValue("href") != null) { - try { - final URL imageURL = new URL(image.getAttributeValue("href").trim()); - module.setImage(imageURL); - } catch (final MalformedURLException e) { - LOG.debug("Malformed URL Exception reading itunes:image tag: {}", image.getAttributeValue("href")); - } - } - } - - return module; - } - - protected String getXmlInnerText(final Element e) { - final StringBuffer sb = new StringBuffer(); - final XMLOutputter xo = new XMLOutputter(); - final List children = e.getContent(); - sb.append(xo.outputString(children)); - return sb.toString(); - } -} +/* + * ITunesParser.java + * + * Created on August 1, 2005, 8:29 PM + * + * This library is provided under dual licenses. + * You may choose the terms of the Lesser General Public License or the Apache + * License at your discretion. + * + * Copyright (C) 2005 Robert Cooper, Temple of the Screaming Penguin + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + + */ +package com.rometools.modules.itunes.io; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import java.util.Locale; +import java.util.StringTokenizer; + +import org.jdom2.Content; +import org.jdom2.Element; +import org.jdom2.Namespace; +import org.jdom2.output.XMLOutputter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.rometools.modules.itunes.AbstractITunesObject; +import com.rometools.modules.itunes.EntryInformation; +import com.rometools.modules.itunes.EntryInformationImpl; +import com.rometools.modules.itunes.FeedInformationImpl; +import com.rometools.modules.itunes.ITunes; +import com.rometools.modules.itunes.types.Category; +import com.rometools.modules.itunes.types.Duration; +import com.rometools.modules.itunes.types.Subcategory; +import com.rometools.rome.feed.module.Module; +import com.rometools.rome.io.ModuleParser; +import com.rometools.rome.io.WireFeedParser; +import com.rometools.utils.Integers; + +/** + * @version $Revision: 1.10 $ + * @author Robert "kebernet" Cooper + */ +public class ITunesParser implements ModuleParser { + + private static final Logger LOG = LoggerFactory.getLogger(ITunesParser.class); + + private final Namespace ns; + + /** Creates a new instance of ITunesParser */ + public ITunesParser() { + this(Namespace.getNamespace(AbstractITunesObject.URI)); + } + + /** + * @param ns target namespace + */ + protected ITunesParser(final Namespace ns) { + this.ns = ns; + } + + /** + * @param feedParser ignored + */ + public void setParser(final WireFeedParser feedParser) { + } + + @Override + public String getNamespaceUri() { + return AbstractITunesObject.URI; + } + + @Override + public Module parse(final Element element, final Locale locale) { + AbstractITunesObject module = null; + + if (element.getName().equals("channel")) { + final FeedInformationImpl feedInfo = new FeedInformationImpl(); + module = feedInfo; + + // Now I am going to get the channel specific tags + final Element owner = element.getChild("owner", ns); + + if (owner != null) { + final Element name = owner.getChild("name", ns); + + if (name != null) { + feedInfo.setOwnerName(name.getValue().trim()); + } + + final Element email = owner.getChild("email", ns); + + if (email != null) { + feedInfo.setOwnerEmailAddress(email.getValue().trim()); + } + } + + final List categories = element.getChildren("category", ns); + for (final Element element2 : categories) { + final Element category = element2; + if (category != null && category.getAttribute("text") != null) { + final Category cat = new Category(); + cat.setName(category.getAttribute("text").getValue().trim()); + + final Element subcategory = category.getChild("category", ns); + + if (subcategory != null && subcategory.getAttribute("text") != null) { + final Subcategory subcat = new Subcategory(); + subcat.setName(subcategory.getAttribute("text").getValue().trim()); + cat.setSubcategory(subcat); + } + + feedInfo.getCategories().add(cat); + } + } + + final Element complete = element.getChild("complete", ns); + if (complete != null) { + feedInfo.setComplete("yes".equals(complete.getTextTrim().toLowerCase())); + } + + final Element newFeedUrl = element.getChild("new-feed-url", ns); + if (newFeedUrl != null) { + try { + feedInfo.setNewFeedUrl(new URL(newFeedUrl.getTextTrim())); + } catch (final MalformedURLException e) { + LOG.debug("Malformed URL Exception reading itunes:new-feed-url tag: {}", newFeedUrl.getTextTrim()); + } + } + + } else if (element.getName().equals("item")) { + final EntryInformationImpl entryInfo = new EntryInformationImpl(); + module = entryInfo; + + // Now I am going to get the item specific tags + + final Element duration = element.getChild("duration", ns); + if (duration != null && duration.getValue() != null) { + final Duration dur = new Duration(duration.getValue().trim()); + entryInfo.setDuration(dur); + } + + final Element isClosedCaptioned = element.getChild("isClosedCaptioned", ns); + + if (isClosedCaptioned != null && isClosedCaptioned.getValue() != null ) { + entryInfo.setClosedCaptioned(EntryInformation.ClosedCaptioned.valueOf(isClosedCaptioned.getTextTrim().toLowerCase())); + } + + final Element order = element.getChild("order", ns); + + if (order != null && order.getValue() != null) { + final Integer o = Integer.valueOf(order.getValue().trim()); + entryInfo.setOrder(o); + } + } + if (module != null) { + // All these are common to both Channel and Item + final Element author = element.getChild("author", ns); + + if (author != null && author.getText() != null) { + module.setAuthor(author.getText()); + } + + final Element block = element.getChild("block", ns); + + if (block != null) { + module.setBlock("yes".equals(block.getTextTrim().toLowerCase())); + } + + final Element explicit = element.getChild("explicit", ns); + + if (explicit != null && explicit.getValue() != null) { + module.setExplicit(ITunes.Explicit.valueOf(explicit.getTextTrim().toLowerCase())); + } + + final Element keywords = element.getChild("keywords", ns); + + if (keywords != null) { + final StringTokenizer tok = new StringTokenizer(getXmlInnerText(keywords).trim(), ","); + final String[] keywordsArray = new String[tok.countTokens()]; + + for (int i = 0; tok.hasMoreTokens(); i++) { + keywordsArray[i] = tok.nextToken(); + } + + module.setKeywords(keywordsArray); + } + + final Element subtitle = element.getChild("subtitle", ns); + + if (subtitle != null) { + module.setSubtitle(subtitle.getTextTrim()); + } + + final Element summary = element.getChild("summary", ns); + + if (summary != null) { + module.setSummary(summary.getTextTrim()); + } + + final Element image = element.getChild("image", ns); + + if (image != null && image.getAttributeValue("href") != null) { + try { + final URL imageURL = new URL(image.getAttributeValue("href").trim()); + module.setImage(imageURL); + } catch (final MalformedURLException e) { + LOG.debug("Malformed URL Exception reading itunes:image tag: {}", image.getAttributeValue("href")); + } + } + + } + + return module; + } + + protected String getXmlInnerText(final Element e) { + final StringBuffer sb = new StringBuffer(); + final XMLOutputter xo = new XMLOutputter(); + final List children = e.getContent(); + sb.append(xo.outputString(children)); + return sb.toString(); + } +} diff --git a/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesParserOldNamespace.java b/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesParserOldNamespace.java index ac05a7b..86c8d8a 100644 --- a/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesParserOldNamespace.java +++ b/rome-modules/src/main/java/com/rometools/modules/itunes/io/ITunesParserOldNamespace.java @@ -47,12 +47,11 @@ import org.jdom2.Namespace; * @author Robert "kebernet" Cooper */ public class ITunesParserOldNamespace extends ITunesParser { - String URI = "http://www.itunes.com/DTDs/Podcast-1.0.dtd"; + private static final String URI = "http://www.itunes.com/DTDs/Podcast-1.0.dtd"; /** Creates a new instance of ITunesParserOldNamespace */ public ITunesParserOldNamespace() { - super(); - super.ns = Namespace.getNamespace(URI); + super(Namespace.getNamespace(URI)); } @Override diff --git a/rome-modules/src/test/java/com/rometools/modules/itunes/ITunesParserTest.java b/rome-modules/src/test/java/com/rometools/modules/itunes/ITunesParserTest.java index eb8fd68..f32ffd0 100644 --- a/rome-modules/src/test/java/com/rometools/modules/itunes/ITunesParserTest.java +++ b/rome-modules/src/test/java/com/rometools/modules/itunes/ITunesParserTest.java @@ -1,123 +1,242 @@ -/* - * ITunesParserTest.java - * JUnit based test - * - * Created on August 2, 2005, 1:30 PM - */ -package com.rometools.modules.itunes; - -import java.io.File; -import java.util.Iterator; -import java.util.List; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.rometools.modules.AbstractTestCase; -import com.rometools.modules.itunes.AbstractITunesObject; -import com.rometools.modules.itunes.EntryInformationImpl; -import com.rometools.modules.itunes.FeedInformationImpl; -import com.rometools.modules.itunes.io.ITunesGenerator; -import com.rometools.rome.feed.module.Module; -import com.rometools.rome.feed.synd.SyndEntry; -import com.rometools.rome.feed.synd.SyndFeed; -import com.rometools.rome.io.SyndFeedInput; -import com.rometools.rome.io.XmlReader; - -/** - * - * @author cooper - */ -public class ITunesParserTest extends AbstractTestCase { - - private static final Logger LOG = LoggerFactory.getLogger(ITunesParserTest.class); - - public ITunesParserTest(final String testName) { - super(testName); - } - - @Override - protected void setUp() throws Exception { - } - - @Override - protected void tearDown() throws Exception { - } - - public static Test suite() { - final TestSuite suite = new TestSuite(ITunesParserTest.class); - - return suite; - } - - /** - * Test of getNamespaceUri method, of class com.totsp.xml.syndication.itunes.ITunesParser. - */ - public void testGetNamespaceUri() { - LOG.debug("testGetNamespaceUri"); - - assertEquals("Namespace", "http://www.itunes.com/dtds/podcast-1.0.dtd", new ITunesGenerator().getNamespaceUri()); - } - - /** - * Test of parse method, of class com.totsp.xml.syndication.itunes.ITunesParser. - */ - public void testParse() throws Exception { - File feed = new File(getTestFile("xml/leshow.xml")); - final SyndFeedInput input = new SyndFeedInput(); - SyndFeed syndfeed = input.build(new XmlReader(feed.toURI().toURL())); - - final Module module = syndfeed.getModule(AbstractITunesObject.URI); - final FeedInformationImpl feedInfo = (FeedInformationImpl) module; - - assertEquals("owner", "Harry Shearer", feedInfo.getOwnerName()); - assertEquals("email", "", feedInfo.getOwnerEmailAddress()); - assertEquals("image", "http://a1.phobos.apple.com/Music/y2005/m06/d26/h21/mcdrrifv.jpg", feedInfo.getImage().toExternalForm()); - assertEquals("category", "Comedy", feedInfo.getCategories().get(0).getName()); - assertEquals( - "summary", - "A weekly, hour-long romp through the worlds of media, politics, sports and show business, leavened with an eclectic mix of mysterious music, hosted by Harry Shearer.", - feedInfo.getSummary()); - assertEquals(true, feedInfo.getComplete()); - assertEquals("http://example.org", feedInfo.getNewFeedUrl()); - - List entries = syndfeed.getEntries(); - Iterator it = entries.iterator(); - - while (it.hasNext()) { - final SyndEntry entry = it.next(); - final EntryInformationImpl entryInfo = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI); - LOG.debug("{}", entryInfo); - } - - feed = new File(getTestFile("xml/rsr.xml")); - syndfeed = input.build(new XmlReader(feed.toURI().toURL())); - entries = syndfeed.getEntries(); - it = entries.iterator(); - - while (it.hasNext()) { - final SyndEntry entry = it.next(); - final EntryInformationImpl entryInfo = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI); - LOG.debug("{}", entryInfo.getDuration()); - } - } - - /** - * Test of parse method, of class com.rometools.modules.itunes.io.ITunesParser. - */ - public void testParseItem() throws Exception { - File feed = new File(getTestFile("xml/leshow.xml")); - final SyndFeedInput input = new SyndFeedInput(); - SyndFeed syndfeed = input.build(new XmlReader(feed.toURI().toURL())); - - SyndEntry entry = syndfeed.getEntries().get(0); - - EntryInformationImpl entryInfo = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI); - assertEquals(true, entryInfo.getClosedCaptioned()); - assertEquals(Integer.valueOf(2), entryInfo.getOrder()); - assertEquals("http://example.org/image.png", entryInfo.getImage().toString()); - } -} +/* + * ITunesParserTest.java + * JUnit based test + * + * Created on August 2, 2005, 1:30 PM + */ +package com.rometools.modules.itunes; + +import java.io.File; +import java.io.IOException; +import java.util.Iterator; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.rometools.modules.AbstractTestCase; +import com.rometools.modules.itunes.EntryInformation.ClosedCaptioned; +import com.rometools.modules.itunes.ITunes.Explicit; +import com.rometools.modules.itunes.io.ITunesGenerator; +import com.rometools.rome.feed.module.Module; +import com.rometools.rome.feed.synd.SyndEntry; +import com.rometools.rome.feed.synd.SyndFeed; +import com.rometools.rome.io.FeedException; +import com.rometools.rome.io.SyndFeedInput; +import com.rometools.rome.io.XmlReader; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * + * @author cooper + */ +public class ITunesParserTest extends AbstractTestCase { + + private static final Logger LOG = LoggerFactory.getLogger(ITunesParserTest.class); + private static final int itemCountInLeShowFeed = 4; + + public ITunesParserTest(final String testName) { + super(testName); + } + + @Override + protected void setUp() throws Exception { + } + + @Override + protected void tearDown() throws Exception { + } + + public static Test suite() { + final TestSuite suite = new TestSuite(ITunesParserTest.class); + + return suite; + } + + /** + * Test of getNamespaceUri method, of class com.totsp.xml.syndication.itunes.ITunesParser. + */ + public void testGetNamespaceUri() { + LOG.debug("testGetNamespaceUri"); + + assertEquals("Namespace", "http://www.itunes.com/dtds/podcast-1.0.dtd", new ITunesGenerator().getNamespaceUri()); + } + + /** + * Test of parse method, of class com.totsp.xml.syndication.itunes.ITunesParser. + */ + public void testParse() throws Exception { + File feed = new File(getTestFile("xml/leshow.xml")); + final SyndFeedInput input = new SyndFeedInput(); + SyndFeed syndfeed = input.build(new XmlReader(feed.toURI().toURL())); + + final Module module = syndfeed.getModule(AbstractITunesObject.URI); + final FeedInformationImpl feedInfo = (FeedInformationImpl) module; + + assertEquals("owner", "Harry Shearer", feedInfo.getOwnerName()); + assertEquals("email", "", feedInfo.getOwnerEmailAddress()); + assertEquals("image", "http://a1.phobos.apple.com/Music/y2005/m06/d26/h21/mcdrrifv.jpg", feedInfo.getImage().toExternalForm()); + assertEquals("category", "Comedy", feedInfo.getCategories().get(0).getName()); + assertEquals( + "summary", + "A weekly, hour-long romp through the worlds of media, politics, sports and show business, leavened with an eclectic mix of mysterious music, hosted by Harry Shearer.", + feedInfo.getSummary()); + assertEquals("complete", Boolean.TRUE, feedInfo.getComplete()); + assertEquals("new-feed-url", "http://newlocation.com/example.rss", feedInfo.getNewFeedUrl().toExternalForm()); + assertFalse("block", feedInfo.getBlock()); + + List entries = syndfeed.getEntries(); + Iterator it = entries.iterator(); + + while (it.hasNext()) { + final SyndEntry entry = it.next(); + final EntryInformationImpl entryInfo = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI); + LOG.debug("{}", entryInfo); + } + + feed = new File(getTestFile("xml/rsr.xml")); + syndfeed = input.build(new XmlReader(feed.toURI().toURL())); + entries = syndfeed.getEntries(); + it = entries.iterator(); + + while (it.hasNext()) { + final SyndEntry entry = it.next(); + final EntryInformationImpl entryInfo = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI); + LOG.debug("{}", entryInfo.getDuration()); + } + + } + + /** + * Test of parse method, of class com.rometools.modules.itunes.io.ITunesParser. + */ + public void testParseItem() throws Exception { + File feed = new File(getTestFile("xml/leshow.xml")); + final SyndFeedInput input = new SyndFeedInput(); + SyndFeed syndfeed = input.build(new XmlReader(feed.toURI().toURL())); + + SyndEntry entry = syndfeed.getEntries().get(0); + + EntryInformationImpl entryInfo = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI); + assertEquals(ClosedCaptioned.yes, entryInfo.getClosedCaptioned()); + assertEquals(Integer.valueOf(2), entryInfo.getOrder()); + assertEquals("http://a1.phobos.apple.com/Music/y2005/m06/d26/h21/mcdrrifv.jpg", entryInfo.getImage().toString()); + } + + /** + * @throws FeedException if error on parsing feed + * @throws IOException if file not readable + */ + public void testParseRsr() throws IOException, FeedException { + final SyndFeed syndfeed = getSyndFeed("xml/rsr.xml"); + final List entries = syndfeed.getEntries(); + final Iterator it = entries.iterator(); + while (it.hasNext()) { + final SyndEntry entry = it.next(); + final EntryInformationImpl entryInfo = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI); + LOG.debug("{}", entryInfo.getDuration()); + } + } + + /** + * test for itunes:explicit tags. + * + * @throws FeedException if error on parsing feed + * @throws IOException if file not readable + */ + public void testImageTagOnItem() throws IOException, FeedException { + final SyndFeed feed = getSyndFeed("xml/leshow.xml"); + assertEquals("http://a1.phobos.apple.com/Music/y2005/m06/d26/h21/mcdrrifv.jpg", + ((EntryInformation) feed.getEntries().get(0).getModule(AbstractITunesObject.URI)).getImage().toExternalForm()); + } + + /** + * test for itunes:explicit tags. + * + * @throws FeedException if error on parsing feed + * @throws IOException if file not readable + */ + public void testExplicitTags() throws IOException, FeedException { + final SyndFeed feed = getSyndFeed("xml/leshow.xml"); + final FeedInformationImpl feedInfo = (FeedInformationImpl) feed.getModule(AbstractITunesObject.URI); + assertEquals("explicit tag on feed", Explicit.yes, feedInfo.getExplicit()); + assertEquals("wrong count of items", itemCountInLeShowFeed, feed.getEntries().size()); + assertEquals("explicit tag on 1. item", Explicit.yes, + ((EntryInformation) feed.getEntries().get(0).getModule(AbstractITunesObject.URI)).getExplicit()); + assertEquals("explicit tag on 2. item", Explicit.no, + ((EntryInformation) feed.getEntries().get(1).getModule(AbstractITunesObject.URI)).getExplicit()); + assertEquals("explicit tag on 3. item", Explicit.clean, + ((EntryInformation) feed.getEntries().get(2).getModule(AbstractITunesObject.URI)).getExplicit()); + assertNull("explicit tag on 4. item", + ((EntryInformation) feed.getEntries().get(3).getModule(AbstractITunesObject.URI)).getExplicit()); + } + + /** + * test for itunes:isClosedCaptioned tags. + * + * @throws FeedException if error on parsing feed + * @throws IOException if file not readable + */ + public void testClosedCaptionedTags() throws IOException, FeedException { + final SyndFeed feed = getSyndFeed("xml/leshow.xml"); + assertEquals("wrong count of items", itemCountInLeShowFeed, feed.getEntries().size()); + assertEquals("isClosedCaptioned tag on 1. item", ClosedCaptioned.yes, + ((EntryInformation) feed.getEntries().get(0).getModule(AbstractITunesObject.URI)).getClosedCaptioned()); + assertEquals("isClosedCaptioned tag on 2. item", ClosedCaptioned.no, + ((EntryInformation) feed.getEntries().get(1).getModule(AbstractITunesObject.URI)).getClosedCaptioned()); + assertEquals("isClosedCaptioned tag on 3. item", ClosedCaptioned.no, + ((EntryInformation) feed.getEntries().get(2).getModule(AbstractITunesObject.URI)).getClosedCaptioned()); + assertNull("isClosedCaptioned tag on 4. item", + ((EntryInformation) feed.getEntries().get(3).getModule(AbstractITunesObject.URI)).getClosedCaptioned()); + } + + /** + * test for itunes:order tags. + * + * @throws FeedException if error on parsing feed + * @throws IOException if file not readable + */ + public void testOrderTags() throws IOException, FeedException { + final SyndFeed feed = getSyndFeed("xml/leshow.xml"); + assertEquals("wrong count of items", itemCountInLeShowFeed, feed.getEntries().size()); + assertEquals("order tag on 1. item", Integer.valueOf(2), + ((EntryInformation) feed.getEntries().get(0).getModule(AbstractITunesObject.URI)).getOrder()); + assertEquals("order tag on 2. item", Integer.valueOf(1), + ((EntryInformation) feed.getEntries().get(1).getModule(AbstractITunesObject.URI)).getOrder()); + assertNull("order tag on 3. item", + ((EntryInformation) feed.getEntries().get(2).getModule(AbstractITunesObject.URI)).getOrder()); + assertNull("order tag on 4. item", + ((EntryInformation) feed.getEntries().get(3).getModule(AbstractITunesObject.URI)).getOrder()); + } + + /** + * test for itunes:block tags. + * + * @throws FeedException if error on parsing feed + * @throws IOException if file not readable + */ + public void testBlockTags() throws IOException, FeedException { + final SyndFeed feed = getSyndFeed("xml/leshow.xml"); + assertEquals("wrong count of items", itemCountInLeShowFeed, feed.getEntries().size()); + assertTrue("block tag on 1. item", + ((EntryInformation) feed.getEntries().get(0).getModule(AbstractITunesObject.URI)).getBlock()); + assertFalse("block tag on 2. item", + ((EntryInformation) feed.getEntries().get(1).getModule(AbstractITunesObject.URI)).getBlock()); + assertFalse("block tag on 3. item", + ((EntryInformation) feed.getEntries().get(2).getModule(AbstractITunesObject.URI)).getBlock()); + assertFalse("block tag on 4. item", + ((EntryInformation) feed.getEntries().get(3).getModule(AbstractITunesObject.URI)).getBlock()); + } + + /** + * @param testfile path to test file + * @return SyndFeed from test file + * @throws FeedException if error on parsing feed + * @throws IOException if file not readable + */ + private SyndFeed getSyndFeed(final String testfile) throws IOException, FeedException { + return new SyndFeedInput().build(new File(getTestFile(testfile))); + } +} diff --git a/rome-modules/src/test/resources/xml/leshow.xml b/rome-modules/src/test/resources/xml/leshow.xml index f6855fc..d6ab50c 100644 --- a/rome-modules/src/test/resources/xml/leshow.xml +++ b/rome-modules/src/test/resources/xml/leshow.xml @@ -1,189 +1,93 @@ - - KCRW's Le Show - Harry Shearer - http://www.kcrw.com/show/ls - A weekly, hour-long romp through the worlds of media, politics, sports and show business, leavened with an eclectic mix of mysterious music, hosted by Harry Shearer. - An hour's worth of Harry Shearer - A weekly, hour-long romp through the worlds of media, politics, sports and show business, leavened with an eclectic mix of mysterious music, hosted by Harry Shearer. + + KCRW's Le Show + Harry Shearer + http://www.kcrw.com/show/ls + A weekly, hour-long romp through the worlds of media, politics, sports and show business, leavened with an eclectic mix of mysterious music, hosted by Harry Shearer. + An hour's worth of Harry Shearer + A weekly, hour-long romp through the worlds of media, politics, sports and show business, leavened with an eclectic mix of mysterious music, hosted by Harry Shearer. yes - http://example.org - en - - KCRW 2005 - - - Harry Shearer - - - - KCRW's Le Show - - - Comedy - - - - - - - - - - - - - - - - le Show - Harry Shearer - - - - - http://66.186.18.80/podcast/mp3/ls/ls050731le_Show.mp3 - - Sun, 31 Jul 2005 16:00:00 GMT - - - - Comedy - - - - - - - - - - - - - - no - - 46:34 - - - yes - 2 - - - - - - le Show - Harry Shearer - - - - - - - - http://66.186.18.80/podcast/mp3/ls/ls050724le_Show.mp3 - - Sun, 24 Jul 2005 16:00:00 GMT - - - - Comedy - - - - - - - - - - - - - - no - - 44:00 - - - - - - - le Show - Harry Shearer - - - - - - - - http://66.186.18.80/podcast/mp3/ls/ls050717le_Show.mp3 - - Sun, 17 Jul 2005 16:00:00 GMT - - - - Comedy - - - - - - - - - - - - - - no - - 48:33 - - - - - - - le Show - Harry Shearer - - - - - http://66.186.18.80/podcast/mp3/ls/ls050710le_Show.mp3 - - Sun, 10 Jul 2005 16:00:00 GMT - - - - Comedy - - - - - - - - - - - - - - no - - 45:56 - - - - - + http://newlocation.com/example.rss + en + KCRW 2005 + + Harry Shearer + + + KCRW's Le Show + Comedy + + + no + yes + + le Show + Harry Shearer + + + + + http://66.186.18.80/podcast/mp3/ls/ls050731le_Show.mp3 + Sun, 31 Jul 2005 16:00:00 GMT + Comedy + + + yes + 46:34 + + yes + 2 + KCRW's Le Show + yes + + + le Show + Harry Shearer + + + + + http://66.186.18.80/podcast/mp3/ls/ls050724le_Show.mp3 + Sun, 24 Jul 2005 16:00:00 GMT + Comedy + + + no + 44:00 + no + no + 1 + + + + le Show + Harry Shearer + + + + + http://66.186.18.80/podcast/mp3/ls/ls050717le_Show.mp3 + Sun, 17 Jul 2005 16:00:00 GMT + Comedy + + + 48:33 + no + no + clean + + + le Show + Harry Shearer + + http://66.186.18.80/podcast/mp3/ls/ls050710le_Show.mp3 + Sun, 10 Jul 2005 16:00:00 GMT + Comedy + + + 45:56 + +