Refactored some code

This commit is contained in:
Patrick Gotthard 2016-01-08 18:29:50 +01:00
parent ac9dc0df5c
commit f9576b8d00
9 changed files with 1215 additions and 1333 deletions

View file

@ -1,114 +1,87 @@
/* /*
* Attribute.java * Attribute.java
* *
* Created on April 24, 2006, 11:11 PM * Created on April 24, 2006, 11:11 PM
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.opml.feed.opml; package com.rometools.opml.feed.opml;
import java.io.Serializable; import java.io.Serializable;
import com.rometools.rome.feed.impl.EqualsBean; import com.rometools.rome.feed.impl.EqualsBean;
import com.rometools.rome.feed.impl.ToStringBean; import com.rometools.rome.feed.impl.ToStringBean;
/** /**
* This is a simple name-value pair attribute for outlines. * This is a simple name-value pair attribute for outlines.
* *
* @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a> * @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a>
*/ */
public class Attribute implements Cloneable, Serializable { public class Attribute implements Cloneable, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String _name; private String name;
private String _value; private String value;
/** Creates a new instance of Attribute */ /**
public Attribute() { * Creates a new instance of Attribute.
super(); *
} * @param name name of the attribute.
* @param value value of the attribute.
/** */
* Creates a new instance of Attribute. public Attribute(final String name, final String value) {
* if (name == null || value == null) {
* @param name name of the attribute. throw new NullPointerException("Name and value are required.");
* @param value value of the attribute. }
*/ setName(name);
public Attribute(final String name, final String value) { setValue(value);
if (name == null || value == null) { }
throw new NullPointerException("Name and value are required.");
} public void setName(final String name) {
setName(name); this.name = name;
setValue(value); }
}
public String getName() {
/** return name;
* name of the attribute. }
*
* @param name name of the attribute. public void setValue(final String value) {
*/ this.value = value;
public void setName(final String name) { }
_name = name;
} public String getValue() {
return value;
/** }
* name of the attribute.
* @Override
* @return name of the attribute. public Object clone() {
*/ return new Attribute(name, value);
public String getName() { }
return _name;
} @Override
public boolean equals(final Object obj) {
/** return new EqualsBean(Attribute.class, this).beanEquals(obj);
* value of the attribute. }
*
* @param value value of the attribute. @Override
*/ public int hashCode() {
public void setValue(final String value) { return new EqualsBean(Attribute.class, this).beanHashCode();
_value = value; }
}
@Override
/** public String toString() {
* value of the attribute. return new ToStringBean(Attribute.class, this).toString();
* }
* @return value of the attribute.
*/ }
public String getValue() {
return _value;
}
@Override
public Object clone() {
return new Attribute(_name, _value);
}
@Override
public boolean equals(final Object obj) {
final EqualsBean eBean = new EqualsBean(Attribute.class, this);
return eBean.beanEquals(obj);
}
@Override
public int hashCode() {
final EqualsBean equals = new EqualsBean(Attribute.class, this);
return equals.beanHashCode();
}
@Override
public String toString() {
final ToStringBean tsBean = new ToStringBean(Attribute.class, this);
return tsBean.toString();
}
}

View file

