Package net.sf.jpluck.palm

Source Code of net.sf.jpluck.palm.ToPluck

package net.sf.jpluck.palm;

import java.io.File;
import java.io.IOException;
import java.util.Date;

import net.sf.jpluck.jxl.Document;
import net.sf.jpluck.jxl.JXL;


public class ToPluck extends Database {
  public static final int RESTRICT_NONE = 0;
  public static final int RESTRICT_DOMAIN = 1;
  public static final int RESTRICT_HOST = 2;
  public static final int RESTRICT_DIRECTORY = 3;

  public ToPluck() {
    super(1, "Plck", "JPlk");
    setName("JPlk-Pluck");
  }

  public void addLink(String name, String url, String category, int maxDepth, int restrict) {
    recordList.add(new LinkRecord(name, url, category, maxDepth, restrict));
  }

  private class LinkRecord implements Record {
    private String category;
    private String name;
    private String url;
    private int maxDepth;
    private int restrict;
    private Date lastConverted;

    LinkRecord(String name, String url, String category, int maxDepth, int restrict) {
      this.name = name;
      this.url = url;
      this.category = category;
      this.maxDepth = maxDepth;
      this.restrict = restrict;
    }

    public int getRecordId() {
      return recordList.indexOf(this) + 1;
    }

    public void write(PdbOutputStream out) throws IOException {
      out.writeBoolean((getRecordId() % 2 == 0));
      out.writeNullTerminatedString(name);
      out.writeNullTerminatedString(url);
      out.writeNullTerminatedString(category);
      out.writeByte(maxDepth);
      out.writeByte(restrict);
    }
  }
 
  public static void main(String[] args) throws Exception {
    String filename = args[0];
    if (!filename.endsWith(".jxl")) {
      System.err.println("ERROR: filename does end with \".jxl\"");
      System.exit(-1);
    }
    File file = new File(filename);
    System.out.println("Reading " + file.getAbsolutePath());
    JXL jxl=new JXL(file);
    Document[] documents = jxl.getDocuments();
    ToPluck toPluck = new ToPluck();
    for (int i = 0; i < documents.length; i++) {
      Document document = documents[i];
      String category=null;
      if (document.getCategories().length>0) {
        category=document.getCategories()[0];
      }
      String r =document.getRestrict();
      int restrict=RESTRICT_NONE;
      if (r.equals("domain")) {
        restrict=RESTRICT_DOMAIN;
      } else if(r.equals("host")) {
        restrict=RESTRICT_HOST;
      } else if (r.equals("directory")) {
        restrict=RESTRICT_DIRECTORY;
      }
      toPluck.addLink(document.getName(), document.getUri(), category, document.getLinkDepth(), restrict);
    }
    File pdb = new File(filename.replaceAll("\\.jxl", "-Pluck.pdb"));
    System.out.println("Writing " + pdb.getAbsolutePath());
    toPluck.write(pdb);
    System.out.println("Done!");
  }
}
TOP

Related Classes of net.sf.jpluck.palm.ToPluck

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.