cvs commit: jakarta-alexandria/proposal/gump/java Jenny.java

[email protected]
Newsgroups gmane.comp.jakarta.alexandria.devel
Message-ID <[email protected]>
conor       2002/12/11 19:17:23

  Modified:    proposal/gump/java Jenny.java
  Log:
  Allow Jenny to be run offline (i.e. behind a firewall) by not expanding
  http hrefs.
  
  Revision  Changes    Path
  1.20      +33 -12    jakarta-alexandria/proposal/gump/java/Jenny.java
  
  Index: Jenny.java
  ===================================================================
  RCS file: /home/cvs/jakarta-alexandria/proposal/gump/java/Jenny.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -w -u -r1.19 -r1.20
  --- Jenny.java	27 Aug 2002 14:54:09 -0000	1.19
  +++ Jenny.java	12 Dec 2002 03:17:23 -0000	1.20
  @@ -78,6 +78,7 @@
   
   // Java classes
   import java.io.File;
  +import java.net.ConnectException;
   import java.text.SimpleDateFormat;
   import java.util.Date;
   import java.util.Enumeration;
  @@ -86,6 +87,9 @@
   
   public class Jenny {
   
  +    /** Indicates whether extrenal references should be followed or not */
  +    private boolean online = true;
  +
       DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
       TransformerFactory tFactory = TransformerFactory.newInstance();
   
  @@ -165,8 +169,12 @@
       private Element expand(Element node) throws Exception {
          // expand hrefs
          Attr href = node.getAttributeNode("href");
  +       
          if (href != null && !node.getNodeName().equals("url")) {
              String source=href.getValue();
  +           if (source.startsWith("http://") && !online) {
  +               throw new ConnectException("Not online");
  +           }
              Node sub = parse(source);
   
              boolean isExtern = source.startsWith("http://")
  @@ -248,9 +256,8 @@
                      }
                      
                      System.err.println("Failed to expand "
  -                                      + name.toString()
  -                                      + " because of exception "
  -                                      + t);
  +                                      + name.toString());
  +                   System.err.println("   - " + t);
                  }
              }
          }
  @@ -335,8 +342,8 @@
        * merge, sort, and insert defaults into a workspace
        * @param source document to be transformed
        */
  -    private Jenny(String source) throws Exception {
  -
  +    private Jenny(String source, boolean online) throws Exception {
  +        this.online = online;
           // Obtain the date to be used
           Date lastModified = new Date();
           try {
  @@ -367,10 +374,24 @@
        */
       public static void main(String[] args) {
           try {
  -            if (args.length == 1) {
  -                new Jenny(args[0]);
  +            boolean onlineOption = true;
  +            boolean usageOK = true;
  +            
  +            if (args.length > 2) {
  +                usageOK = false;
  +            } else if (args.length == 2) {
  +                if (args[1].equalsIgnoreCase("-offline")) {
  +                    onlineOption = false;
  +                } else if (!args[1].equalsIgnoreCase("-online")) {
  +                    usageOK = false;
  +                }
  +            }
  +            
  +            if (usageOK) {
  +                new Jenny(args[0], onlineOption);
               } else {
  -                System.out.println("Usage: Jenny workspace.xml");
  +                System.out.println("Usage: Jenny workspace.xml [-offline | -online]");
  +                System.exit(1);
               }
           } catch (Exception e) {
               e.printStackTrace();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.