Package org.nasutekds.server.util

Examples of org.nasutekds.server.util.LDIFReader


    if (isSchemaFileDefined)
    {
      LDIFExportConfig exportConfig =
        new LDIFExportConfig(schemaFile,
                             ExistingFileBehavior.OVERWRITE);
      LDIFReader reader = null;
      Entry schemaEntry = null;
      try
      {
        reader = new LDIFReader(new LDIFImportConfig(schemaFile));
        schemaEntry = reader.readEntry();

        for (AttributeType attribute : attributes)
        {
          Modification mod = new Modification(ModificationType.ADD,
              Attributes.create(getAttributeName(attribute).toLowerCase(),
                  getValueOffline(attribute)));
          schemaEntry.applyModification(mod);
        }
        for (ObjectClass oc : objectClasses)
        {
          Modification mod = new Modification(ModificationType.ADD,
              Attributes.create(getAttributeName(oc).toLowerCase(),
                  getValueOffline(oc)));
          schemaEntry.applyModification(mod);
        }
        LDIFWriter writer = new LDIFWriter(exportConfig);
        writer.writeEntry(schemaEntry);
        exportConfig.getWriter().newLine();
      }
      catch (Throwable t)
      {
      }
      finally
      {
        if (reader != null)
        {
          try
          {
            reader.close();
          }
          catch (Throwable t)
          {
          }
        }
View Full Code Here


  {
    String schemaFile = getSchemaFile((SchemaFileElement)schemaElement);
    LDIFExportConfig exportConfig =
      new LDIFExportConfig(schemaFile,
          ExistingFileBehavior.OVERWRITE);
    LDIFReader reader = null;
    Entry schemaEntry = null;
    try
    {
      reader = new LDIFReader(new LDIFImportConfig(schemaFile));
      schemaEntry = reader.readEntry();

      Modification mod = new Modification(ModificationType.DELETE,
          Attributes.create(
              getSchemaFileAttributeName(schemaElement).toLowerCase(),
              getSchemaFileAttributeValue(schemaElement)));
      schemaEntry.applyModification(mod);
      LDIFWriter writer = new LDIFWriter(exportConfig);
      writer.writeEntry(schemaEntry);
      exportConfig.getWriter().newLine();
    }
    catch (Throwable t)
    {
    }
    finally
    {
      if (reader != null)
      {
        try
        {
          reader.close();
        }
        catch (Throwable t)
        {
        }
      }
View Full Code Here

      try
      {
        String ldif = getBackendLdif(backendName);

        ldifImportConfig = new LDIFImportConfig(new StringReader(ldif));
        LDIFReader reader = new LDIFReader(ldifImportConfig);
        Entry backendConfigEntry;
        while ((backendConfigEntry = reader.readEntry()) != null)
        {
          DirectoryServer.getConfigHandler().addEntry(backendConfigEntry, null);
        }
        DirectoryServer.getConfigHandler().writeUpdatedConfig();
      }
View Full Code Here

      try
      {
        String ldif = getAdditionalIndexLdif(backendName);

        ldifImportConfig = new LDIFImportConfig(new StringReader(ldif));
        LDIFReader reader = new LDIFReader(ldifImportConfig);
        Entry indexEntry;
        while ((indexEntry = reader.readEntry()) != null)
        {
          DirectoryServer.getConfigHandler().addEntry(indexEntry, null);
        }
        DirectoryServer.getConfigHandler().writeUpdatedConfig();
      }
View Full Code Here

      String ldif = getAdditionalIndexLdif(backendName);
      LDIFImportConfig ldifImportConfig = null;
      try
      {
        ldifImportConfig = new LDIFImportConfig(new StringReader(ldif));
        LDIFReader reader = new LDIFReader(ldifImportConfig);
        Entry indexEntry;
        while ((indexEntry = reader.readEntry()) != null)
        {
          ArrayList<String> args = new ArrayList<String>();
          args.add("create-local-db-index");
          args.add("--backend-name");
          args.add(backendName);
View Full Code Here

                "objectClass: ds-cfg-external-changelog-domain",
                "cn: external changelog",
                "ds-cfg-enabled: " + (!getBackend().isPrivateBackend()));
            LDIFImportConfig ldifImportConfig = new LDIFImportConfig(
                new StringReader(ldif));
            LDIFReader reader = new LDIFReader(ldifImportConfig);
            Entry eclEntry = reader.readEntry();
            DirectoryServer.getConfigHandler().addEntry(eclEntry, null);
            ldifImportConfig.close();
          }
        }
      }
View Full Code Here

          InterruptedException, ExecutionException
  {
    this.rootContainer = rootContainer;
    try
    {
      reader = new LDIFReader(importConfiguration, rootContainer,
          READER_WRITER_BUFFER_SIZE);
    }
    catch (IOException ioe)
    {
      Message message = ERR_JEB_IMPORT_LDIF_READER_IO_ERROR.get();
View Full Code Here

      exportConfig.setWrapColumn(75);
    }


    // Create the LDIF reader/writer from the import/export config.
    LDIFReader reader;
    LDIFWriter writer;
    try
    {
      reader = new LDIFReader(importConfig);
    }
    catch (Exception e)
    {
      Message message = ERR_LDIFSEARCH_CANNOT_CREATE_READER.get(
              String.valueOf(e));
      err.println(message);
      return 1;
    }

    try
    {
      writer = new LDIFWriter(exportConfig);
    }
    catch (Exception e)
    {
      try
      {
        reader.close();
      } catch (Exception e2) {}

      Message message = ERR_LDIFSEARCH_CANNOT_CREATE_WRITER.get(
              String.valueOf(e));
      err.println(message);
      return 1;
    }


    // Start reading data from the LDIF reader.
    long startTime  = System.currentTimeMillis();
    long stopTime   = startTime + timeLimitMillis;
    long matchCount = 0;
    int  resultCode = LDAPResultCode.SUCCESS;
    while (true)
    {
      // If the time limit has been reached, then stop now.
      if ((timeLimitMillis > 0) && (System.currentTimeMillis() > stopTime))
      {
        resultCode = LDAPResultCode.TIME_LIMIT_EXCEEDED;

        Message message = WARN_LDIFSEARCH_TIME_LIMIT_EXCEEDED.get();
        err.println(message);
        break;
      }


      try
      {
        Entry entry = reader.readEntry(checkSchema);
        if (entry == null)
        {
          break;
        }


        // Check to see if the entry has an acceptable base and scope.
        boolean matchesBaseAndScope = false;
        for (DN baseDN : baseDNs)
        {
          if (entry.matchesBaseAndScope(baseDN, searchScope))
          {
            matchesBaseAndScope = true;
            break;
          }
        }

        if (! matchesBaseAndScope)
        {
          continue;
        }


        // Check to see if the entry matches any of the filters.
        boolean matchesFilter = false;
        for (SearchFilter filter : searchFilters)
        {
          if (filter.matchesEntry(entry))
          {
            matchesFilter = true;
            break;
          }
        }

        if (! matchesFilter)
        {
          continue;
        }


        // Prepare the entry to return to the client.
        if (! allUserAttrs)
        {
          Iterator<AttributeType> iterator =
               entry.getUserAttributes().keySet().iterator();
          while (iterator.hasNext())
          {
            if (! userAttributeTypes.contains(iterator.next()))
            {
              iterator.remove();
            }
          }
        }

        if (! allOperationalAttrs)
        {
          Iterator<AttributeType> iterator =
               entry.getOperationalAttributes().keySet().iterator();
          while (iterator.hasNext())
          {
            if (! operationalAttributeTypes.contains(iterator.next()))
            {
              iterator.remove();
            }
          }
        }


        // Write the entry to the client and increase the count.
        // FIXME -- Should we include a comment about which base+filter matched?
        writer.writeEntry(entry);
        writer.flush();

        matchCount++;
        if ((sizeLimitValue > 0) && (matchCount >= sizeLimitValue))
        {
          resultCode = LDAPResultCode.SIZE_LIMIT_EXCEEDED;

          Message message = WARN_LDIFSEARCH_SIZE_LIMIT_EXCEEDED.get();
          err.println(message);
          break;
        }
      }
      catch (LDIFException le)
      {
        if (le.canContinueReading())
        {
          Message message = ERR_LDIFSEARCH_CANNOT_READ_ENTRY_RECOVERABLE.get(
                  le.getMessage());
          err.println(message);
        }
        else
        {
          Message message = ERR_LDIFSEARCH_CANNOT_READ_ENTRY_FATAL.get(
                  le.getMessage());
          err.println(message);
          resultCode = LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR;
          break;
        }
      }
      catch (Exception e)
      {
        Message message = ERR_LDIFSEARCH_ERROR_DURING_PROCESSING.get(
                String.valueOf(e));
        err.println(message);
        resultCode = LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR;
        break;
      }
    }


    // Close the reader and writer.
    try
    {
      reader.close();
    } catch (Exception e) {}

    try
    {
      writer.close();
View Full Code Here

      err.println(message);
      return LDAPResultCode.CLIENT_SIDE_PARAM_ERROR;
    }

    LDIFImportConfig importConfig = new LDIFImportConfig(sourceFile.getValue());
    LDIFReader sourceReader;
    try
    {
      sourceReader = new LDIFReader(importConfig);
    }
    catch (IOException ioe)
    {
      Message message = ERR_LDIFMODIFY_CANNOT_OPEN_SOURCE.get(
              sourceFile.getValue(),
                                  String.valueOf(ioe));
      err.println(message);
      return LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR;
    }


    File changes = new File(changesFile.getValue());
    if (! changes.exists())
    {
      Message message = ERR_LDIFMODIFY_CHANGES_DOES_NOT_EXIST.get(
              changesFile.getValue());
      err.println(message);
      return LDAPResultCode.CLIENT_SIDE_PARAM_ERROR;
    }

    importConfig = new LDIFImportConfig(changesFile.getValue());
    LDIFReader changeReader;
    try
    {
      changeReader = new LDIFReader(importConfig);
    }
    catch (IOException ioe)
    {
      Message message = ERR_LDIFMODIFY_CANNOT_OPEN_CHANGES.get(
              sourceFile.getValue(), ioe.getMessage());
      err.println(message);
      return LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR;
    }


    LDIFExportConfig exportConfig =
         new LDIFExportConfig(targetFile.getValue(),
                              ExistingFileBehavior.OVERWRITE);
    LDIFWriter targetWriter;
    try
    {
      targetWriter = new LDIFWriter(exportConfig);
    }
    catch (IOException ioe)
    {
      Message message = ERR_LDIFMODIFY_CANNOT_OPEN_TARGET.get(
              sourceFile.getValue(), ioe.getMessage());
      err.println(message);
      return LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR;
    }


    // Actually invoke the LDIF procesing.
    LinkedList<Message> errorList = new LinkedList<Message>();
    boolean successful;
    try
    {
      successful = modifyLDIF(sourceReader, changeReader, targetWriter,
                              errorList);
    }
    catch (Exception e)
    {
      Message message = ERR_LDIFMODIFY_ERROR_PROCESSING_LDIF.get(
              String.valueOf(e));
      err.println(message);

      successful = false;
    }

    try
    {
      sourceReader.close();
    } catch (Exception e) {}

    try
    {
      changeReader.close();
    } catch (Exception e) {}

    try
    {
      targetWriter.close();
View Full Code Here

        catch (Exception e) {}
      }
    }

    // Open the source LDIF file and read it into a tree map.
    LDIFReader reader;
    LDIFImportConfig importConfig = new LDIFImportConfig(sourceLDIF.getValue());
    try
    {
      reader = new LDIFReader(importConfig);
    }
    catch (Exception e)
    {
      Message message = ERR_LDIFDIFF_CANNOT_OPEN_SOURCE_LDIF.get(
              sourceLDIF.getValue(),
              String.valueOf(e));
      err.println(message);
      return 1;
    }

    TreeMap<DN,Entry> sourceMap = new TreeMap<DN,Entry>();
    try
    {
      while (true)
      {
        Entry entry = reader.readEntry(checkSchema);
        if (entry == null)
        {
          break;
        }

        if (! ignoreEntries.contains(entry.getDN()))
        {
          sourceMap.put(entry.getDN(), entry);
        }
      }
    }
    catch (Exception e)
    {
      Message message = ERR_LDIFDIFF_ERROR_READING_SOURCE_LDIF.get(
              sourceLDIF.getValue(),
              String.valueOf(e));
      err.println(message);
      return 1;
    }
    finally
    {
      try
      {
        reader.close();
      } catch (Exception e) {}
    }


    // Open the target LDIF file and read it into a tree map.
    importConfig = new LDIFImportConfig(targetLDIF.getValue());
    try
    {
      reader = new LDIFReader(importConfig);
    }
    catch (Exception e)
    {
      Message message = ERR_LDIFDIFF_CANNOT_OPEN_TARGET_LDIF.get(
              targetLDIF.getValue(),
              String.valueOf(e));
      err.println(message);
      return 1;
    }

    TreeMap<DN,Entry> targetMap = new TreeMap<DN,Entry>();
    try
    {
      while (true)
      {
        Entry entry = reader.readEntry(checkSchema);
        if (entry == null)
        {
          break;
        }

        if (! ignoreEntries.contains(entry.getDN()))
        {
          targetMap.put(entry.getDN(), entry);
        }
      }
    }
    catch (Exception e)
    {
      Message message = ERR_LDIFDIFF_ERROR_READING_TARGET_LDIF.get(
              targetLDIF.getValue(),
              String.valueOf(e));
      err.println(message);
      return 1;
    }
    finally
    {
      try
      {
        reader.close();
      } catch (Exception e) {}
    }


    // Open the output writer that we'll use to write the differences.
View Full Code Here

TOP

Related Classes of org.nasutekds.server.util.LDIFReader

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.