⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 baseentry.java

📁 google gdata API 很好用的API
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }    Link editLink = getEditLink();    if (editLink == null) {      throw new UnsupportedOperationException("Entry cannot be deleted");    }    URL editUrl = new URL(editLink.getHref());    state.service.delete(editUrl);  }  /**   * Generates XML in the Atom format.   *   * @param   w   *            Output writer.   *   * @param   extProfile   *            Extension profile.   *   * @throws  IOException   */  public void generateAtom(XmlWriter w,                           ExtensionProfile extProfile) throws IOException {    Vector<XmlWriter.Namespace> nsDecls =      new Vector<XmlWriter.Namespace>(namespaceDeclsAtom);    nsDecls.addAll(extProfile.getNamespaceDecls());    generateStartElement(w, Namespaces.atomNs, "entry", null, nsDecls);    if (state.id != null) {      w.simpleElement(Namespaces.atomNs, "id", null, state.id);    }    if (state.published != null) {      w.simpleElement(Namespaces.atomNs, "published", null,                      state.published.toString());    }    if (state.updated != null) {      w.simpleElement(Namespaces.atomNs, "updated", null,          state.updated.toString());    }    if (isDraft()) {      w.startElement(Namespaces.atomPubNs, "control", null, null);      w.simpleElement(Namespaces.atomPubNs, "draft", null, "yes");      w.endElement();    }    w.startRepeatingElement();    for (Category cat: state.categories) {      cat.generateAtom(w);    }    w.endRepeatingElement();    if (state.title != null) {      state.title.generateAtom(w, "title");    }    if (state.summary != null) {      state.summary.generateAtom(w, "summary");    }    if (state.rights != null) {      state.rights.generateAtom(w, "rights");    }    if (state.content != null) {      state.content.generateAtom(w);    }    w.startRepeatingElement();    for (Link link: state.links) {      link.generateAtom(w, extProfile);    }    w.endRepeatingElement();    w.startRepeatingElement();    for (Person author: state.authors) {      author.generateAtom(extProfile, w, "author");    }    w.endRepeatingElement();    w.startRepeatingElement();    for (Person contributor: state.contributors) {      contributor.generateAtom(extProfile, w, "contributor");    }    w.endRepeatingElement();    if (state.source != null) {      state.source.generateAtom(w, extProfile);    }    // Invoke ExtensionPoint.    generateExtensions(w, extProfile);    w.endElement(Namespaces.atomNs, "entry");  }  /**   * Generates XML in the RSS format.   *   * @param   w   *            Output writer.   *   * @param   extProfile   *            Extension profile.   *   * @throws  IOException   */  public void generateRss(XmlWriter w,                          ExtensionProfile extProfile) throws IOException {    Vector<XmlWriter.Namespace> nsDecls =      new Vector<XmlWriter.Namespace>(namespaceDeclsRss);    nsDecls.addAll(extProfile.getNamespaceDecls());    generateStartElement(w, Namespaces.rssNs, "item", null, nsDecls);    if (state.id != null) {      List<Attribute> attrs = new ArrayList<Attribute>(1);      attrs.add(new Attribute("isPermaLink", "false"));      w.simpleElement(Namespaces.rssNs, "guid", attrs, state.id);    }    String lang = null;    if (state.content != null) {      lang = state.content.getLang();    }    if (lang == null && state.summary != null) {      lang = state.summary.getLang();    }    if (lang == null && state.title != null) {      lang = state.title.getLang();    }    if (lang != null) {      w.simpleElement(Namespaces.rssNs, "language", null, lang);    }    if (state.published != null) {      w.simpleElement(Namespaces.rssNs, "pubDate", null,                      state.published.toStringRfc822());    }    if (state.updated != null) {      w.simpleElement(Namespaces.atomNs, "updated", null,          state.updated.toString());    }    w.startRepeatingElement();    for (Category cat: state.categories) {      cat.generateRss(w);    }    w.endRepeatingElement();    if (state.title != null) {      state.title.generateRss(w, "title", TextConstruct.RssFormat.PLAIN_TEXT);    }    if (state.summary != null) {      state.summary.generateAtom(w, "summary");    }    if (state.content != null) {      state.content.generateRss(w);    }    w.startRepeatingElement();    for (Link link: state.links) {      link.generateRss(w);    }    w.endRepeatingElement();    w.startRepeatingElement();    for (Person author: state.authors) {      author.generateRss(w, "author");    }    w.endRepeatingElement();    w.startRepeatingElement();    for (Person contributor: state.contributors) {      contributor.generateRss(w, "author");    }    w.endRepeatingElement();    // Invoke ExtensionPoint.    generateExtensions(w, extProfile);    w.endElement(Namespaces.rssNs, "item");  }  /** Top-level namespace declarations for generated XML. */  private static final Collection<XmlWriter.Namespace> namespaceDeclsAtom =    new Vector<XmlWriter.Namespace>(1);  private static final Collection<XmlWriter.Namespace> namespaceDeclsRss =    new Vector<XmlWriter.Namespace>(1);  static {    namespaceDeclsAtom.add(Namespaces.atomNs);    namespaceDeclsRss.add(Namespaces.atomNs);  }  /**   * Parses XML in the Atom format.   *   * @param   extProfile   *            Extension profile.   *   * @param   input   *            XML input stream.   */  public void parseAtom(ExtensionProfile extProfile,                        InputStream input) throws IOException,                                              ParseException {    AtomHandler handler = new AtomHandler(extProfile);    new XmlParser().parse(input, handler, Namespaces.atom, "entry");  }  /**   * Parses XML in the Atom format.   *   * @param   extProfile   *            Extension profile.   *   * @param   reader   *            XML Reader.  The caller is responsible for ensuring   *            that the character encoding is correct.   */  public void parseAtom(ExtensionProfile extProfile,                        Reader reader) throws IOException,                                              ParseException {    AtomHandler handler = new AtomHandler(extProfile);    new XmlParser().parse(reader, handler, Namespaces.atom, "entry");  }  /** {@code <atom:entry>} parser. */  public class AtomHandler extends ExtensionPoint.ExtensionHandler {    public AtomHandler(ExtensionProfile extProfile) throws IOException {      super(extProfile, Entry.class);    }    public XmlParser.ElementHandler getChildHandler(String namespace,                                                    String localName,                                                    Attributes attrs)        throws ParseException, IOException {      if (namespace.equals(Namespaces.atom)) {        if (localName.equals("id")) {          return new IdHandler();        } else if (localName.equals("published")) {          return new PublishedHandler();        } else if (localName.equals("updated")) {          return new UpdatedHandler();        } else if (localName.equals("title")) {          TextConstruct.ChildHandlerInfo chi =            TextConstruct.getChildHandler(attrs);          if (state.title != null) {            throw new ParseException("Duplicate title.");          }          state.title = chi.textConstruct;          return chi.handler;        } else if (localName.equals("summary")) {          TextConstruct.ChildHandlerInfo chi =            TextConstruct.getChildHandler(attrs);          if (state.summary != null) {            throw new ParseException("Duplicate summary.");          }          state.summary = chi.textConstruct;          return chi.handler;        } else if (localName.equals("rights")) {          TextConstruct.ChildHandlerInfo chi =            TextConstruct.getChildHandler(attrs);          if (state.rights != null) {            throw new ParseException("Duplicate rights.");          }          state.rights = chi.textConstruct;          return chi.handler;        } else if (localName.equals("content")) {          Content.ChildHandlerInfo chi = Content.getChildHandler(attrs);          if (state.content != null) {            throw new ParseException("Duplicate content.");          }          state.content = chi.content;          return chi.handler;        } else if (localName.equals("category")) {          Category cat = new Category();          return cat.new AtomHandler(extProfile, state.categories,              BaseEntry.this);        } else if (localName.equals("link")) {          Link link = new Link();          state.links.add(link);          return link.new AtomHandler(extProfile);        } else if (localName.equals("author")) {          Person author = new Person();          state.authors.add(author);          return author.new AtomHandler(extProfile);        } else if (localName.equals("contributor")) {          Person contributor = new Person();          state.contributors.add(contributor);          return contributor.new AtomHandler(extProfile);        } else if (localName.equals("source")) {          state.source = new Source();          return state.source.new SourceHandler(extProfile);        }      } else if (namespace.equals(Namespaces.atomPub)) {        if (localName.equals("control")) {          return new ControlHandler();        }      } else {        return super.getChildHandler(namespace, localName, attrs);      }      return null;    }    /** {@code <atom:id>} parser. */    class IdHandler extends XmlParser.ElementHandler {      public void processEndElement() throws ParseException {        if (state.id != null) {          throw new ParseException("Duplicate entry ID.");        }        if (value == null) {          throw new ParseException("ID must have a value.");        }        state.id = value;      }    }    /** {@code <atom:published>} parser. */    class PublishedHandler extends Rfc3339Handler {      public void processEndElement() throws ParseException {        super.processEndElement();        state.published = getDateTime();      }    }    /** {@code <atom:updated>} parser. */    class UpdatedHandler extends Rfc3339Handler {      public void processEndElement() throws ParseException {        super.processEndElement();        state.updated = getDateTime();      }    }    /** {@code <app:control>} parser. */    class ControlHandler extends XmlParser.ElementHandler {      public XmlParser.ElementHandler getChildHandler(String namespace,                                                      String localName,                                                      Attributes attrs)          throws ParseException, IOException {        if (namespace.equals(Namespaces.atomPub)) {          if (localName.equals("draft")) {            return new DraftHandler();          }        } else {          return super.getChildHandler(namespace, localName, attrs);        }        return null;      }    }    /** {@code <app:draft>} parser. */    class DraftHandler extends XmlParser.ElementHandler {      public void processEndElement() throws ParseException {        if (state.isDraft != null) {          throw new ParseException("Duplicate draft element");        }        if (value.equals("yes")) {          state.isDraft = true;        } else if (value.equals("no")) {          state.isDraft = false;        } else {          throw new ParseException("Invalid value for draft");        }      }    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -