Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Processing instructions and parameters

Adding support for multiple style sheets

Return to article.


Listing 5: Adapted StylingMover

public File move(File sourceFile,File targetDir,int depth)
   throws XMException
{
   try
   {
      File targetFile = new File(targetDir,getTargetName(sourceFile));
      if(!build && targetFile.exists())
         if(targetFile.lastModified() >= sourceFile.lastModified())
            return null;
      serializer.setOutputStream(new FileOutputStream(targetFile));
      linkFilter.setDirectory(sourceFile.getParentFile(),depth);
      linkFilter.setContentHandler(serializer.asContentHandler());
      // the lexical handler is required for CDATA sections
      if(serializer instanceof LexicalHandler)
         linkFilter.setProperty("http://xml.org/sax/properties/lexical-handler",
			                       serializer);
      else
         throw new NotImplementedException("LexicalHandler interface required");
      SAXResult result = new SAXResult(linkFilter);

      XMLReader reader = JAXPHelper.createXMLReader(false);
      ProcessingInstructionHandler handler = new ProcessingInstructionHandler();
      reader.setContentHandler(handler);
      try
      {
         reader.parse(JAXPHelper.toInputSource(sourceFile));
      }
      catch(SAXException e)
      {
         if(!handler.isStopException(e))
            throw e;
      }

      String href = handler.getHRef();
      Transformer transformer = templates.getTransformer(href,sourceFile);
      Iterator iterator = handler.getParamsIterator();
      while(iterator.hasNext())
      {
         Map.Entry entry = (Map.Entry)iterator.next();
         transformer.setParameter((String)entry.getKey(),(String)entry.getValue());
      }
      transformer.transform(new StreamSource(sourceFile),result);
      return targetFile;
   }
   catch(SAXException e)
   {
      messenger.error(new XMException(e));
   }
   catch(IOException e)
   {
      messenger.error(new XMException(e));
   }
   catch(TransformerException e)
   {
      messenger.error(new XMException(e));
   }
   return null;
}

Return to article.