Minor polishing.

This commit is contained in:
Mattias Hellborg Arthursson
2013-11-18 16:46:04 +01:00
parent 086497d66e
commit b9985e5759
42 changed files with 378 additions and 403 deletions

View File

@@ -85,7 +85,7 @@ import java.util.NoSuchElementException;
*/
public class LdifParser implements Parser, InitializingBean {
private static final Logger log = LoggerFactory.getLogger(LdifParser.class);
private static final Logger LOG = LoggerFactory.getLogger(LdifParser.class);
/**
* The resource to parse.
@@ -227,7 +227,7 @@ public class LdifParser implements Parser, InitializingBean {
Assert.notNull(reader, "A reader must be obtained: parser not open.");
if (!reader.ready()) {
log.debug("Reader not ready!");
LOG.debug("Reader not ready!");
return null;
}
@@ -242,7 +242,7 @@ public class LdifParser implements Parser, InitializingBean {
switch(identifier) {
case NewRecord:
log.trace("Starting new record.");
LOG.trace("Starting new record.");
//Start new record.
record = new LdapAttributes(caseInsensitive);
builder = new StringBuilder(line);
@@ -250,20 +250,20 @@ public class LdifParser implements Parser, InitializingBean {
break;
case Control:
log.trace("'control' encountered.");
LOG.trace("'control' encountered.");
//Log WARN and discard record.
log.warn("LDIF change records have no implementation: record will be ignored.");
LOG.warn("LDIF change records have no implementation: record will be ignored.");
builder = null;
record = null;
break;
case ChangeType:
log.trace("'changetype' encountered.");
LOG.trace("'changetype' encountered.");
//Log WARN and discard record.
log.warn("LDIF change records have no implementation: record will be ignored.");
LOG.warn("LDIF change records have no implementation: record will be ignored.");
builder = null;
record = null;
@@ -273,21 +273,21 @@ public class LdifParser implements Parser, InitializingBean {
//flush buffer.
addAttributeToRecord(builder.toString(), record);
log.trace("Starting new attribute.");
LOG.trace("Starting new attribute.");
//Start new attribute.
builder = new StringBuilder(line);
break;
case Continuation:
log.trace("...appending line to buffer.");
LOG.trace("...appending line to buffer.");
//Append line to buffer.
builder.append(line.replaceFirst(" ", ""));
break;
case EndOfRecord:
log.trace("...done parsing record. (EndOfRecord)");
LOG.trace("...done parsing record. (EndOfRecord)");
//Validate record and return.
if (record == null) {
@@ -298,14 +298,14 @@ public class LdifParser implements Parser, InitializingBean {
addAttributeToRecord(builder.toString(), record);
if (specification.isSatisfiedBy(record)) {
log.debug("record parsed:\n" + record);
LOG.debug("record parsed:\n" + record);
return record;
} else {
throw new InvalidRecordFormatException("Record [dn: " + record.getDN() + "] does not conform to specification.");
}
} catch(NamingException e) {
log.error("Error adding attribute to record", e);
LOG.error("Error adding attribute to record", e);
return null;
}
}
@@ -330,7 +330,7 @@ public class LdifParser implements Parser, InitializingBean {
Attribute attribute = attributePolicy.parse(buffer);
if (attribute.getID().equalsIgnoreCase("dn")) {
log.trace("...adding DN to record.");
LOG.trace("...adding DN to record.");
String dn;
if (attribute.get() instanceof byte[]) {
@@ -342,7 +342,7 @@ public class LdifParser implements Parser, InitializingBean {
record.setName(LdapUtils.newLdapName(dn));
} else {
log.trace("...adding attribute to record.");
LOG.trace("...adding attribute to record.");
Attribute attr = record.get(attribute.getID());
if (attr != null) {
@@ -353,9 +353,9 @@ public class LdifParser implements Parser, InitializingBean {
}
}
} catch (NamingException e) {
log.error("Error adding attribute to record", e);
LOG.error("Error adding attribute to record", e);
} catch (NoSuchElementException e) {
log.error("Error adding attribute to record", e);
LOG.error("Error adding attribute to record", e);
}
}

View File

@@ -15,11 +15,10 @@
*/
package org.springframework.ldap.ldif.parser;
import java.io.IOException;
import org.springframework.core.io.Resource;
import javax.naming.directory.Attributes;
import org.springframework.core.io.Resource;
import java.io.IOException;
/**
* The Parser interface represents the required methods to be implemented by parser utilities.
@@ -34,35 +33,35 @@ public interface Parser {
*
* @param resource The resource to parse.
*/
public void setResource(Resource resource);
void setResource(Resource resource);
/**
* Sets the control parameter for specifying case sensitivity on creation of the {@link Attributes} object.
*
* @param caseInsensitive The resource to parse.
*/
public void setCaseInsensitive(boolean caseInsensitive);
void setCaseInsensitive(boolean caseInsensitive);
/**
* Opens the resource: the resource must be opened prior to parsing.
*
* @throws IOException if a problem is encountered while trying to open the resource.
*/
public void open() throws IOException;
void open() throws IOException;
/**
* Closes the resource after parsing.
*
* @throws IOException if a problem is encountered while trying to close the resource.
*/
public void close() throws IOException;
void close() throws IOException;
/**
* Resets the line read parser.
*
* @throws Exception if a problem is encountered while trying to reset the resource.
*/
public void reset() throws IOException;
void reset() throws IOException;
/**
* True if the resource contains more records; false otherwise.
@@ -70,7 +69,7 @@ public interface Parser {
* @return boolean indicating whether or not the end of record has been reached.
* @throws IOException if a problem is encountered while trying to validate the resource is ready.
*/
public boolean hasMoreRecords() throws IOException;
boolean hasMoreRecords() throws IOException;
/**
* Parses the next record from the resource.
@@ -78,7 +77,7 @@ public interface Parser {
* @return LdapAttributes object representing the record parsed.
* @throws IOException if a problem is encountered while trying to read from the resource.
*/
public Attributes getRecord() throws IOException;
Attributes getRecord() throws IOException;
/**
* Indicates whether or not the parser is ready to to return results.
@@ -86,5 +85,5 @@ public interface Parser {
* @return boolean indicator
* @throws IOException if there is a problem with the underlying resource.
*/
public boolean isReady() throws IOException;
boolean isReady() throws IOException;
}

View File

@@ -48,7 +48,7 @@ public class SeparatorPolicy {
private static final String COMMENT = "#";
private static final String NewRecord = "^dn:.*$";
private static final String NEW_RECORD = "^dn:.*$";
private boolean record = false;
@@ -103,7 +103,7 @@ public class SeparatorPolicy {
//Version Identifiers are ignored by parser.
return LineIdentifier.VersionIdentifier;
} else if (StringUtils.hasLength(line) && line.matches(NewRecord)) {
} else if (StringUtils.hasLength(line) && line.matches(NEW_RECORD)) {
record = true;
skip = false;
return LineIdentifier.NewRecord;