配置

From Apache OpenOffice Wiki
Jump to: navigation, search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


协议处理器需要配置条目,这些条目可以向框架提供必要信息以查找处理器。配置分支 org.openoffice.Office.ProtocolHandler 的模式定义如何将处理器实例绑定到它们的 URL 模式:

  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE oor:component-schema SYSTEM "../../../../component-schema.dtd">
  <oor:component-schema xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" oor:name="ProtocolHandler" oor:package="org.openoffice.Office" xml:lang="en-US">
      <templates>
          <group oor:name="Handler">
              <prop oor:name="Protocols" oor:type="oor:string-list"/>
          </group>
      </templates>
          <component>
              <set oor:name="HandlerSet" oor:node-type="Handler"/>
          </component>
  </oor:component-schema>


每个 set 节点条目使用协议处理器的 UNO 实现名称指定一个协议处理器。它拥有的唯一属性是 Protocols 项。它的类型必须是 [string-list],并包含绑定到处理器的 URL 模式的列表。允许使用占位符,如果不使用,则整个字符串必须匹配分发的 URL。


vnd.sun.star.framework.ExampleHandler 的配置

以下示例 ProtocolHandler.xcu 包含用于示例的 Java 协议处理器的协议处理器配置:

  <?xml version='1.0' encoding='UTF-8'?>
  <oor:component-data oor:name="ProtocolHandler" oor:package="org.openoffice.Office" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <node oor:name="HandlerSet">
          <node oor:name="vnd.sun.star.framework.ExampleHandler" oor:op="replace">
              <prop oor:name="Protocols">
                  <value>myProtocol_1://* myProtocol_2://*</value>
              </prop>
          </node>
      </node>
  </oor:component-data>


示例使用占位符加入了两个新的 URL 协议:

 myProtocol_1://*
 myProtocol_2://*


这两个协议都绑定到处理器实现 vnd.sun.star.framework.ExampleHandler。请注意,这必须是处理器的实现名称,而不是它实现的 com.sun.star.frame.ProtocolHandler 服务的名称。com.sun.star.frame.ProtocolHandler 服务的所有实现都共享同一个 UNO 服务名称,因此不能在配置文件中使用此名称。


为防止出现模糊的实现名称,经常使用以下命名模式来命名实现名称:

 vnd.<namespace_of_company>.<namespace_of_implementation>.<class_name> 

例如:vnd.sun.star.framework.ExampleHandler

 <namespace_of_company>= sun.star<
 namespace_of_implementation>= framework
 <class_name>= ExampleHandler 


或者也可以使用 编写 UNO 组件 - 可实现的核心接口 - XServiceInfo 中建议的命名约定:

 <namespace_of_creator>.comp.<namespace_of_implementation>.<class_name> 

例如:org.openoffice.comp.framework.OProtocolHandler


所有这些约定都是建议性的;重要的是:

在配置文件中使用实现的名称,而不是常规服务的名称 "com.sun.star.frame.ProtocolHandler"
  • 请尽量使您选择的实现名称是唯一的,并请留意当其他开发者添加具有相同名称的处理器时,您的处理器将停止运行。


org.openoffice.Office.addon.example 的配置

以下 ProtocolHandler.xcu 文件将使用实现名称 org.openoffice.Office.addon.example 在使用相同模式的配置分支 org.openoffice.Office.ProtocolHandler 中配置示例的 C++ 协议处理器。

  <?xml version="1.0" encoding="UTF-8"?>
  <oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="ProtocolHandler" oor:package="org.openoffice.Office"> 
      <node oor:name="HandlerSet"> 
          <node oor:name="org.openoffice.Office.addon.example" oor:op="replace"> 
              <prop oor:name="Protocols" oor:type="oor:string-list">
                  <value>org.openoffice.Office.addon.example:*</value> 
              </prop> 
          </node> 
      </node>
  </oor:component-data>


配置使用占位符加入了一个新的 URL 协议:

 org.openoffice.Office.addon.example:*


根据此 URL 协议,C++ 协议处理器可以将一个已分发的 URL,如

 org.openoffice.Office.addon.example:Function1 

路由到相应的目标例行程序。请参阅上述 C++ 源代码片断的 XDispatch 接口中的 dispatch() 方法的实现。

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages