IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope: Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  XML  >

Working XML: Wrapping up XM version 1

Managing a list of links and the table of contents

developerWorks

Return to article.


Listing 4. WalkFilter kicks in the directory reading
        
public void startElement(String namespaceURI,
                         String localName,
                         String qName,
                         Attributes atts)
   throws SAXException
{
   if(!namespaceURI.equals(this.namespaceURI))
      super.startElement(namespaceURI,localName,qName,atts);
   else
      try
      {
         if(localName.equals("Directory"))
         {
            if(inDirectory)
               messenger.error(new XMException(Resources.getString("nestedelement"),
                                               new Object[] { qName }));
            String dir = atts.getValue("dir");
            if(dir == null || dir.trim().length() == 0)
               messenger.error(new XMException(Resources.getString("dirrequired"),
                               new Object[] { qName }));
            String stValue = atts.getValue("markSource");
            boolean markSource = stValue != null && stValue.equalsIgnoreCase("true");
            if(markSource && sourceFile == null)
               throw new NotImplementedException("Caller has not set the sourceFile but the document wants it marked.");
            File sourceDir = sourceFile != null ? sourceFile.getParentFile() : null,
                 dirFile = null;
            if(sourceDir != null)
               dirFile = new File(sourceDir,dir);
            else
               dirFile = new File(dir);
            directoryReader.read(dirFile,markSource ? sourceFile : null);
            inDirectory = true;
         }
      }
      catch(XMException e)
      {
         throw new SAXException(e);
      }
}
      

Return to article.

    关于 IBM 隐私条约 联系 IBM 使用条款