@ -1,333 +1,322 @@
/* /*
* Opml.java * Opml.java
* *
* Created on April 24, 2006, 11:00 PM * Created on April 24, 2006, 11:00 PM
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.opml.feed.opml; package com.rometools.opml.feed.opml;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import com.rometools.rome.feed.WireFeed; import com.rometools.rome.feed.WireFeed;
/** /**
* This class represents the root of an OPML 1/2 feed and contains the elements that may appear in * This class represents the root of an OPML 1/2 feed and contains the elements that may appear in the &lt;head&gt; tag
* the &lt;head&gt; tag of the feed. * of the feed.
* *
* @author <a href="mailto:cooper@screaming-penguin.com"> Robert "kebernet" Cooper</a> * @author <a href="mailto:cooper@screaming-penguin.com"> Robert "kebernet" Cooper</a>
*/ */
public class Opml extends WireFeed { public class Opml extends WireFeed {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Date _created; private Date created;
private Date _modified; private Date modified;
private Integer _verticalScrollState; private Integer verticalScrollState;
private Integer _windowBottom; private Integer windowBottom;
private Integer _windowLeft; private Integer windowLeft;
private Integer _windowRight; private Integer windowRight;
private Integer _windowTop; private Integer windowTop;
private List<Outline> _outlines; private List<Outline> outlines;
private String _docs; private String docs;
private String _ownerEmail; private String ownerEmail;
private String _ownerId; private String ownerId;
private String _ownerName; private String ownerName;
private String _title; private String title;
private int[] _expansionState; private int[] expansionState;
/** Creates a new instance of Opml */ /**
public Opml() { * <dateCreated> is a date-time, indicating when the document was created.
super(); *
} * @param created date-time, indicating when the document was created.
*/
/** public void setCreated(final Date created) {
* <dateCreated> is a date-time, indicating when the document was created. this.created = created;
* }
* @param created date-time, indicating when the document was created.
*/ /**
public void setCreated(final Date created) { * &lt;dateCreated&gt; is a date-time, indicating when the document was created.
_created = created; *
} * @return date-time, indicating when the document was created.
*/
/** public Date getCreated() {
* &lt;dateCreated&gt; is a date-time, indicating when the document was created. return created;
* }
* @return date-time, indicating when the document was created.
*/ /**
public Date getCreated() { * (OPML 2) &lt;docs&gt; is the http address of documentation for the format used in the OPML file. It's probably a
return _created; * pointer to <a href="http://www.opml.org/spec2">this page</a> for people who might stumble across the file on a
} * web server 25 years from now and wonder what it is.
*
/** * @param docs http address of documentation for the format used
* (OPML 2) &lt;docs&gt; is the http address of documentation for the format used in the OPML */
* file. It's probably a pointer to <a href="http://www.opml.org/spec2">this page</a> for people public void setDocs(final String docs) {
* who might stumble across the file on a web server 25 years from now and wonder what it is. this.docs = docs;
* }
* @param docs http address of documentation for the format used
*/ /**
public void setDocs(final String docs) { * (OPML 2) &lt;docs&gt; is the http address of documentation for the format used in the OPML file. It's probably a
_docs = docs; * pointer to <a href="http://www.opml.org/spec2">this page</a> for people who might stumble across the file on a
} * web server 25 years from now and wonder what it is.
*
/** * @return http address of documentation for the format used
* (OPML 2) &lt;docs&gt; is the http address of documentation for the format used in the OPML */
* file. It's probably a pointer to <a href="http://www.opml.org/spec2">this page</a> for people public String getDocs() {
* who might stumble across the file on a web server 25 years from now and wonder what it is. return docs;
* }
* @return http address of documentation for the format used
*/ /**
public String getDocs() { * &lt;expansionState&gt;is a comma-separated list of line numbers that are expanded. The line numbers in the list
return _docs; * tell you which headlines to expand. The order is important. For each element in the list, X, starting at the
} * first summit, navigate flatdown X times and expand. Repeat for each element in the list.
*
/** * @param expansionState int array containing expanded elements.
* &lt;expansionState&gt;is a comma-separated list of line numbers that are expanded. The line */
* numbers in the list tell you which headlines to expand. The order is important. For each public void setExpansionState(final int[] expansionState) {
* element in the list, X, starting at the first summit, navigate flatdown X times and expand. this.expansionState = expansionState;
* Repeat for each element in the list. }
*
* @param expansionState int array containing expanded elements. /**
*/ * &lt;expansionState&gt; is a comma-separated list of line numbers that are expanded. The line numbers in the list
public void setExpansionState(final int[] expansionState) { * tell you which headlines to expand. The order is important. For each element in the list, X, starting at the
_expansionState = expansionState; * first summit, navigate flatdown X times and expand. Repeat for each element in the list.
} *
* @return int array containing expanded elements.
/** */
* &lt;expansionState&gt; is a comma-separated list of line numbers that are expanded. The line public int[] getExpansionState() {
* numbers in the list tell you which headlines to expand. The order is important. For each return expansionState;
* element in the list, X, starting at the first summit, navigate flatdown X times and expand. }
* Repeat for each element in the list.
* /**
* @return int array containing expanded elements. * &lt;dateModified&gt; is a date-time, indicating when the document was last modified.
*/ *
public int[] getExpansionState() { * @param modified date-time, indicating when the document was last modified.
return _expansionState; */
} public void setModified(final Date modified) {
this.modified = modified;
/** }
* &lt;dateModified&gt; is a date-time, indicating when the document was last modified.
* /**
* @param modified date-time, indicating when the document was last modified. * &lt;dateModified&gt; is a date-time, indicating when the document was last modified.
*/ *
public void setModified(final Date modified) { * @return date-time, indicating when the document was last modified.
_modified = modified; */
} public Date getModified() {
return modified;
/** }
* &lt;dateModified&gt; is a date-time, indicating when the document was last modified.
* /**
* @return date-time, indicating when the document was last modified. * Root level Outline object that should appear in the &lt;body&gt;
*/ *
public Date getModified() { * @param outlines Root level Outline object that should appear in the &lt;body&gt;
return _modified; */
} public void setOutlines(final List<Outline> outlines) {
this.outlines = outlines;
/** }
* Root level Outline object that should appear in the &lt;body&gt;
* /**
* @param outlines Root level Outline object that should appear in the &lt;body&gt; * Root level Outline object that should appear in the &lt;body&gt;
*/ *
public void setOutlines(final List<Outline> outlines) { * @return Root level Outline object that should appear in the &lt;body&gt;
_outlines = outlines; */
} public List<Outline> getOutlines() {
if (outlines == null) {
/** outlines = new ArrayList<Outline>();
* Root level Outline object that should appear in the &lt;body&gt; }
*
* @return Root level Outline object that should appear in the &lt;body&gt; return outlines;
*/ }
public List<Outline> getOutlines() {
if (_outlines == null) { /**
_outlines = new ArrayList<Outline>(); * &lt;ownerEmail&gt; is a string, the email address of the owner of the document.
} *
* @param ownerEmail the email address of the owner of the document.
return _outlines; */
} public void setOwnerEmail(final String ownerEmail) {
this.ownerEmail = ownerEmail;
/** }
* &lt;ownerEmail&gt; is a string, the email address of the owner of the document.
* /**
* @param ownerEmail the email address of the owner of the document. * &lt;ownerEmail&gt; is a string, the email address of the owner of the document.
*/ *
public void setOwnerEmail(final String ownerEmail) { * @return the email address of the owner of the document.
_ownerEmail = ownerEmail; */
} public String getOwnerEmail() {
return ownerEmail;
/** }
* &lt;ownerEmail&gt; is a string, the email address of the owner of the document.
* /**
* @return the email address of the owner of the document. * (OPML 2) &lt;ownerId&gt; is the http address of a web page that contains <strike>an HTML</strike> a form that
*/ * allows a human reader to communicate with the author of the document via email or other means.
public String getOwnerEmail() { *
return _ownerEmail; * @param ownerId http address of a web page that contains <strike>an HTML</strike> a form that allows a human
} * reader to communicate with the author of the document via email or other means.
*/
/** public void setOwnerId(final String ownerId) {
* (OPML 2) &lt;ownerId&gt; is the http address of a web page that contains <strike>an this.ownerId = ownerId;
* HTML</strike> a form that allows a human reader to communicate with the author of the }
* document via email or other means.
* /**
* @param ownerId http address of a web page that contains <strike>an HTML</strike> a form that * (OPML 2) &lt;ownerId&gt; is the http address of a web page that contains <strike>an HTML</strike> a form that
* allows a human reader to communicate with the author of the document via email or * allows a human reader to communicate with the author of the document via email or other means.
* other means. *
*/ * @return http address of a web page that contains <strike>an HTML</strike> a form that allows a human reader to
public void setOwnerId(final String ownerId) { * communicate with the author of the document via email or other means.
_ownerId = ownerId; */
} public String getOwnerId() {
return ownerId;
/** }
* (OPML 2) &lt;ownerId&gt; is the http address of a web page that contains <strike>an
* HTML</strike> a form that allows a human reader to communicate with the author of the /**
* document via email or other means. * &lt;ownerName&gt; is a string, the owner of the document.
* *
* @return http address of a web page that contains <strike>an HTML</strike> a form that allows * @param ownerName the owner of the document.
* a human reader to communicate with the author of the document via email or other */
* means. public void setOwnerName(final String ownerName) {
*/ this.ownerName = ownerName;
public String getOwnerId() { }
return _ownerId;
} /**
* &lt;ownerName&gt; is a string, the owner of the document.
/** *
* &lt;ownerName&gt; is a string, the owner of the document. * @return the owner of the document.
* */
* @param ownerName the owner of the document. public String getOwnerName() {
*/ return ownerName;
public void setOwnerName(final String ownerName) { }
_ownerName = ownerName;
} /**
* &lt;title&gt; is the title of the document.
/** *
* &lt;ownerName&gt; is a string, the owner of the document. * @param title title of the document.
* */
* @return the owner of the document. public void setTitle(final String title) {
*/ this.title = title;
public String getOwnerName() { }
return _ownerName;
} /**
* &lt;title&gt; is the title of the document.
/** *
* &lt;title&gt; is the title of the document. * @return title of the document.
* */
* @param title title of the document. public String getTitle() {
*/ return title;
public void setTitle(final String title) { }
_title = title;
} /**
* &lt;vertScrollState&gt; is a number, saying which line of the outline is displayed on the top line of the window.
/** * This number is calculated with the expansion state already applied.
* &lt;title&gt; is the title of the document. *
* * @param verticalScrollState which line of the outline is displayed on the top line of the window.
* @return title of the document. */
*/ public void setVerticalScrollState(final Integer verticalScrollState) {
public String getTitle() { this.verticalScrollState = verticalScrollState;
return _title; }
}
/**
/** * &lt;vertScrollState&gt; is a number, saying which line of the outline is displayed on the top line of the window.
* &lt;vertScrollState&gt; is a number, saying which line of the outline is displayed on the top * This number is calculated with the expansion state already applied.
* line of the window. This number is calculated with the expansion state already applied. *
* * @return which line of the outline is displayed on the top line of the window. This number is calculated with the
* @param verticalScrollState which line of the outline is displayed on the top line of the * expansion state already applied.
* window. */
*/ public Integer getVerticalScrollState() {
public void setVerticalScrollState(final Integer verticalScrollState) { return verticalScrollState;
_verticalScrollState = verticalScrollState; }
}
/**
/** * &lt;windowBottom&gt; is a number, the pixel location of the bottom edge of the window.
* &lt;vertScrollState&gt; is a number, saying which line of the outline is displayed on the top *
* line of the window. This number is calculated with the expansion state already applied. * @param windowBottom the pixel location of the bottom edge of the window.
* */
* @return which line of the outline is displayed on the top line of the window. This number is public void setWindowBottom(final Integer windowBottom) {
* calculated with the expansion state already applied. this.windowBottom = windowBottom;
*/ }
public Integer getVerticalScrollState() {
return _verticalScrollState; /**
} * &lt;windowBottom&gt; is a number, the pixel location of the bottom edge of the window.
*
/** * @return the pixel location of the bottom edge of the window.
* &lt;windowBottom&gt; is a number, the pixel location of the bottom edge of the window. */
* public Integer getWindowBottom() {
* @param windowBottom the pixel location of the bottom edge of the window. return windowBottom;
*/ }
public void setWindowBottom(final Integer windowBottom) {
_windowBottom = windowBottom; /**
} * &lt;windowLeft&gt; is a number, the pixel location of the left edge of the window.
*
/** * @param windowLeft the pixel location of the left edge of the window.
* &lt;windowBottom&gt; is a number, the pixel location of the bottom edge of the window. */
* public void setWindowLeft(final Integer windowLeft) {
* @return the pixel location of the bottom edge of the window. this.windowLeft = windowLeft;
*/ }
public Integer getWindowBottom() {
return _windowBottom; /**
} * &lt;windowLeft&gt; is a number, the pixel location of the left edge of the window.
*
/** * @return the pixel location of the left edge of the window.
* &lt;windowLeft&gt; is a number, the pixel location of the left edge of the window. */
* public Integer getWindowLeft() {
* @param windowLeft the pixel location of the left edge of the window. return windowLeft;
*/ }
public void setWindowLeft(final Integer windowLeft) {
_windowLeft = windowLeft; /**
} * &lt;windowRight&gt; is a number, the pixel location of the right edge of the window.
*
/** * @param windowRight the pixel location of the right edge of the window.
* &lt;windowLeft&gt; is a number, the pixel location of the left edge of the window. */
* public void setWindowRight(final Integer windowRight) {
* @return the pixel location of the left edge of the window. this.windowRight = windowRight;
*/ }
public Integer getWindowLeft() {
return _windowLeft; /**
} * &lt;windowRight&gt; is a number, the pixel location of the right edge of the window.
*
/** * @return the pixel location of the right edge of the window.
* &lt;windowRight&gt; is a number, the pixel location of the right edge of the window. */
* public Integer getWindowRight() {
* @param windowRight the pixel location of the right edge of the window. return windowRight;
*/ }
public void setWindowRight(final Integer windowRight) {
_windowRight = windowRight; /**
} * &lt;windowTop&gt; is a number, the pixel location of the top edge of the window.
*
/** * @param windowTop the pixel location of the top edge of the window.
* &lt;windowRight&gt; is a number, the pixel location of the right edge of the window. */
* public void setWindowTop(final Integer windowTop) {
* @return the pixel location of the right edge of the window. this.windowTop = windowTop;
*/ }
public Integer getWindowRight() {
return _windowRight; /**
} * &lt;windowTop&gt; is a number, the pixel location of the top edge of the window.
*
/** * @return the pixel location of the top edge of the window.
* &lt;windowTop&gt; is a number, the pixel location of the top edge of the window. */
* public Integer getWindowTop() {
* @param windowTop the pixel location of the top edge of the window. return windowTop;
*/ }
public void setWindowTop(final Integer windowTop) {
_windowTop = windowTop; }
}
/**
* &lt;windowTop&gt; is a number, the pixel location of the top edge of the window.
*
* @return the pixel location of the top edge of the window.
*/
public Integer getWindowTop() {
return _windowTop;
}
}

View file

@ -1,377 +1,367 @@
/* /*
* Outline.java * Outline.java
* *
* Created on April 24, 2006, 11:04 PM * Created on April 24, 2006, 11:04 PM
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.opml.feed.opml; package com.rometools.opml.feed.opml;
import java.io.Serializable; import java.io.Serializable;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import com.rometools.rome.feed.impl.EqualsBean; import com.rometools.rome.feed.impl.EqualsBean;
import com.rometools.rome.feed.impl.ToStringBean; import com.rometools.rome.feed.impl.ToStringBean;
import com.rometools.rome.feed.module.Module; import com.rometools.rome.feed.module.Module;
/** /**
* This class represents an OPML outline element. * This class represents an OPML outline element.
* *
* @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a> * @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a>
*/ */
public class Outline implements Cloneable, Serializable { public class Outline implements Cloneable, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Date _created; private Date created;
private List<Attribute> _attributes; private List<Attribute> attributes;
private List<String> _categories; private List<String> categories;
private List<Outline> _children; private List<Outline> children;
private List<Module> _modules; private List<Module> modules;
private String _text; private String text;
private String _title; private String title;
private String _type; private String type;
private boolean _breakpoint; private boolean breakpoint;
private boolean _comment; private boolean comment;
/** Creates a new instance of Outline */ public Outline() {
public Outline() { }
super();
} /**
* Creates a new outline with the specified type and text values.
/** *
* Creates a new outline with the specified type and text values. * @param type type attribute value/
* * @param text text attribute value
* @param type type attribute value/ */
* @param text text attribute value public Outline(final String type, final String text) {
*/ setType(type);
public Outline(final String type, final String text) { setText(text);
super(); }
setType(type);
setText(text); /**
} * Creates an outline with the given title, xmlUrl and htmlUrl. This is traditionally used for aggregator feed lists
* and will get a type of "rss".
/** *
* Creates an outline with the given title, xmlUrl and htmlUrl. This is traditionally used for * @param title Title of the entry.
* aggregator feed lists and will get a type of "rss". * @param xmlUrl link to XML file.
* * @param htmlUrl link to html page.
* @param title Title of the entry. */
* @param xmlUrl link to XML file. public Outline(final String title, final URL xmlUrl, final URL htmlUrl) {
* @param htmlUrl link to html page. super();
*/ setType("rss");
public Outline(final String title, final URL xmlUrl, final URL htmlUrl) { setTitle(title);
super(); setAttributes(new ArrayList<Attribute>());
setType("rss");
setTitle(title); if (xmlUrl != null) {
setAttributes(new ArrayList<Attribute>()); getAttributes().add(new Attribute("xmlUrl", xmlUrl.toString()));
}
if (xmlUrl != null) {
getAttributes().add(new Attribute("xmlUrl", xmlUrl.toString())); if (htmlUrl != null) {
} getAttributes().add(new Attribute("htmlUrl", htmlUrl.toString()));
}
if (htmlUrl != null) { }
getAttributes().add(new Attribute("htmlUrl", htmlUrl.toString()));
} /**
} * List of attributes on this outline excluding the "common types" for the specification.
*
/** * @param attributes List of attributes on this outline.
* List of attributes on this outline excluding the "common types" for the specification. */
* public void setAttributes(final List<Attribute> attributes) {
* @param attributes List of attributes on this outline. this.attributes = attributes;
*/ }
public void setAttributes(final List<Attribute> attributes) {
_attributes = attributes; /**
} * List of attributes on this outline excluding the "common types" for the specification.
*
/** * @return List of attributes on this outline.
* List of attributes on this outline excluding the "common types" for the specification. */
* public List<Attribute> getAttributes() {
* @return List of attributes on this outline. if (attributes == null) {
*/ attributes = new ArrayList<Attribute>();
public List<Attribute> getAttributes() { }
if (_attributes == null) {
_attributes = new ArrayList<Attribute>(); return attributes;
} }
return _attributes; /**
} * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on this outline. This
* attribute is mainly necessary for outlines used to edit scripts. If it's not present, the value is false.
/** *
* isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on * @param breakpoint whether a breakpoint is set on this outline.
* this outline. This attribute is mainly necessary for outlines used to edit scripts. If it's */
* not present, the value is false. public void setBreakpoint(final boolean breakpoint) {
* this.breakpoint = breakpoint;
* @param breakpoint whether a breakpoint is set on this outline. }
*/
public void setBreakpoint(final boolean breakpoint) { /**
_breakpoint = breakpoint; * isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on this outline. This
} * attribute is mainly necessary for outlines used to edit scripts. If it's not present, the value is false.
*
/** * @return whether a breakpoint is set on this outline
* isBreakpoint is a string, either "true" or "false", indicating whether a breakpoint is set on */
* this outline. This attribute is mainly necessary for outlines used to edit scripts. If it's public boolean isBreakpoint() {
* not present, the value is false. return breakpoint;
* }
* @return whether a breakpoint is set on this outline
*/ /**
public boolean isBreakpoint() { * (OPML 2) A List of Strings indicating values in the category attribute.
return _breakpoint; *
} * @param categories (OPML 2) A List of Strings indicating values in the category attribute.
*/
/** public void setCategories(final List<String> categories) {
* (OPML 2) A List of Strings indicating values in the category attribute. this.categories = categories;
* }
* @param categories (OPML 2) A List of Strings indicating values in the category attribute.
*/ /**
public void setCategories(final List<String> categories) { * (OPML 2) A List of Strings indicating values in the category attribute.
_categories = categories; *
} * @return (OPML 2) A List of Strings indicating values in the category attribute.
*/
/** public List<String> getCategories() {
* (OPML 2) A List of Strings indicating values in the category attribute. if (categories == null) {
* categories = new ArrayList<String>();
* @return (OPML 2) A List of Strings indicating values in the category attribute. }
*/
public List<String> getCategories() { return categories;
if (_categories == null) { }
_categories = new ArrayList<String>();
} /**
* A list of sub-outlines for this entry.
return _categories; *
} * @param children A list of sub-outlines for this entry.
*/
/** public void setChildren(final List<Outline> children) {
* A list of sub-outlines for this entry. this.children = children;
* }
* @param children A list of sub-outlines for this entry.
*/ /**
public void setChildren(final List<Outline> children) { * A list of sub-outlines for this entry.
_children = children; *
} * @return A list of sub-outlines for this entry.
*/
/** public List<Outline> getChildren() {
* A list of sub-outlines for this entry. if (children == null) {
* children = new ArrayList<Outline>();
* @return A list of sub-outlines for this entry. }
*/
public List<Outline> getChildren() { return children;
if (_children == null) { }
_children = new ArrayList<Outline>();
} /**
* isComment is a string, either "true" or "false", indicating whether the outline is commented or not. By
return _children; * convention if an outline is commented, all subordinate outlines are considered to also be commented. If it's not
} * present, the value is false.
*
/** * @param comment whether the outline is commented
* isComment is a string, either "true" or "false", indicating whether the outline is commented */
* or not. By convention if an outline is commented, all subordinate outlines are considered to public void setComment(final boolean comment) {
* also be commented. If it's not present, the value is false. this.comment = comment;
* }
* @param comment whether the outline is commented
*/ /**
public void setComment(final boolean comment) { * isComment is a string, either "true" or "false", indicating whether the outline is commented or not. By
_comment = comment; * convention if an outline is commented, all subordinate outlines are considered to also be commented. If it's not
} * present, the value is false.
*
/** * @return whether the outline is commented
* isComment is a string, either "true" or "false", indicating whether the outline is commented */
* or not. By convention if an outline is commented, all subordinate outlines are considered to public boolean isComment() {
* also be commented. If it's not present, the value is false. return comment;
* }
* @return whether the outline is commented
*/ /**
public boolean isComment() { * (OPML 2) created is the date-time that the outline node was created.
return _comment; *
} * @param created date-time that the outline node was created.
*/
/** public void setCreated(final Date created) {
* (OPML 2) created is the date-time that the outline node was created. this.created = created;
* }
* @param created date-time that the outline node was created.
*/ /**
public void setCreated(final Date created) { * (OPML 2) created is the date-time that the outline node was created.
_created = created; *
} * @return date-time that the outline node was created.
*/
/** public Date getCreated() {
* (OPML 2) created is the date-time that the outline node was created. return created;
* }
* @return date-time that the outline node was created.
*/ /**
public Date getCreated() { * A convenience method to return the value of the url attribute.
return _created; *
} * @return value of the htmlUrl attribute.
*/
/** public String getUrl() {
* A convenience method to return the value of the url attribute. return getAttributeValue("url");
* }
* @return value of the htmlUrl attribute.
*/ /**
public String getUrl() { * A convenience method to return the value of the htmlUrl attribute.
return getAttributeValue("url"); *
} * @return value of the htmlUrl attribute.
*/
/** public String getHtmlUrl() {
* A convenience method to return the value of the htmlUrl attribute. return getAttributeValue("htmlUrl");
* }
* @return value of the htmlUrl attribute.
*/ public void setModules(final List<Module> modules) {
public String getHtmlUrl() { this.modules = modules;
return getAttributeValue("htmlUrl"); }
}
public List<Module> getModules() {
public void setModules(final List<Module> modules) { if (modules == null) {
_modules = modules; modules = new ArrayList<Module>();
} }
public List<Module> getModules() { return modules;
if (_modules == null) { }
_modules = new ArrayList<Module>();
} /**
* The "text" attribute of the outline.
return _modules; *
} * @param text The "text" attribute of the outline.
*/
/** public void setText(final String text) {
* The "text" attribute of the outline. this.text = text;
* }
* @param text The "text" attribute of the outline.
*/ /**
public void setText(final String text) { * The "text" attribute of the outline.
_text = text; *
} * @return The "text" attribute of the outline.
*/
/** public String getText() {
* The "text" attribute of the outline. return text;
* }
* @return The "text" attribute of the outline.
*/ /**
public String getText() { * The "title" attribute of the outline.
return _text; *
} * @param title The "title" attribute of the outline.
*/
/** public void setTitle(final String title) {
* The "title" attribute of the outline. this.title = title;
* }
* @param title The "title" attribute of the outline.
*/ /**
public void setTitle(final String title) { * The "title" attribute of the outline.
_title = title; *
} * @return The "title" attribute of the outline.
*/
/** public String getTitle() {
* The "title" attribute of the outline. return title;
* }
* @return The "title" attribute of the outline.
*/ /**
public String getTitle() { * The "type" attribute of the outline.
return _title; *
} * @param type The "type" attribute of the outline.
*/
/** public void setType(final String type) {
* The "type" attribute of the outline. this.type = type;
* }
* @param type The "type" attribute of the outline.
*/ /**
public void setType(final String type) { * The "type" attribute of the outline.
_type = type; *
} * @return The "type" attribute of the outline.
*/
/** public String getType() {
* The "type" attribute of the outline. return type;
* }
* @return The "type" attribute of the outline.
*/ /**
public String getType() { * A convenience method to return the value of the xmlUrl attribute.
return _type; *
} * @return value of the xmlUrl attribute.
*/
/** public String getXmlUrl() {
* A convenience method to return the value of the xmlUrl attribute. return getAttributeValue("xmlUrl");
* }
* @return value of the xmlUrl attribute.
*/ /**
public String getXmlUrl() { * Returns the value of an attribute on the outline or null.
return getAttributeValue("xmlUrl"); *
} * @param name name of the attribute.
*/
/** public String getAttributeValue(final String name) {
* Returns the value of an attribute on the outline or null. final List<Attribute> attributes = Collections.synchronizedList(getAttributes());
* for (int i = 0; i < attributes.size(); i++) {
* @param name name of the attribute. final Attribute a = attributes.get(i);
*/
public String getAttributeValue(final String name) { if (a.getName() != null && a.getName().equals(name)) {
final List<Attribute> attributes = Collections.synchronizedList(getAttributes()); return a.getValue();
for (int i = 0; i < attributes.size(); i++) { }
final Attribute a = attributes.get(i); }
return null;
if (a.getName() != null && a.getName().equals(name)) { }
return a.getValue();
} @Override
} public Object clone() {
return null;
} final Outline o = new Outline();
o.setBreakpoint(isBreakpoint());
@Override o.setCategories(new ArrayList<String>(getCategories()));
public Object clone() { o.setComment(isComment());
o.setCreated(created != null ? (Date) created.clone() : null);
final Outline o = new Outline(); o.setModules(new ArrayList<Module>(getModules()));
o.setBreakpoint(isBreakpoint()); o.setText(getText());
o.setCategories(new ArrayList<String>(getCategories())); o.setTitle(getTitle());
o.setComment(isComment()); o.setType(getType());
o.setCreated(_created != null ? (Date) _created.clone() : null);
o.setModules(new ArrayList<Module>(getModules())); final ArrayList<Outline> children = new ArrayList<Outline>();
o.setText(getText()); for (int i = 0; i < getChildren().size(); i++) {
o.setTitle(getTitle()); children.add((Outline) this.children.get(i).clone());
o.setType(getType()); }
o.setChildren(children);
final ArrayList<Outline> children = new ArrayList<Outline>();
for (int i = 0; i < getChildren().size(); i++) { final ArrayList<Attribute> attributes = new ArrayList<Attribute>();
children.add((Outline) _children.get(i).clone()); for (int i = 0; i < getAttributes().size(); i++) {
} attributes.add((Attribute) this.attributes.get(i).clone());
o.setChildren(children); }
o.setAttributes(attributes);
final ArrayList<Attribute> attributes = new ArrayList<Attribute>();
for (int i = 0; i < getAttributes().size(); i++) { return o;
attributes.add((Attribute) _attributes.get(i).clone()); }
}
o.setAttributes(attributes); @Override
public boolean equals(final Object obj) {
return o; return new EqualsBean(Outline.class, this).beanEquals(obj);
} }
@Override @Override
public boolean equals(final Object obj) { public int hashCode() {
final EqualsBean eBean = new EqualsBean(Outline.class, this); return new EqualsBean(Outline.class, this).beanHashCode();
}
return eBean.beanEquals(obj);
} @Override
public String toString() {
@Override return new ToStringBean(Outline.class, this).toString();
public int hashCode() { }
final EqualsBean equals = new EqualsBean(Outline.class, this);
}
return equals.beanHashCode();
}
@Override
public String toString() {
final ToStringBean tsBean = new ToStringBean(Outline.class, this);
return tsBean.toString();
}
}

View file

@ -1,365 +1,349 @@
/* /*
* ConverterForOPML10.java * ConverterForOPML10.java
* *
* Created on April 25, 2006, 1:26 AM * Created on April 25, 2006, 1:26 AM
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.rometools.opml.feed.synd.impl; package com.rometools.opml.feed.synd.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Stack; import java.util.Stack;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.rometools.opml.feed.opml.Attribute; import com.rometools.opml.feed.opml.Attribute;
import com.rometools.opml.feed.opml.Opml; import com.rometools.opml.feed.opml.Opml;
import com.rometools.opml.feed.opml.Outline; import com.rometools.opml.feed.opml.Outline;
import com.rometools.rome.feed.WireFeed; import com.rometools.rome.feed.WireFeed;
import com.rometools.rome.feed.synd.Converter; import com.rometools.rome.feed.synd.Converter;
import com.rometools.rome.feed.synd.SyndCategory; import com.rometools.rome.feed.synd.SyndCategory;
import com.rometools.rome.feed.synd.SyndCategoryImpl; import com.rometools.rome.feed.synd.SyndCategoryImpl;
import com.rometools.rome.feed.synd.SyndContent; import com.rometools.rome.feed.synd.SyndContent;
import com.rometools.rome.feed.synd.SyndContentImpl; import com.rometools.rome.feed.synd.SyndContentImpl;
import com.rometools.rome.feed.synd.SyndEntry; import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndEntryImpl; import com.rometools.rome.feed.synd.SyndEntryImpl;
import com.rometools.rome.feed.synd.SyndFeed; import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.feed.synd.SyndLink; import com.rometools.rome.feed.synd.SyndLink;
import com.rometools.rome.feed.synd.SyndLinkImpl; import com.rometools.rome.feed.synd.SyndLinkImpl;
import com.rometools.rome.feed.synd.SyndPerson; import com.rometools.rome.feed.synd.SyndPerson;
import com.rometools.rome.feed.synd.SyndPersonImpl; import com.rometools.rome.feed.synd.SyndPersonImpl;
/** /**
* * @author cooper
* @author cooper */
*/ public class ConverterForOPML10 implements Converter {
public class ConverterForOPML10 implements Converter {
private static final Logger LOG = LoggerFactory.getLogger(ConverterForOPML10.class);
private static final Logger LOG = LoggerFactory.getLogger(ConverterForOPML10.class);
public static final String URI_TREE = "urn:rome.tree";
public static final String URI_TREE = "urn:rome.tree"; public static final String URI_ATTRIBUTE = "urn:rome.attribute#";
public static final String URI_ATTRIBUTE = "urn:rome.attribute#";
protected void addOwner(final Opml opml, final SyndFeed syndFeed) {
/** Creates a new instance of ConverterForOPML10 */ if (opml.getOwnerEmail() != null || opml.getOwnerName() != null) {
public ConverterForOPML10() { final List<SyndPerson> authors = new ArrayList<SyndPerson>();
super(); final SyndPerson person = new SyndPersonImpl();
} person.setEmail(opml.getOwnerEmail());
person.setName(opml.getOwnerName());
protected void addOwner(final Opml opml, final SyndFeed syndFeed) { authors.add(person);
if (opml.getOwnerEmail() != null || opml.getOwnerName() != null) { syndFeed.setAuthors(authors);
final List<SyndPerson> authors = new ArrayList<SyndPerson>(); }
final SyndPerson person = new SyndPersonImpl(); }
person.setEmail(opml.getOwnerEmail());
person.setName(opml.getOwnerName()); /**
authors.add(person); * Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl.
syndFeed.setAuthors(authors); * <p>
} * It assumes the given SyndFeedImpl has no properties set.
} * <p>
*
/** * @param feed real feed to copy/convert.
* Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl. * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed.
* <p> */
* It assumes the given SyndFeedImpl has no properties set. @Override
* <p> public void copyInto(final WireFeed feed, final SyndFeed syndFeed) {
* final Opml opml = (Opml) feed;
* @param feed real feed to copy/convert. syndFeed.setTitle(opml.getTitle());
* @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real addOwner(opml, syndFeed);
* feed. syndFeed.setPublishedDate(opml.getModified() != null ? opml.getModified() : opml.getCreated());
*/ syndFeed.setFeedType(opml.getFeedType());
@Override syndFeed.setModules(opml.getModules());
public void copyInto(final WireFeed feed, final SyndFeed syndFeed) { syndFeed.setFeedType(getType());
final Opml opml = (Opml) feed;
syndFeed.setTitle(opml.getTitle()); createEntries(new Stack<Integer>(), syndFeed.getEntries(), opml.getOutlines());
addOwner(opml, syndFeed); }
syndFeed.setPublishedDate(opml.getModified() != null ? opml.getModified() : opml.getCreated());
syndFeed.setFeedType(opml.getFeedType()); protected void createEntries(final Stack<Integer> context, final List<SyndEntry> allEntries, final List<Outline> outlines) {
syndFeed.setModules(opml.getModules()); final List<Outline> so = Collections.synchronizedList(outlines);
syndFeed.setFeedType(getType());
for (int i = 0; i < so.size(); i++) {
createEntries(new TreeContext(), syndFeed.getEntries(), opml.getOutlines()); createEntry(context, allEntries, so.get(i));
} }
}
protected void createEntries(final TreeContext context, final List<SyndEntry> allEntries, final List<Outline> outlines) {
final List<Outline> so = Collections.synchronizedList(outlines); protected SyndEntry createEntry(final Stack<Integer> context, final List<SyndEntry> allEntries, final Outline outline) {
final SyndEntry entry = new SyndEntryImpl();
for (int i = 0; i < so.size(); i++) {
createEntry(context, allEntries, so.get(i)); if (outline.getType() != null && outline.getType().equals("rss")) {
} entry.setLink(outline.getHtmlUrl() != null ? outline.getHtmlUrl() : outline.getXmlUrl());
} } else if (outline.getType() != null && outline.getType().equals("link")) {
entry.setLink(outline.getUrl());
protected SyndEntry createEntry(final TreeContext context, final List<SyndEntry> allEntries, final Outline outline) { }
final SyndEntry entry = new SyndEntryImpl();
if (outline.getHtmlUrl() != null) {
if (outline.getType() != null && outline.getType().equals("rss")) { final SyndLink link = new SyndLinkImpl();
entry.setLink(outline.getHtmlUrl() != null ? outline.getHtmlUrl() : outline.getXmlUrl()); link.setRel("alternate");
} else if (outline.getType() != null && outline.getType().equals("link")) { link.setType("text/html");
entry.setLink(outline.getUrl()); link.setHref(outline.getHtmlUrl());
} entry.getLinks().add(link);
entry.setLink(outline.getHtmlUrl());
if (outline.getHtmlUrl() != null) { }
final SyndLink link = new SyndLinkImpl();
link.setRel("alternate"); if (outline.getXmlUrl() != null && outline.getType() != null && outline.getType().equalsIgnoreCase("rss")) {
link.setType("text/html"); final SyndLink link = new SyndLinkImpl();
link.setHref(outline.getHtmlUrl()); link.setRel("alternate");
entry.getLinks().add(link); link.setType("application/rss+xml");
entry.setLink(outline.getHtmlUrl()); link.setHref(outline.getXmlUrl());
} entry.getLinks().add(link);
if (outline.getXmlUrl() != null && outline.getType() != null && outline.getType().equalsIgnoreCase("rss")) { if (entry.getLink() == null) {
final SyndLink link = new SyndLinkImpl(); entry.setLink(outline.getXmlUrl());
link.setRel("alternate"); }
link.setType("application/rss+xml"); }
link.setHref(outline.getXmlUrl());
entry.getLinks().add(link); if (outline.getXmlUrl() != null && outline.getType() != null && outline.getType().equalsIgnoreCase("atom")) {
final SyndLink link = new SyndLinkImpl();
if (entry.getLink() == null) { link.setRel("alternate");
entry.setLink(outline.getXmlUrl()); link.setType("application/atom+xml");
} link.setHref(outline.getXmlUrl());
} entry.getLinks().add(link);
if (outline.getXmlUrl() != null && outline.getType() != null && outline.getType().equalsIgnoreCase("atom")) { if (entry.getLink() == null) {
final SyndLink link = new SyndLinkImpl(); entry.setLink(outline.getXmlUrl());
link.setRel("alternate"); }
link.setType("application/atom+xml"); }
link.setHref(outline.getXmlUrl());
entry.getLinks().add(link); if (outline.getType() != null && outline.getType().equals("rss")) {
entry.setTitle(outline.getTitle());
if (entry.getLink() == null) { } else {
entry.setLink(outline.getXmlUrl()); entry.setTitle(outline.getText());
} }
}
if (outline.getText() == null && entry.getTitle() != null) {
if (outline.getType() != null && outline.getType().equals("rss")) { final SyndContent c = new SyndContentImpl();
entry.setTitle(outline.getTitle()); c.setValue(outline.getText());
} else { entry.setDescription(c);
entry.setTitle(outline.getText()); }
}
entry.setPublishedDate(outline.getCreated());
if (outline.getText() == null && entry.getTitle() != null) {
final SyndContent c = new SyndContentImpl(); final String nodeName = "node." + outline.hashCode();
c.setValue(outline.getText());
entry.setDescription(c); final SyndCategory cat = new TreeCategoryImpl();
} cat.setTaxonomyUri(URI_TREE);
cat.setName(nodeName);
entry.setPublishedDate(outline.getCreated()); entry.getCategories().add(cat);
final String nodeName = "node." + outline.hashCode(); if (!context.isEmpty()) {
final Integer parent = context.peek();
final SyndCategory cat = new TreeCategoryImpl(); final SyndCategory pcat = new TreeCategoryImpl();
cat.setTaxonomyUri(URI_TREE); pcat.setTaxonomyUri(URI_TREE);
cat.setName(nodeName); pcat.setName("parent." + parent);
entry.getCategories().add(cat); entry.getCategories().add(pcat);
}
if (!context.isEmpty()) {
final Integer parent = context.peek(); final List<Attribute> attributes = Collections.synchronizedList(outline.getAttributes());
final SyndCategory pcat = new TreeCategoryImpl();
pcat.setTaxonomyUri(URI_TREE); for (int i = 0; i < attributes.size(); i++) {
pcat.setName("parent." + parent); final Attribute a = attributes.get(i);
entry.getCategories().add(pcat); final SyndCategory acat = new SyndCategoryImpl();
} acat.setName(a.getValue());
acat.setTaxonomyUri(URI_ATTRIBUTE + a.getName());
final List<Attribute> attributes = Collections.synchronizedList(outline.getAttributes()); entry.getCategories().add(acat);
}
for (int i = 0; i < attributes.size(); i++) {
final Attribute a = attributes.get(i); entry.setModules(outline.getModules());
final SyndCategory acat = new SyndCategoryImpl(); allEntries.add(entry);
acat.setName(a.getValue()); context.push(new Integer(outline.hashCode()));
acat.setTaxonomyUri(URI_ATTRIBUTE + a.getName()); createEntries(context, allEntries, outline.getChildren());
entry.getCategories().add(acat); context.pop();
}
return entry;
entry.setModules(outline.getModules()); }
allEntries.add(entry);
context.push(new Integer(outline.hashCode())); /**
createEntries(context, allEntries, outline.getChildren()); * Creates real feed with a deep copy/conversion of the values of a SyndFeedImpl.
context.pop(); * <p>
*
return entry; * @param syndFeed SyndFeedImpl to copy/convert value from.
} * @return a real feed with copied/converted values of the SyndFeedImpl.
*/
/** @Override
* Creates real feed with a deep copy/conversion of the values of a SyndFeedImpl. public WireFeed createRealFeed(final SyndFeed syndFeed) {
* <p>
* final List<SyndEntry> entries = Collections.synchronizedList(syndFeed.getEntries());
* @param syndFeed SyndFeedImpl to copy/convert value from.
* @return a real feed with copied/converted values of the SyndFeedImpl. final HashMap<String, Outline> entriesByNode = new HashMap<String, Outline>();
*
*/ // this will hold entries that we can't parent the first time.
@Override final ArrayList<OutlineHolder> doAfterPass = new ArrayList<OutlineHolder>();
public WireFeed createRealFeed(final SyndFeed syndFeed) {
// this holds root level outlines;
final List<SyndEntry> entries = Collections.synchronizedList(syndFeed.getEntries()); final ArrayList<Outline> root = new ArrayList<Outline>();
final HashMap<String, Outline> entriesByNode = new HashMap<String, Outline>(); for (int i = 0; i < entries.size(); i++) {
final SyndEntry entry = entries.get(i);
// this will hold entries that we can't parent the first time. final Outline o = new Outline();
final ArrayList<OutlineHolder> doAfterPass = new ArrayList<OutlineHolder>();
final List<SyndCategory> cats = Collections.synchronizedList(entry.getCategories());
// this holds root level outlines; boolean parentFound = false;
final ArrayList<Outline> root = new ArrayList<Outline>(); final StringBuffer category = new StringBuffer();
for (int i = 0; i < entries.size(); i++) { for (int j = 0; j < cats.size(); j++) {
final SyndEntry entry = entries.get(i); final SyndCategory cat = cats.get(j);
final Outline o = new Outline();
if (cat.getTaxonomyUri() != null && cat.getTaxonomyUri().equals(URI_TREE)) {
final List<SyndCategory> cats = Collections.synchronizedList(entry.getCategories()); final String nodeVal = cat.getName().substring(cat.getName().lastIndexOf("."), cat.getName().length());
boolean parentFound = false;
final StringBuffer category = new StringBuffer(); if (cat.getName().startsWith("node.")) {
entriesByNode.put(nodeVal, o);
for (int j = 0; j < cats.size(); j++) { } else if (cat.getName().startsWith("parent.")) {
final SyndCategory cat = cats.get(j); parentFound = true;
if (cat.getTaxonomyUri() != null && cat.getTaxonomyUri().equals(URI_TREE)) { final Outline parent = entriesByNode.get(nodeVal);
final String nodeVal = cat.getName().substring(cat.getName().lastIndexOf("."), cat.getName().length());
if (parent != null) {
if (cat.getName().startsWith("node.")) { parent.getChildren().add(o);
entriesByNode.put(nodeVal, o); } else {
} else if (cat.getName().startsWith("parent.")) { doAfterPass.add(new OutlineHolder(o, nodeVal));
parentFound = true; }
}
final Outline parent = entriesByNode.get(nodeVal); } else if (cat.getTaxonomyUri() != null && cat.getTaxonomyUri().startsWith(URI_ATTRIBUTE)) {
final String name = cat.getTaxonomyUri().substring(cat.getTaxonomyUri().indexOf("#") + 1, cat.getTaxonomyUri().length());
if (parent != null) { o.getAttributes().add(new Attribute(name, cat.getName()));
parent.getChildren().add(o); } else {
} else { if (category.length() > 0) {
doAfterPass.add(new OutlineHolder(o, nodeVal)); category.append(", ");
} }
}
} else if (cat.getTaxonomyUri() != null && cat.getTaxonomyUri().startsWith(URI_ATTRIBUTE)) { category.append(cat.getName());
final String name = cat.getTaxonomyUri().substring(cat.getTaxonomyUri().indexOf("#") + 1, cat.getTaxonomyUri().length()); }
o.getAttributes().add(new Attribute(name, cat.getName())); }
} else {
if (category.length() > 0) { if (!parentFound) {
category.append(", "); root.add(o);
} }
category.append(cat.getName()); if (category.length() > 0) {
} o.getAttributes().add(new Attribute("category", category.toString()));
} }
if (!parentFound) { final List<SyndLink> links = Collections.synchronizedList(entry.getLinks());
root.add(o); // final String entryLink = entry.getLink();
}
for (int j = 0; j < links.size(); j++) {
if (category.length() > 0) { final SyndLink link = links.get(j);
o.getAttributes().add(new Attribute("category", category.toString()));
} // if(link.getHref().equals(entryLink)) {
if (link.getType() != null && link.getRel() != null && link.getRel().equals("alternate")
final List<SyndLink> links = Collections.synchronizedList(entry.getLinks()); && (link.getType().equals("application/rss+xml") || link.getType().equals("application/atom+xml"))) {
// final String entryLink = entry.getLink(); o.setType("rss");
for (int j = 0; j < links.size(); j++) { if (o.getXmlUrl() == null) {
final SyndLink link = links.get(j); o.getAttributes().add(new Attribute("xmlUrl", link.getHref()));
}
// if(link.getHref().equals(entryLink)) { } else if (link.getType() != null && link.getType().equals("text/html")) {
if (link.getType() != null && link.getRel() != null && link.getRel().equals("alternate") if (o.getHtmlUrl() == null) {
&& (link.getType().equals("application/rss+xml") || link.getType().equals("application/atom+xml"))) { o.getAttributes().add(new Attribute("htmlUrl", link.getHref()));
o.setType("rss"); }
} else {
if (o.getXmlUrl() == null) { o.setType(link.getType());
o.getAttributes().add(new Attribute("xmlUrl", link.getHref())); }
}
} else if (link.getType() != null && link.getType().equals("text/html")) { // }
if (o.getHtmlUrl() == null) { }
o.getAttributes().add(new Attribute("htmlUrl", link.getHref()));
} if (o.getType() == null || o.getType().equals("link")) {
} else { o.setText(entry.getTitle());
o.setType(link.getType());
} } else {
o.setTitle(entry.getTitle());
// } }
}
if (o.getText() == null && entry.getDescription() != null) {
if (o.getType() == null || o.getType().equals("link")) { o.setText(entry.getDescription().getValue());
o.setText(entry.getTitle()); }
}
} else {
o.setTitle(entry.getTitle()); // Do back and parenting for things we missed.
} for (int i = 0; i < doAfterPass.size(); i++) {
final OutlineHolder o = doAfterPass.get(i);
if (o.getText() == null && entry.getDescription() != null) { final Outline parent = entriesByNode.get(o.parent);
o.setText(entry.getDescription().getValue());
} if (parent == null) {
} root.add(o.outline);
LOG.warn("Unable to find parent node: {}", o.parent);
// Do back and parenting for things we missed. } else {
for (int i = 0; i < doAfterPass.size(); i++) { parent.getChildren().add(o.outline);
final OutlineHolder o = doAfterPass.get(i); }
final Outline parent = entriesByNode.get(o.parent); }
if (parent == null) { final Opml opml = new Opml();
root.add(o.outline); opml.setFeedType(getType());
LOG.warn("Unable to find parent node: {}", o.parent); opml.setCreated(syndFeed.getPublishedDate());
} else { opml.setTitle(syndFeed.getTitle());
parent.getChildren().add(o.outline);
} final List<SyndPerson> authors = Collections.synchronizedList(syndFeed.getAuthors());
}
for (int i = 0; i < authors.size(); i++) {
final Opml opml = new Opml(); final SyndPerson p = authors.get(i);
opml.setFeedType(getType());
opml.setCreated(syndFeed.getPublishedDate()); if (syndFeed.getAuthor() == null || syndFeed.getAuthor().equals(p.getName())) {
opml.setTitle(syndFeed.getTitle()); opml.setOwnerName(p.getName());
opml.setOwnerEmail(p.getEmail());
final List<SyndPerson> authors = Collections.synchronizedList(syndFeed.getAuthors()); opml.setOwnerId(p.getUri());
}
for (int i = 0; i < authors.size(); i++) { }
final SyndPerson p = authors.get(i);
opml.setOutlines(root);
if (syndFeed.getAuthor() == null || syndFeed.getAuthor().equals(p.getName())) {
opml.setOwnerName(p.getName()); return opml;
opml.setOwnerEmail(p.getEmail()); }
opml.setOwnerId(p.getUri());
} /**
} * Returns the type (version) of the real feed this converter handles.
*
opml.setOutlines(root); * @return the real feed type.
* @see WireFeed for details on the format of this string.
return opml; */
} @Override
public String getType() {
/** return "opml_1.0";
* Returns the type (version) of the real feed this converter handles. }
* <p>
* private static class OutlineHolder {
* @return the real feed type.
* @see WireFeed for details on the format of this string. private final Outline outline;
* <p> private final String parent;
*/
@Override public OutlineHolder(final Outline outline, final String parent) {
public String getType() { this.outline = outline;
return "opml_1.0"; this.parent = parent;
} }
private static class OutlineHolder { }
Outline outline;
String parent; }
public OutlineHolder(final Outline outline, final String parent) {
this.outline = outline;
this.parent = parent;
}
}
private static class TreeContext extends Stack<Integer> {
private static final long serialVersionUID = 1L;
TreeContext() {
super();
}
}
}

View file

@ -1,67 +1,50 @@
/* package com.rometools.opml.feed.synd.impl;
* ConverterForOPML20.java
* import com.rometools.rome.feed.WireFeed;
* Created on April 25, 2006, 5:29 PM import com.rometools.rome.feed.synd.SyndFeed;
*
* To change this template, choose Tools | Template Manager /**
* and open the template in the editor. * @author cooper
*/ */
package com.rometools.opml.feed.synd.impl; public class ConverterForOPML20 extends ConverterForOPML10 {
import com.rometools.rome.feed.WireFeed; /**
import com.rometools.rome.feed.synd.SyndFeed; * Returns the type (version) of the real feed this converter handles.
* <p>
/** *
* * @return the real feed type.
* @author cooper * @see WireFeed for details on the format of this string.
*/ * <p>
public class ConverterForOPML20 extends ConverterForOPML10 { */
/** Creates a new instance of ConverterForOPML20 */ @Override
public ConverterForOPML20() { public String getType() {
super(); return "opml_2.0";
} }
/** /**
* Returns the type (version) of the real feed this converter handles. * Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl.
* <p> * <p>
* * It assumes the given SyndFeedImpl has no properties set.
* @return the real feed type. * <p>
* @see WireFeed for details on the format of this string. *
* <p> * @param feed real feed to copy/convert.
*/ * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed.
@Override */
public String getType() { @Override
return "opml_2.0"; public void copyInto(final WireFeed feed, final SyndFeed syndFeed) {
} super.copyInto(feed, syndFeed);
}
/**
* Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl. /**
* <p> * Creates real feed with a deep copy/conversion of the values of a SyndFeedImpl.
* It assumes the given SyndFeedImpl has no properties set. * <p>
* <p> *
* * @param syndFeed SyndFeedImpl to copy/convert value from.
* @param feed real feed to copy/convert. * @return a real feed with copied/converted values of the SyndFeedImpl.
* @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real */
* feed. @Override
*/ public WireFeed createRealFeed(final SyndFeed syndFeed) {
@Override return super.createRealFeed(syndFeed);
public void copyInto(final WireFeed feed, final SyndFeed syndFeed) { }
super.copyInto(feed, syndFeed);
} }
/**
* Creates real feed with a deep copy/conversion of the values of a SyndFeedImpl.
* <p>
*
* @param syndFeed SyndFeedImpl to copy/convert value from.
* @return a real feed with copied/converted values of the SyndFeedImpl.
*/
@Override
public WireFeed createRealFeed(final SyndFeed syndFeed) {
WireFeed retValue;
retValue = super.createRealFeed(syndFeed);
return retValue;
}
}

View file

@ -1,38 +1,23 @@
/* package com.rometools.opml.feed.synd.impl;
* TreeCategoryImpl.java
* import com.rometools.rome.feed.synd.SyndCategory;
* Created on April 27, 2006, 3:44 AM import com.rometools.rome.feed.synd.SyndCategoryImpl;
*
* To change this template, choose Tools | Template Manager /**
* and open the template in the editor. * @author cooper
*/ */
public class TreeCategoryImpl extends SyndCategoryImpl {
package com.rometools.opml.feed.synd.impl;
private static final long serialVersionUID = 1L;
import com.rometools.rome.feed.synd.SyndCategory;
import com.rometools.rome.feed.synd.SyndCategoryImpl; @Override
public boolean equals(final Object o) {
/** final SyndCategory c = (SyndCategory) o;
* if (c.getTaxonomyUri() != null && c.getTaxonomyUri().equals(getTaxonomyUri())) {
* @author cooper return true;
*/ } else {
public class TreeCategoryImpl extends SyndCategoryImpl { return false;
}
private static final long serialVersionUID = 1L; }
/** Creates a new instance of TreeCategoryImpl */ }
public TreeCategoryImpl() {
super();
}
@Override
public boolean equals(final Object o) {
final SyndCategory c = (SyndCategory) o;
if (c.getTaxonomyUri() != null && c.getTaxonomyUri().equals(getTaxonomyUri())) {
return true;
} else {
return false;
}
}
}

View file

@ -35,11 +35,10 @@ import com.rometools.rome.io.impl.BaseWireFeedGenerator;
import com.rometools.rome.io.impl.DateParser; import com.rometools.rome.io.impl.DateParser;
/** /**
*
* @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a> * @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a>
*/ */
public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGenerator { public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGenerator {
/** Creates a new instance of Opml10Generator */
public OPML10Generator() { public OPML10Generator() {
super("opml_1.0"); super("opml_1.0");
} }
@ -50,16 +49,16 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe
/** /**
* Creates an XML document (JDOM) for the given feed bean. * Creates an XML document (JDOM) for the given feed bean.
* <p>
* *
* @param feed the feed bean to generate the XML document from. * @param feed the feed bean to generate the XML document from.
* @return the generated XML document (JDOM). * @return the generated XML document (JDOM).
* @throws IllegalArgumentException thrown if the type of the given feed bean does not match * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the
* with the type of the WireFeedGenerator. * WireFeedGenerator.
* @throws FeedException thrown if the XML Document could not be created. * @throws FeedException thrown if the XML Document could not be created.
*/ */
@Override @Override
public Document generate(final WireFeed feed) throws IllegalArgumentException, FeedException { public Document generate(final WireFeed feed) throws IllegalArgumentException, FeedException {
if (!(feed instanceof Opml)) { if (!(feed instanceof Opml)) {
throw new IllegalArgumentException("Not an OPML file"); throw new IllegalArgumentException("Not an OPML file");
} }
@ -88,9 +87,7 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe
if (target == null || name == null || value == null) { if (target == null || name == null || value == null) {
return false; return false;
} }
target.setAttribute(name, value.toString()); target.setAttribute(name, value.toString());
return true; return true;
} }

View file

@ -37,14 +37,12 @@ import com.rometools.rome.io.impl.BaseWireFeedParser;
import com.rometools.rome.io.impl.DateParser; import com.rometools.rome.io.impl.DateParser;
/** /**
*
* @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a> * @author <a href="mailto:cooper@screaming-penguin.com">Robert "kebernet" Cooper</a>
*/ */
public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser { public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
private static Logger LOG = LoggerFactory.getLogger(OPML10Parser.class); private static Logger LOG = LoggerFactory.getLogger(OPML10Parser.class);
/** Creates a new instance of Opml10Parser */
public OPML10Parser() { public OPML10Parser() {
super("opml_1.0", null); super("opml_1.0", null);
} }
@ -111,7 +109,6 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
opml.setWindowBottom(readInteger(head.getChildText("windowBottom"))); opml.setWindowBottom(readInteger(head.getChildText("windowBottom")));
} catch (final NumberFormatException nfe) { } catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse windowBottom", nfe); LOG.warn("Unable to parse windowBottom", nfe);
if (validate) { if (validate) {
throw new FeedException("Unable to parse windowBottom", nfe); throw new FeedException("Unable to parse windowBottom", nfe);
} }
@ -121,13 +118,15 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
} catch (final NumberFormatException nfe) { } catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse windowLeft", nfe); LOG.warn("Unable to parse windowLeft", nfe);
if (validate) {
throw new FeedException("Unable to parse windowLeft", nfe);
}
} }
try { try {
opml.setWindowRight(readInteger(head.getChildText("windowRight"))); opml.setWindowRight(readInteger(head.getChildText("windowRight")));
} catch (final NumberFormatException nfe) { } catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse windowRight", nfe); LOG.warn("Unable to parse windowRight", nfe);
if (validate) { if (validate) {
throw new FeedException("Unable to parse windowRight", nfe); throw new FeedException("Unable to parse windowRight", nfe);
} }
@ -137,7 +136,6 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
opml.setWindowLeft(readInteger(head.getChildText("windowLeft"))); opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
} catch (final NumberFormatException nfe) { } catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse windowLeft", nfe); LOG.warn("Unable to parse windowLeft", nfe);
if (validate) { if (validate) {
throw new FeedException("Unable to parse windowLeft", nfe); throw new FeedException("Unable to parse windowLeft", nfe);
} }
@ -147,7 +145,6 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
opml.setWindowTop(readInteger(head.getChildText("windowTop"))); opml.setWindowTop(readInteger(head.getChildText("windowTop")));
} catch (final NumberFormatException nfe) { } catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse windowTop", nfe); LOG.warn("Unable to parse windowTop", nfe);
if (validate) { if (validate) {
throw new FeedException("Unable to parse windowTop", nfe); throw new FeedException("Unable to parse windowTop", nfe);
} }
@ -157,7 +154,6 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
opml.setExpansionState(readIntArray(head.getChildText("expansionState"))); opml.setExpansionState(readIntArray(head.getChildText("expansionState")));
} catch (final NumberFormatException nfe) { } catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse expansionState", nfe); LOG.warn("Unable to parse expansionState", nfe);
if (validate) { if (validate) {
throw new FeedException("Unable to parse expansionState", nfe); throw new FeedException("Unable to parse expansionState", nfe);
} }

View file

@ -1,11 +1,3 @@
/*
* OPML20Generator.java
*
* Created on April 25, 2006, 5:31 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.rometools.opml.io.impl; package com.rometools.opml.io.impl;
import java.util.Locale; import java.util.Locale;
@ -20,21 +12,18 @@ import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.impl.DateParser; import com.rometools.rome.io.impl.DateParser;
/** /**
*
* @author cooper * @author cooper
*/ */
public class OPML20Generator extends OPML10Generator { public class OPML20Generator extends OPML10Generator {
/** Creates a new instance of OPML20Generator */
public OPML20Generator() { public OPML20Generator() {
} }
/** /**
* Returns the type of feed the generator creates. * Returns the type of feed the generator creates.
* <p>
* *
* @return the type of feed the generator creates. * @return the type of feed the generator creates.
* @see WireFeed for details on the format of this string. * @see WireFeed for details on the format of this string.
* <p>
*/ */
@Override @Override
public String getType() { public String getType() {
@ -43,47 +32,43 @@ public class OPML20Generator extends OPML10Generator {
/** /**
* Creates an XML document (JDOM) for the given feed bean. * Creates an XML document (JDOM) for the given feed bean.
* <p>
* *
* @param feed the feed bean to generate the XML document from. * @param feed the feed bean to generate the XML document from.
* @return the generated XML document (JDOM). * @return the generated XML document (JDOM).
* @throws IllegalArgumentException thrown if the type of the given feed bean does not match * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the
* with the type of the WireFeedGenerator. * WireFeedGenerator.
* @throws FeedException thrown if the XML Document could not be created. * @throws FeedException thrown if the XML Document could not be created.
*/ */
@Override @Override
public Document generate(final WireFeed feed) throws IllegalArgumentException, FeedException { public Document generate(final WireFeed feed) throws IllegalArgumentException, FeedException {
Document retValue; final Document retValue = super.generate(feed);
retValue = super.generate(feed);
retValue.getRootElement().setAttribute("version", "2.0"); retValue.getRootElement().setAttribute("version", "2.0");
return retValue; return retValue;
} }
@Override @Override
protected Element generateHead(final Opml opml) { protected Element generateHead(final Opml opml) {
Element retValue;
retValue = super.generateHead(opml);
final Element docs = new Element("docs"); final Element docs = new Element("docs");
docs.setText(opml.getDocs()); docs.setText(opml.getDocs());
retValue.addContent(docs);
final Element retValue = super.generateHead(opml);
retValue.addContent(docs);
return retValue; return retValue;
} }
@Override @Override
protected Element generateOutline(final Outline outline) { protected Element generateOutline(final Outline outline) {
Element retValue;
retValue = super.generateOutline(outline); final Element retValue = super.generateOutline(outline);
if (outline.getCreated() != null) { if (outline.getCreated() != null) {
retValue.setAttribute("created", DateParser.formatRFC822(outline.getCreated(), Locale.US)); retValue.setAttribute("created", DateParser.formatRFC822(outline.getCreated(), Locale.US));
} }
return retValue; return retValue;
} }
} }