Package nz.govt.natlib.adapter

Examples of nz.govt.natlib.adapter.DataAdapter


    //Config.getInstance();
   
    Config.getInstance().setXMLBaseURL(Fits.FITS_XML+"nlnz");

    // Get the appropriate adapter.
    DataAdapter adapter = AdapterFactory.getInstance().getAdapter(file);   
   
    //The adapter's DTD to use for output
    String outDTD = adapter.getOutputType();

    //output stream to hold raw output from adapter
    ByteArrayOutputStream adapterOutput = new ByteArrayOutputStream(2048);
   
    //holder for the transformed adapter output
    //ByteArrayOutputStream tAdapterOutput = new ByteArrayOutputStream(2048);
   
    // Set up the parser context and listener to hold the adapter output
    ParserContext pContext = new ParserContext();
   
    ParserListener listener= new DTDXmlParserListener(adapterOutput, outDTD == null ? null
        : Config.getInstance().getXMLBaseURL() + "/" + outDTD);
    pContext.addListener(listener);
   
    // Attempt to harvest the metadata.
    try {       
      // Extract the metadata.
      adapter.adapt(file, pContext);

      //transformer to convert raw output to nlnz_presmet format
      //TransformProcessor transformer = TransformProcessor.getInstance(outDTD, "nlnz_presmet.xsd");
           
      //get the adapter output as a byte array
View Full Code Here


            .getAbsolutePath());
        jarFile = newJarFile;
      }
      Loader.loadJar(jarFile.getAbsolutePath());
      try {
        DataAdapter adapterImpl = (DataAdapter) ClassLoader
            .getSystemClassLoader().loadClass(adapter)
            .newInstance();
        AdapterFactory.getInstance().addAdapter(adapterImpl);
        ArrayList profiles = Config.getInstance()
            .getAvailableProfiles();
        Iterator itp = profiles.iterator();
        while (itp.hasNext()) {
          Profile p = (Profile) itp.next();
          p.setAdapter(adapterImpl.getClass().getName(), true);
        }
        ArrayList editprofiles = Config.getEditInstance()
            .getAvailableProfiles();
        Iterator itp2 = editprofiles.iterator();
        while (itp2.hasNext()) {
          Profile p = (Profile) itp2.next();
          p.setAdapter(adapterImpl.getClass().getName(), true);
        }
        Config.getEditInstance().setJarForAdapter(adapterImpl,
            jarFile.getName());
        Config.getInstance().setJarForAdapter(adapterImpl,
            jarFile.getName());
View Full Code Here

  }

  private void delAdapter() {
    int idx = adapterTable.getSelectedRow();
    if (idx > -1) {
      DataAdapter adapter = tableModel.getAdapter(idx);
      if (Config.getEditInstance().getJarForAdapter(adapter).equals(
          Config.SYSTEM_ADAPTER)) {
        JOptionPane.showMessageDialog(this,
            "Unable to uninstall system adapter "
                + adapter.getName(),
            "Unable to remove adapter",
            JOptionPane.WARNING_MESSAGE, delPic);
      } else {
        int result = JOptionPane.showConfirmDialog(this,
            "Are you sure you wish to uninstall "
                + adapter.getName(), "Remove Adapter",
            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
            delPic);
        if (result == JOptionPane.OK_OPTION) {
          removeAdapter(adapter);
        }
View Full Code Here

          String className = map.getNamedItem(CLASS_TAG)
              .getNodeValue();
          // String outputDTD =
          // map.getNamedItem(OUTPUT_DTD_TAG).getNodeValue();
          // create it and set it up...
          DataAdapter adapter = null;
          try {
            adapter = (DataAdapter) Class.forName(className, true,
                ClassLoader.getSystemClassLoader())
                .newInstance();
            String jarName = map.getNamedItem(JAR_TAG)
View Full Code Here

    public int getColumnCount() {
      return 3;
    }

    public DataAdapter getAdapter(int index) {
      DataAdapter res = null;
      if (index < adapterList.size()) {
        res = (DataAdapter) adapterList.get(index);
      }
      return res;
    }
View Full Code Here

      }
      return res;
    }

    public Object getValueAt(int row, int col) {
      DataAdapter adapter = getAdapter(row);
      switch (col) {
      case 0:
        return adapter.getName();
      case 1:
        return adapter.getOutputType();
      case 2:
        return Config.getEditInstance().getJarForAdapter(adapter);
      default:
        return null;
      }
View Full Code Here

  protected void harvestFile(Configuration config, File file,
      PropertySource props) throws IOException {
   
    // get the adapter...
    DataAdapter adapter = AdapterFactory.getInstance().getAdapter(file);

    // adapt each file...
    String outDTD = adapter.getOutputType();
    ByteArrayOutputStream bout = new ByteArrayOutputStream(2048);
    ParserContext handler = new ParserContext();

    // fill in some details - to be included in the output...
    handler.setAttribute(ParserContext.FILE_INDEX, fileCount++);
    handler.setAttribute(ParserContext.OBJECT, props
        .getProperty("ID", null));
    handler.setAttribute(ParserContext.PROCESS, props.getProperty("Type",
        null));

    // Set up the handler.
    ParserListener listener = new DTDXmlParserListener(bout, outDTD == null ? null
        : Config.getInstance().getXMLBaseURL() + "/" + outDTD);
    handler.addListener(listener);

    // Adapt the file.
    LogManager.getInstance().logMessage(LogMessage.WORTHLESS_CHATTER, "Starting Adapter");
    adapter.adapt(file, handler);
    LogManager.getInstance().logMessage(LogMessage.WORTHLESS_CHATTER, "Finished adapting");

    // Get the transformer that is configured to map from the native format
    // to the "nlnz_presmet.xsd" format. Note that because the
    // nlnz_presmet.xsd files have a preamble, and may contain metadata for
    // multiple files within a single output file (for the
    // ComplexObjectHarvester) the transformation does not
    // create a complete XML file, just a <File>...</File> section.
    // Different Harvester implementations may use the transformer mapping
    // to create complete XML documents; it's up to the Harvester what it
    // expects the transformation to achieve.
    LogManager.getInstance().logMessage(LogMessage.WORTHLESS_CHATTER, "Starting Transformation");
    TransformProcessor transformer = TransformProcessor.getInstance(adapter
        .getOutputType(), getOutputType());
   
    // Transform the document into the target format.
    LogManager.getInstance().logMessage(LogMessage.WORTHLESS_CHATTER, "Finished Transformation");
    transformer.transform(new ByteArrayInputStream(bout.toByteArray()),
View Full Code Here

  public void harvestFile(Configuration config, File file,
      PropertySource props) throws IOException {
    OutputStream out = null;
    try {
      DataAdapter adapter = AdapterFactory.getInstance().getAdapter(file);
     
      File f = new File(config.getOutputDirectory() + "/"
          + file.getName() + ".xml");
      out = new FileOutputStream(f);

      String outDTD = config.getOutputDTD();
     
      // This loads the DoNohtingTransformer.
      TransformProcessor transformer = new DoNothingTransformer();
       
        //TransformProcessor.getInstance(
        //  inDTD, outDTD);
     

      ByteArrayOutputStream bout = new ByteArrayOutputStream(2048);
      ParserContext handler = new ParserContext();
      ParserListener listener = new DTDXmlParserListener(bout,
          outDTD == null ? null : Config.getInstance()
              .getXMLBaseURL()
              + "/" + outDTD);
      handler.addListener(listener);
      adapter.adapt(file, handler);

      transformer.transform(new ByteArrayInputStream(bout.toByteArray()),
          out);
    } finally {
      if (out != null) {
View Full Code Here

    try {
      // Make sure the Harvester System is initialised.
      Config.getInstance();
     
      // Get the appropriate adapter.
      DataAdapter adapter = AdapterFactory.getInstance().getAdapter(f);
     
      // Extract the metadata.
      adapter.adapt(f, ctx);

      // Display the metadata.
      System.out.println(listener.getContents());
     
    } catch (IOException e) {
View Full Code Here

        System.out.println("    Log Directory: " + p.getLogDirectory());
        System.out.println("    Adapters switched on:");
        Iterator adapters = p.getAdapterClasses();
        while (adapters.hasNext()) {
          String adClass = (String) adapters.next();
          DataAdapter da = AdapterFactory.getInstance().getAdapter(
              adClass);
          if (da != null) {
            System.out.println("      " + da.getName() + " "
                + da.getVersion());
            System.out.println("      Desc: " + da.getDescription()
                + ": ");
          }
        }
      }
      handled = true;
View Full Code Here

TOP

Related Classes of nz.govt.natlib.adapter.DataAdapter

Copyright © 2018 www.massapicom. 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.