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

📄 extensionprofile.java

📁 google gdata API 很好用的API
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    if (entryLinkProfile != null) {      result.addAll(entryLinkProfile.computeNamespaceDecls());    }    return Collections.unmodifiableSet(result);  }  /**   * Reads the ExtensionProfile XML format.   *   * @param   configProfile   *            ExtensionProfile defining configuration extensions.   */  public class Handler extends XmlParser.ElementHandler {    private ExtensionProfile configProfile;    private ClassLoader configLoader;    private List<XmlWriter.Namespace> namespaces =              new ArrayList<XmlWriter.Namespace>();    public Handler(ExtensionProfile configProfile, ClassLoader configLoader)        throws IOException {      this.configProfile = configProfile;      this.configLoader = configLoader;    }    public void validate() throws ServiceConfigurationException {    }    public void processEndElement() throws ParseException {      try {        validate();      } catch (ServiceConfigurationException e) {        throw new ParseException(e);      }    }    public XmlParser.ElementHandler getChildHandler(String namespace,                                                    String localName,                                                    Attributes attrs)        throws ParseException, IOException {      if (namespace.equals(Namespaces.gdataConfig)) {        if (localName.equals("namespaceDescription")) {          String alias = attrs.getValue("", "alias");          if (alias == null) {            throw new ParseException(                      "NamespaceDescription alias attribute is missing");          }          String uri = attrs.getValue("", "uri");          if (uri == null) {            throw new ParseException(                      "NamespaceDescription uri attribute is missing");          }          XmlWriter.Namespace declaredNs = new XmlWriter.Namespace(alias, uri);          namespaces.add(declaredNs);          declareAdditionalNamespace(declaredNs);          return new XmlParser.ElementHandler();        } else if (localName.equals("extensionPoint")) {          return new ExtensionPointHandler(configProfile, configLoader,                                           namespaces, attrs);        }      }      return super.getChildHandler(namespace, localName, attrs);    }  }  /**   * Reads the ExtensionPoint XML format   *   * @param   configProfile   *            ExtensionProfile defining configuration extensions.   */  public class ExtensionPointHandler extends XmlParser.ElementHandler {    private ExtensionProfile configProfile;    private ClassLoader configLoader;    private Class extensionPoint;    private boolean arbitraryXml;    private List<ExtensionDescription> extDescriptions =      new ArrayList<ExtensionDescription>();    private List<XmlWriter.Namespace> namespaces;    public ExtensionPointHandler(ExtensionProfile configProfile,                                 ClassLoader configLoader,                                 List<XmlWriter.Namespace> namespaces,                                 Attributes attrs)        throws ParseException, IOException {      this.configProfile = configProfile;      this.configLoader = configLoader;      this.namespaces = namespaces;      String extendedClassName = attrs.getValue("", "extendedClass");      if (extendedClassName == null) {        throw new ParseException(                    "ExtensionPoint extendedClass attribute is missing");      }      try {        extensionPoint = configLoader.loadClass(extendedClassName);      } catch (ClassNotFoundException e) {        throw new ParseException("Unable to load ExtensionPoint class", e);      }      if (!ExtensionPoint.class.isAssignableFrom(extensionPoint)) {        throw new ParseException(                    "Extended classes must extend ExtensionPoint");      }      String arbitraryXmlAttr = attrs.getValue("", "arbitraryXml");      if (arbitraryXmlAttr != null) {        if (arbitraryXmlAttr.equals("true") || arbitraryXmlAttr.equals("1")) {          arbitraryXml = true;        } else if (arbitraryXmlAttr.equals("false") ||                   arbitraryXmlAttr.equals("0")) {          arbitraryXml = false;        } else {          throw new ParseException("Invalid value for arbitaryXml: " +                                   arbitraryXml);        }      }    }    public void processEndElement() throws ParseException {      if (arbitraryXml) {        declareArbitraryXmlExtension(extensionPoint);      }      for (ExtensionDescription extDescription: extDescriptions) {        declare(extensionPoint, extDescription);      }    }    public XmlParser.ElementHandler getChildHandler(String namespace,                                                    String localName,                                                    Attributes attrs)        throws ParseException, IOException {      if (namespace.equals(Namespaces.gdataConfig)) {        if (localName.equals("extensionDescription")) {          ExtensionDescription extDescription = new ExtensionDescription();          extDescriptions.add(extDescription);          return extDescription.new Handler(configProfile, configLoader,                                            namespaces, attrs);        }      }      return super.getChildHandler(namespace, localName, attrs);    }  }  /**   * Parses XML in the ExtensionProfile format.   *   * @param   configProfile   *            Extension profile description configuration extensions.   *   * @param   classLoader   *            ClassLoader to load extension classes   *   * @param   stream   *            InputStream from which to read the description   */  public void parseConfig(ExtensionProfile configProfile,                          ClassLoader classLoader,                          InputStream stream) throws IOException,                                                   ParseException {    Handler handler = new Handler(configProfile, classLoader);    new XmlParser().parse(stream, handler, Namespaces.gdataConfig,                          "extensionProfile");  }  /**   * Generates XML in the external config format.   *   * @param   w   *          Output writer.   *   * @param   extProfile   *          Extension profile.   *   * @throws  IOException   */  public void generateConfig(XmlWriter w,                             ExtensionProfile extProfile) throws IOException {    w.startElement(Namespaces.gdataConfigNs, "extensionProfile", null, nsDecls);    for (XmlWriter.Namespace namespace : additionalNamespaces) {      List<Attribute> nsAttrs = new ArrayList<Attribute>();      nsAttrs.add(new Attribute("alias", namespace.getAlias()));      nsAttrs.add(new Attribute("uri", namespace.getUri()));      w.simpleElement(Namespaces.gdataConfigNs, "namespaceDescription",                      nsAttrs, null);    }    //    // Get a list of the extended classes sorted by class name    //    TreeSet<Class> extensionSet = new TreeSet<Class>(         new Comparator<Class>() {          public int compare(Class c1, Class c2) {            return c1.getName().compareTo(c2.getName());          }          public boolean equals(Comparator c) {            return this.getClass().equals(c.getClass());          }        });    for (Class extensionPoint : profile.keySet()) {      extensionSet.add(extensionPoint);    }    for (Class extensionPoint : extensionSet) {      ExtensionPoint.Manifest  manifest = profile.get(extensionPoint);      List<Attribute> ptAttrs = new ArrayList<Attribute>();      ptAttrs.add(new Attribute("extendedClass", extensionPoint.getName()));      ptAttrs.add(new Attribute("arbitraryXml", manifest.arbitraryXml));      w.startElement(Namespaces.gdataConfigNs, "extensionPoint", ptAttrs, null);      // Create an ordered list of the descriptions in this profile      TreeSet<ExtensionDescription> descSet =         new TreeSet<ExtensionDescription>();      for (ExtensionDescription extDescription :            manifest.getSupportedExtensions().values()) {        descSet.add(extDescription);      }      // Now output based upon the ordered list      for (ExtensionDescription extDescription : descSet) {        extDescription.generateConfig(w, extProfile);      }      w.endElement(Namespaces.gdataConfigNs, "extensionPoint");    }    w.endElement(Namespaces.gdataConfigNs, "extensionProfile");  }}

⌨️ 快捷键说明

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