You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2006/12/18 18:32:09 UTC
svn commit: r488355 [3/10] - in /directory/sandbox/pamarcelot/ldapstudio:
ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/
ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/filter/
ldapstudio-browse...
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifDeloldrdnLine.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifDeloldrdnLine.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifDeloldrdnLine.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifDeloldrdnLine.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.model.ldif.lines;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+
+
+public class LdifDeloldrdnLine extends LdifValueLineBase
+{
+
+ private static final long serialVersionUID = 7427736453871426864L;
+
+
+ protected LdifDeloldrdnLine()
+ {
+ }
+
+
+ public LdifDeloldrdnLine( int offset, String rawDeleteOldrdnSpec, String rawValueType, String rawDeleteOldrdn,
+ String rawNewLine )
+ {
+ super( offset, rawDeleteOldrdnSpec, rawValueType, rawDeleteOldrdn, rawNewLine );
+ }
+
+
+ public String getRawDeleteOldrdnSpec()
+ {
+ return super.getRawLineStart();
+ }
+
+
+ public String getUnfoldedDeleteOldrdnSpec()
+ {
+ return super.getUnfoldedLineStart();
+ }
+
+
+ public String getRawDeleteOldrdn()
+ {
+ return super.getRawValue();
+ }
+
+
+ public String getUnfoldedDeleteOldrdn()
+ {
+ return super.getUnfoldedValue();
+ }
+
+
+ public boolean isDeleteOldRdn()
+ {
+ return "1".equals( this.getUnfoldedDeleteOldrdn() );
+ }
+
+
+ public String toRawString()
+ {
+ return super.toRawString();
+ }
+
+
+ public boolean isValid()
+ {
+ if ( !super.isValid() )
+ return false;
+
+ return ( "0".equals( getUnfoldedDeleteOldrdn() ) || "1".equals( getUnfoldedDeleteOldrdn() ) );
+ }
+
+
+ public String getInvalidString()
+ {
+ if ( this.getUnfoldedDeleteOldrdnSpec().length() == 0 )
+ {
+ return "Missing delete old RDN spec 'deleteoldrdn'";
+ }
+ else if ( !"0".equals( getUnfoldedDeleteOldrdn() ) && !"1".equals( getUnfoldedDeleteOldrdn() ) )
+ {
+ return "Invalid value of delete old RDN, must be '0' or '1'";
+ }
+ else
+ {
+ return super.getInvalidString();
+ }
+ }
+
+
+ public static LdifDeloldrdnLine create0()
+ {
+ return new LdifDeloldrdnLine( 0, "deleteoldrdn", ":", "0", BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+
+ public static LdifDeloldrdnLine create1()
+ {
+ return new LdifDeloldrdnLine( 0, "deleteoldrdn", ":", "1", BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifDnLine.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifDnLine.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifDnLine.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifDnLine.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.model.ldif.lines;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.utils.LdifUtils;
+
+
+public class LdifDnLine extends LdifValueLineBase
+{
+
+ private static final long serialVersionUID = 6180172049870560007L;
+
+
+ protected LdifDnLine()
+ {
+ }
+
+
+ public LdifDnLine( int offset, String rawDnSpec, String rawValueType, String rawDn, String rawNewLine )
+ {
+ super( offset, rawDnSpec, rawValueType, rawDn, rawNewLine );
+ }
+
+
+ public String getRawDnSpec()
+ {
+ return super.getRawLineStart();
+ }
+
+
+ public String getUnfoldedDnSpec()
+ {
+ return super.getUnfoldedLineStart();
+ }
+
+
+ public String getRawDn()
+ {
+ return super.getRawValue();
+ }
+
+
+ public String getUnfoldedDn()
+ {
+ return super.getUnfoldedValue();
+ }
+
+
+ public String toRawString()
+ {
+ return super.toRawString();
+ }
+
+
+ public boolean isValid()
+ {
+ return super.isValid();
+ }
+
+
+ public String getInvalidString()
+ {
+ if ( this.getUnfoldedDnSpec().length() == 0 )
+ {
+ return "Missing DN spec 'dn'";
+ }
+ else if ( this.getUnfoldedDn().length() == 0 )
+ {
+ return "Missing DN";
+ }
+ else
+ {
+ return super.getInvalidString();
+ }
+ }
+
+
+ public static LdifDnLine create( String dn )
+ {
+ if ( LdifUtils.mustEncode( dn ) )
+ {
+ return new LdifDnLine( 0, "dn", "::", LdifUtils.base64encode( LdifUtils.utf8encode( dn ) ),
+ BrowserCoreConstants.LINE_SEPARATOR );
+ }
+ else
+ {
+ return new LdifDnLine( 0, "dn", ":", dn, BrowserCoreConstants.LINE_SEPARATOR );
+ }
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifLineBase.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifLineBase.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifLineBase.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifLineBase.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,207 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.model.ldif.lines;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifPart;
+import org.eclipse.core.runtime.Preferences;
+
+
+/**
+ * Base class for all lines in a LDIF file.
+ *
+ *
+ */
+public abstract class LdifLineBase implements LdifPart
+{
+
+ private String rawNewLine;
+
+ private int offset;
+
+
+ protected LdifLineBase()
+ {
+ }
+
+
+ protected LdifLineBase( int offset, String rawNewLine )
+ {
+ super();
+ this.rawNewLine = rawNewLine;
+ this.offset = offset;
+ }
+
+
+ public final String getRawNewLine()
+ {
+ return getNonNull( this.rawNewLine );
+ }
+
+
+ public String getUnfoldedNewLine()
+ {
+ return unfold( this.getRawNewLine() );
+ }
+
+
+ public final void adjustOffset( int adjust )
+ {
+ this.offset += adjust;
+ }
+
+
+ public final int getOffset()
+ {
+ return this.offset;
+ }
+
+
+ public final int getLength()
+ {
+ return this.toRawString().length();
+ }
+
+
+ public boolean isValid()
+ {
+ return this.rawNewLine != null;
+ }
+
+
+ public String getInvalidString()
+ {
+ if ( this.rawNewLine == null )
+ {
+ return "Missing new line";
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ public String toRawString()
+ {
+ return this.getRawNewLine();
+ }
+
+
+ public final String toFormattedString()
+ {
+
+ Preferences store = BrowserCorePlugin.getDefault().getPluginPreferences();
+ boolean spaceAfterColon = store.getBoolean( BrowserCoreConstants.PREFERENCE_LDIF_SPACE_AFTER_COLON );
+ String lineSeparator = store.getString( BrowserCoreConstants.PREFERENCE_LDIF_LINE_SEPARATOR );
+
+ String raw = toRawString();
+ String unfolded = unfold( raw );
+
+ if ( this instanceof LdifValueLineBase )
+ {
+ if ( unfolded.indexOf( "::" ) > -1 )
+ {
+ unfolded = unfolded.replaceFirst( "::[ ]*", spaceAfterColon ? ":: " : "::" );
+ }
+ else if ( unfolded.indexOf( ":<" ) > -1 )
+ {
+ unfolded = unfolded.replaceFirst( ":<[ ]*", spaceAfterColon ? ":< " : ":<" );
+ }
+ else if ( unfolded.indexOf( ":" ) > -1 )
+ {
+ unfolded = unfolded.replaceFirst( ":[ ]*", spaceAfterColon ? ": " : ":" );
+ }
+ }
+
+ if ( rawNewLine != null )
+ {
+ int index = unfolded.lastIndexOf( rawNewLine );
+ if ( index > -1 )
+ {
+ unfolded = unfolded.substring( 0, unfolded.length() - rawNewLine.length() );
+ unfolded = unfolded + lineSeparator;
+ }
+ }
+
+ if ( this instanceof LdifValueLineBase )
+ {
+ return fold( unfolded, 0 );
+ }
+ else
+ {
+ return unfolded;
+ }
+ }
+
+
+ public final String toString()
+ {
+ String text = toRawString();
+ text = text.replaceAll( "\n", "\\\\n" );
+ text = text.replaceAll( "\r", "\\\\r" );
+ return getClass().getName() + " (" + getOffset() + "," + getLength() + "): '" + text + "'";
+ }
+
+
+ protected static String getNonNull( String s )
+ {
+ return s != null ? s : "";
+ }
+
+
+ protected static String unfold( String s )
+ {
+ s = s.replaceAll( "\n\r ", "" );
+ s = s.replaceAll( "\r\n ", "" );
+ s = s.replaceAll( "\n ", "" );
+ s = s.replaceAll( "\r ", "" );
+ return s;
+ }
+
+
+ protected static String fold( String value, int indent )
+ {
+ Preferences store = BrowserCorePlugin.getDefault().getPluginPreferences();
+ int lineWidth = store.getInt( BrowserCoreConstants.PREFERENCE_LDIF_LINE_WIDTH );
+ String lineSeparator = store.getString( BrowserCoreConstants.PREFERENCE_LDIF_LINE_SEPARATOR );
+
+ StringBuffer formattedLdif = new StringBuffer();
+ int offset = lineWidth - indent;
+ int endIndex = 0 + offset;
+ while ( endIndex + lineSeparator.length() < value.length() )
+ {
+ formattedLdif.append( value.substring( endIndex - offset, endIndex ) );
+ formattedLdif.append( lineSeparator );
+ formattedLdif.append( ' ' );
+ offset = lineWidth - 1;
+ endIndex += offset;
+ }
+ String rest = value.substring( endIndex - offset, value.length() );
+ formattedLdif.append( rest );
+
+ // return
+ return formattedLdif.toString();
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifModSpecSepLine.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifModSpecSepLine.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifModSpecSepLine.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifModSpecSepLine.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.model.ldif.lines;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+
+
+public class LdifModSpecSepLine extends LdifNonEmptyLineBase
+{
+
+ private static final long serialVersionUID = -6411592502825895865L;
+
+
+ protected LdifModSpecSepLine()
+ {
+ }
+
+
+ public LdifModSpecSepLine( int offset, String rawMinus, String rawNewLine )
+ {
+ super( offset, rawMinus, rawNewLine );
+ }
+
+
+ public String getRawMinus()
+ {
+ return super.getRawLineStart();
+ }
+
+
+ public String getUnfoldedMinus()
+ {
+ return super.getUnfoldedLineStart();
+ }
+
+
+ public String toRawString()
+ {
+ return super.toRawString();
+ }
+
+
+ public boolean isValid()
+ {
+ return super.isValid() && this.getUnfoldedMinus().equals( "-" );
+ }
+
+
+ public String getInvalidString()
+ {
+ if ( !this.getUnfoldedMinus().equals( "-" ) )
+ {
+ return "Missing '-'";
+ }
+ else
+ {
+ return super.getInvalidString();
+ }
+ }
+
+
+ public static LdifModSpecSepLine create()
+ {
+ return new LdifModSpecSepLine( 0, "-", BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifModSpecTypeLine.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifModSpecTypeLine.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifModSpecTypeLine.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifModSpecTypeLine.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.model.ldif.lines;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+
+
+public class LdifModSpecTypeLine extends LdifValueLineBase
+{
+
+ private static final long serialVersionUID = 82623220224991909L;
+
+
+ protected LdifModSpecTypeLine()
+ {
+ }
+
+
+ public LdifModSpecTypeLine( int offset, String rawModType, String rawValueType, String rawAttributeDescription,
+ String rawNewLine )
+ {
+ super( offset, rawModType, rawValueType, rawAttributeDescription, rawNewLine );
+ }
+
+
+ public String getRawModType()
+ {
+ return super.getRawLineStart();
+ }
+
+
+ public String getUnfoldedModType()
+ {
+ return super.getUnfoldedLineStart();
+ }
+
+
+ public String getRawAttributeDescription()
+ {
+ return super.getRawValue();
+ }
+
+
+ public String getUnfoldedAttributeDescription()
+ {
+ return super.getUnfoldedValue();
+ }
+
+
+ public String toRawString()
+ {
+ return super.toRawString();
+ }
+
+
+ public boolean isAdd()
+ {
+ return this.getUnfoldedModType().equals( "add" );
+ }
+
+
+ public boolean isReplace()
+ {
+ return this.getUnfoldedModType().equals( "replace" );
+ }
+
+
+ public boolean isDelete()
+ {
+ return this.getUnfoldedModType().equals( "delete" );
+ }
+
+
+ public boolean isValid()
+ {
+ return super.isValid() && ( this.isAdd() || this.isReplace() || this.isDelete() );
+ }
+
+
+ public String getInvalidString()
+ {
+ if ( this.getUnfoldedModType().length() == 0 )
+ {
+ return "Missing modification type 'add', 'replace' or 'delete'";
+ }
+ else if ( !this.isAdd() && !this.isReplace() && !this.isDelete() )
+ {
+ return "Invalid modification type, expected 'add', 'replace' or 'delete'";
+ }
+ else if ( this.getUnfoldedAttributeDescription().length() == 0 )
+ {
+ return "Missing attribute";
+ }
+ else
+ {
+ return super.getInvalidString();
+ }
+ }
+
+
+ public static LdifModSpecTypeLine createAdd( String attributeName )
+ {
+ return new LdifModSpecTypeLine( 0, "add", ":", attributeName, BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+
+ public static LdifModSpecTypeLine createReplace( String attributeName )
+ {
+ return new LdifModSpecTypeLine( 0, "replace", ":", attributeName, BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+
+ public static LdifModSpecTypeLine createDelete( String attributeName )
+ {
+ return new LdifModSpecTypeLine( 0, "delete", ":", attributeName, BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifNewrdnLine.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifNewrdnLine.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifNewrdnLine.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifNewrdnLine.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.model.ldif.lines;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.utils.LdifUtils;
+
+
+public class LdifNewrdnLine extends LdifValueLineBase
+{
+
+ private static final long serialVersionUID = -4393976438427677361L;
+
+
+ protected LdifNewrdnLine()
+ {
+ }
+
+
+ public LdifNewrdnLine( int offset, String rawNewrdnSpec, String rawValueType, String rawNewrdn, String rawNewLine )
+ {
+ super( offset, rawNewrdnSpec, rawValueType, rawNewrdn, rawNewLine );
+ }
+
+
+ public String getRawNewrdnSpec()
+ {
+ return super.getRawLineStart();
+ }
+
+
+ public String getUnfoldedNewrdnSpec()
+ {
+ return super.getUnfoldedLineStart();
+ }
+
+
+ public String getRawNewrdn()
+ {
+ return super.getRawValue();
+ }
+
+
+ public String getUnfoldedNewrdn()
+ {
+ return super.getUnfoldedValue();
+ }
+
+
+ public String toRawString()
+ {
+ return super.toRawString();
+ }
+
+
+ public boolean isValid()
+ {
+ return super.isValid();
+ }
+
+
+ public String getInvalidString()
+ {
+ if ( this.getUnfoldedNewrdnSpec().length() == 0 )
+ {
+ return "Missing new RDN spec 'newrdn'";
+ }
+ else if ( this.getUnfoldedNewrdn().length() == 0 )
+ {
+ return "Missing new RDN";
+ }
+ else
+ {
+ return super.getInvalidString();
+ }
+ }
+
+
+ public static LdifNewrdnLine create( String newrdn )
+ {
+ if ( LdifUtils.mustEncode( newrdn ) )
+ {
+ return new LdifNewrdnLine( 0, "newrdn", "::", LdifUtils.base64encode( LdifUtils.utf8encode( newrdn ) ),
+ BrowserCoreConstants.LINE_SEPARATOR );
+ }
+ else
+ {
+ return new LdifNewrdnLine( 0, "newrdn", ":", newrdn, BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifNewsuperiorLine.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifNewsuperiorLine.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifNewsuperiorLine.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifNewsuperiorLine.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.model.ldif.lines;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.utils.LdifUtils;
+
+
+public class LdifNewsuperiorLine extends LdifValueLineBase
+{
+
+ private static final long serialVersionUID = -8614298286815271694L;
+
+
+ protected LdifNewsuperiorLine()
+ {
+ }
+
+
+ public LdifNewsuperiorLine( int offset, String rawNewSuperiorSpec, String rawValueType, String rawNewSuperiorDn,
+ String rawNewLine )
+ {
+ super( offset, rawNewSuperiorSpec, rawValueType, rawNewSuperiorDn, rawNewLine );
+ }
+
+
+ public String getRawNewSuperiorSpec()
+ {
+ return super.getRawLineStart();
+ }
+
+
+ public String getUnfoldedNewSuperiorSpec()
+ {
+ return super.getUnfoldedLineStart();
+ }
+
+
+ public String getRawNewSuperiorDn()
+ {
+ return super.getRawValue();
+ }
+
+
+ public String getUnfoldedNewSuperiorDn()
+ {
+ return super.getUnfoldedValue();
+ }
+
+
+ public String toRawString()
+ {
+ return super.toRawString();
+ }
+
+
+ public boolean isValid()
+ {
+ return super.isValid();
+ }
+
+
+ public String getInvalidString()
+ {
+ if ( this.getUnfoldedNewSuperiorSpec().length() == 0 )
+ {
+ return "Missing new superior spec 'newsuperior'";
+ }
+ else if ( this.getUnfoldedNewSuperiorDn().length() == 0 )
+ {
+ return "Missing new superior DN";
+ }
+ else
+ {
+ return super.getInvalidString();
+ }
+ }
+
+
+ public static LdifNewsuperiorLine create( String newsuperior )
+ {
+ if ( LdifUtils.mustEncode( newsuperior ) )
+ {
+ return new LdifNewsuperiorLine( 0, "newsuperior", "::", LdifUtils.base64encode( LdifUtils
+ .utf8encode( newsuperior ) ), BrowserCoreConstants.LINE_SEPARATOR );
+ }
+ else
+ {
+ return new LdifNewsuperiorLine( 0, "newsuperior", ":", newsuperior, BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifNonEmptyLineBase.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifNonEmptyLineBase.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifNonEmptyLineBase.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifNonEmptyLineBase.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.model.ldif.lines;
+
+
+public abstract class LdifNonEmptyLineBase extends LdifLineBase
+{
+
+ private String rawLineStart;
+
+
+ protected LdifNonEmptyLineBase()
+ {
+ }
+
+
+ public LdifNonEmptyLineBase( int offset, String rawLineStart, String rawNewLine )
+ {
+ super( offset, rawNewLine );
+ this.rawLineStart = rawLineStart;
+ }
+
+
+ public String getRawLineStart()
+ {
+ return getNonNull( this.rawLineStart );
+ }
+
+
+ public String getUnfoldedLineStart()
+ {
+ return unfold( this.getRawLineStart() );
+ }
+
+
+ public boolean isValid()
+ {
+ return super.isValid() && this.rawLineStart != null;
+ }
+
+
+ public String getInvalidString()
+ {
+ if ( this.rawLineStart == null )
+ {
+ return "Missing line start";
+ }
+ else
+ {
+ return super.getInvalidString();
+ }
+ }
+
+
+ public String toRawString()
+ {
+ return this.getRawLineStart() + this.getRawNewLine();
+ }
+
+
+ public boolean isFolded()
+ {
+ String rawString = toRawString();
+ return rawString.indexOf( "\n " ) > -1 || rawString.indexOf( "\r " ) > -1;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifSepLine.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifSepLine.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifSepLine.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifSepLine.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.model.ldif.lines;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+
+
+public class LdifSepLine extends LdifLineBase
+{
+
+ private static final long serialVersionUID = 1682910718363816158L;
+
+
+ protected LdifSepLine()
+ {
+ }
+
+
+ public LdifSepLine( int offset, String rawNewLine )
+ {
+ super( offset, rawNewLine );
+ }
+
+
+ public static LdifSepLine create()
+ {
+ return new LdifSepLine( 0, BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifValueLineBase.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifValueLineBase.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifValueLineBase.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifValueLineBase.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,215 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.model.ldif.lines;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import org.apache.directory.ldapstudio.browser.core.utils.LdifUtils;
+
+
+public class LdifValueLineBase extends LdifNonEmptyLineBase
+{
+
+ private static final long serialVersionUID = -7030930374861554147L;
+
+ private String rawValueType;
+
+ private String rawValue;
+
+
+ protected LdifValueLineBase()
+ {
+ }
+
+
+ public LdifValueLineBase( int offset, String rawLineStart, String rawValueType, String rawValue, String rawNewLine )
+ {
+ super( offset, rawLineStart, rawNewLine );
+
+ this.rawValueType = rawValueType;
+ this.rawValue = rawValue;
+ }
+
+
+ public String getRawValueType()
+ {
+ return getNonNull( this.rawValueType );
+ }
+
+
+ public String getUnfoldedValueType()
+ {
+ return unfold( this.getRawValueType() );
+ }
+
+
+ public String getRawValue()
+ {
+ return getNonNull( this.rawValue );
+ }
+
+
+ public String getUnfoldedValue()
+ {
+ return unfold( this.getRawValue() );
+ }
+
+
+ public String toRawString()
+ {
+ return this.getRawLineStart() + this.getRawValueType() + this.getRawValue() + this.getRawNewLine();
+ }
+
+
+ public boolean isValid()
+ {
+ return super.isValid() && this.rawValueType != null && this.rawValue != null;
+ }
+
+
+ public String getInvalidString()
+ {
+ if ( this.rawValueType == null )
+ {
+ return "Missing value type ':', '::' or ':<'";
+ }
+ else if ( this.rawValue == null )
+ {
+ return "Missing value";
+ }
+ else
+ {
+ return super.getInvalidString();
+ }
+ }
+
+
+ /**
+ *
+ * @return the string representation of the value, non-base64, unfolded
+ */
+ public final String getValueAsString()
+ {
+ Object o = getValueAsObject();
+ if ( o instanceof String )
+ {
+ return ( String ) o;
+ }
+ else if ( o instanceof byte[] )
+ {
+ return LdifUtils.utf8decode( ( byte[] ) o );
+ }
+ else
+ {
+ return "";
+ }
+ }
+
+
+ /**
+ *
+ * @return the binary representation of the real value, non-base64,
+ * unfolded
+ */
+ public final byte[] getValueAsBinary()
+ {
+ Object o = getValueAsObject();
+ if ( o instanceof String )
+ {
+ return LdifUtils.utf8encode( ( String ) o );
+ }
+ else if ( o instanceof byte[] )
+ {
+ return ( byte[] ) o;
+ }
+ else
+ {
+ return new byte[0];
+ }
+ }
+
+
+ /**
+ * Returns the real data:
+ * <ul>
+ * <li>The unfolded String if value is a safe value.
+ * </ul>
+ * <li>A byte array if value is base64 encoded.
+ * </ul>
+ * <li>A byte array if value references an URL.
+ * </ul>
+ * </ul>
+ *
+ * @return the real value or null
+ */
+ public final Object getValueAsObject()
+ {
+ if ( this.isValueTypeSafe() )
+ {
+ return this.getUnfoldedValue();
+ }
+ else if ( this.isValueTypeBase64() )
+ {
+ return LdifUtils.base64decodeToByteArray( this.getUnfoldedValue() );
+ }
+ else if ( this.isValueTypeURL() )
+ {
+ try
+ {
+ File file = new File( this.getUnfoldedValue() );
+ byte[] data = new byte[( int ) file.length()];
+ FileInputStream fis = new FileInputStream( file );
+ fis.read( data );
+ return data;
+ }
+ catch ( IOException ioe )
+ {
+ return null;
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ public boolean isValueTypeURL()
+ {
+ return this.getUnfoldedValueType().startsWith( ":<" );
+ }
+
+
+ public boolean isValueTypeBase64()
+ {
+ return this.getUnfoldedValueType().startsWith( "::" );
+ }
+
+
+ public boolean isValueTypeSafe()
+ {
+ return this.getUnfoldedValueType().startsWith( ":" ) && !this.isValueTypeBase64() && !this.isValueTypeURL();
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifVersionLine.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifVersionLine.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifVersionLine.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/lines/LdifVersionLine.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.model.ldif.lines;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+
+
+public class LdifVersionLine extends LdifValueLineBase
+{
+
+ private static final long serialVersionUID = 7302151354496025254L;
+
+
+ protected LdifVersionLine()
+ {
+ }
+
+
+ public LdifVersionLine( int offset, String rawVersionSpec, String rawValueType, String rawVersion, String rawNewLine )
+ {
+ super( offset, rawVersionSpec, rawValueType, rawVersion, rawNewLine );
+ }
+
+
+ public String getRawVersionSpec()
+ {
+ return super.getRawLineStart();
+ }
+
+
+ public String getUnfoldedVersionSpec()
+ {
+ return super.getUnfoldedLineStart();
+ }
+
+
+ public String getRawVersion()
+ {
+ return super.getRawValue();
+ }
+
+
+ public String getUnfoldedVersion()
+ {
+ return super.getUnfoldedValue();
+ }
+
+
+ public String toRawString()
+ {
+ return super.toRawString();
+ }
+
+
+ public boolean isValid()
+ {
+ return super.isValid();
+ }
+
+
+ public String getInvalidString()
+ {
+ if ( this.getUnfoldedVersionSpec().length() == 0 )
+ {
+ return "Missing version spec";
+ }
+ else if ( this.getUnfoldedVersion().length() == 0 )
+ {
+ return "Missing version";
+ }
+ else
+ {
+ return super.getInvalidString();
+ }
+ }
+
+
+ public static LdifVersionLine create()
+ {
+ return new LdifVersionLine( 0, "version", ":", "1", BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/DummyLdifContainer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/DummyLdifContainer.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/DummyLdifContainer.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/DummyLdifContainer.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.model.ldif.parser;
+
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifPart;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifCommentLine;
+
+
+public class DummyLdifContainer extends LdifContainer
+{
+
+ private static final long serialVersionUID = -6712132529064161996L;
+
+
+ public DummyLdifContainer( LdifPart part )
+ {
+ super( part );
+ }
+
+
+ public LdifCommentLine[] getComments()
+ {
+ List l = new ArrayList();
+ for ( Iterator it = this.parts.iterator(); it.hasNext(); )
+ {
+ Object o = it.next();
+ if ( o instanceof LdifCommentLine )
+ {
+ l.add( o );
+ }
+ }
+ return ( LdifCommentLine[] ) l.toArray( new LdifCommentLine[l.size()] );
+ }
+
+
+ public boolean isValid()
+ {
+ return false;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/LdifParser.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/LdifParser.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/LdifParser.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/LdifParser.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,1078 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.core.model.ldif.parser;
+
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.internal.model.ConnectionException;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifEOFPart;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifEnumeration;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifInvalidPart;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeAddRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeDeleteRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeModDnRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeModifyRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifCommentContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContentRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifEOFContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifInvalidContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifModSpec;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifRecord;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifSepContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifVersionContainer;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifAttrValLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifChangeTypeLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifCommentLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifControlLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifDeloldrdnLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifDnLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifModSpecSepLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifModSpecTypeLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifNewrdnLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifNewsuperiorLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifSepLine;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifVersionLine;
+
+
+public class LdifParser
+{
+
+ private LdifScanner scanner;
+
+
+ public LdifParser()
+ {
+ this.scanner = new LdifScanner();
+ }
+
+
+ public LdifFile parse( String ldif )
+ {
+
+ LdifFile model = new LdifFile();
+
+ try
+ {
+ LdifEnumeration enumeration = this.parse( new StringReader( ldif ) );
+ while ( enumeration.hasNext( null ) )
+ {
+ LdifContainer container = enumeration.next( null );
+ model.addContainer( container );
+ }
+ }
+ catch ( ConnectionException e )
+ {
+ // doesn't occur on the internal LdifEnumeration implementation
+ }
+
+ return model;
+ }
+
+
+ public LdifEnumeration parse( Reader ldifReader )
+ {
+
+ this.scanner.setLdif( ldifReader );
+
+ LdifEnumeration enumeration = new LdifEnumeration()
+ {
+
+ private List containerList = new ArrayList();
+
+ private boolean headerParsed = false;
+
+ private boolean bodyParsed = false;
+
+ private boolean footerParsed = false;
+
+
+ public boolean hasNext( org.apache.directory.ldapstudio.browser.core.jobs.ExtendedProgressMonitor monitor )
+ {
+ if ( containerList.isEmpty() )
+ {
+
+ LdifFile model = new LdifFile();
+
+ // parse header
+ if ( !headerParsed )
+ {
+ checkAndParseComment( model );
+ checkAndParseVersion( model );
+ checkAndParseComment( model );
+ headerParsed = true;
+ }
+
+ // parse body (in a loop)
+ if ( headerParsed && !bodyParsed )
+ {
+ // parse comment lines
+ if ( !checkAndParseComment( model ) )
+ {
+ // parse record
+ if ( !checkAndParseRecord( model ) )
+ {
+ // parse unknown
+ if ( !checkAndParseOther( model ) )
+ {
+ // end of body
+ bodyParsed = true;
+ }
+ }
+ }
+ }
+
+ // parse footer
+ if ( headerParsed && bodyParsed && !footerParsed )
+ {
+ checkAndParseComment( model );
+ footerParsed = true;
+ }
+
+ LdifContainer[] containers = model.getContainers();
+ this.containerList.addAll( Arrays.asList( containers ) );
+ return !containerList.isEmpty() && !( containers[0] instanceof LdifEOFContainer );
+
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+
+ public LdifContainer next( org.apache.directory.ldapstudio.browser.core.jobs.ExtendedProgressMonitor monitor )
+ {
+ if ( hasNext( monitor ) )
+ {
+ return ( LdifContainer ) this.containerList.remove( 0 );
+ }
+ else
+ {
+ return null;
+ }
+ }
+ };
+
+ return enumeration;
+ }
+
+
+ // public LdifEnumeration parse(Reader ldifReader) {
+ //
+ // this.scanner.setLdif(ldifReader);
+ //
+ // LdifEnumeration enumeration = new LdifEnumeration(){
+ //
+ // private List containerList = new ArrayList();
+ //
+ // public boolean
+ // hasNext(org.apache.directory.ldapstudio.browser.core.jobs.ExtendedProgressMonitor
+ // monitor) {
+ // if(containerList.isEmpty()) {
+ // LdifFile model = parseFile();
+ // LdifContainer[] containers = model.getContainers();
+ // this.containerList.addAll(Arrays.asList(containers));
+ // return !containerList.isEmpty() && !(containers[0] instanceof
+ // LdifEOFContainer);
+ // }
+ // else {
+ // return true;
+ // }
+ // }
+ //
+ // public LdifContainer
+ // next(org.apache.directory.ldapstudio.browser.core.jobs.ExtendedProgressMonitor
+ // monitor) {
+ // if(hasNext(monitor)) {
+ // return (LdifContainer)this.containerList.remove(0);
+ // }
+ // else {
+ // return null;
+ // }
+ // }
+ // };
+ //
+ // return enumeration;
+ // }
+ //
+ // private LdifFile parseFile() {
+ //
+ // LdifFile model = new LdifFile();
+ //
+ // // start comment-version-comment
+ // checkAndParseComment(model);
+ // checkAndParseVersion(model);
+ // checkAndParseComment(model);
+ //
+ // parseRecords(model);
+ //
+ // checkAndParseComment(model);
+ //
+ // return model;
+ // }
+ //
+ // private void parseRecords(LdifFile model) {
+ // do {
+ // // parse comment lines
+ // if(!checkAndParseComment(model)) {
+ // // parse record
+ // if(!checkAndParseRecord(model)) {
+ // // parse unknown
+ // if(!checkAndParseOther(model)) {
+ // return;
+ // }
+ // }
+ // }
+ // }
+ // while(true);
+ //
+ // }
+
+ /**
+ * Checks for version line. If version line is present it is parsed and
+ * added to the given model.
+ *
+ * @param model
+ * the model
+ * @return true if version line was added to the model, false otherwise
+ */
+ private boolean checkAndParseRecord( LdifFile model )
+ {
+
+ // record starts with dn-spec
+ LdifToken dnSpecToken = this.scanner.matchDnSpec();
+ if ( dnSpecToken == null )
+ {
+ return false;
+ }
+
+ // get DN
+ LdifToken dnValueTypeToken = null;
+ LdifToken dnToken = null;
+ LdifToken dnSepToken = null;
+ dnValueTypeToken = this.scanner.matchValueType();
+ if ( dnValueTypeToken != null )
+ {
+ dnToken = this.scanner.matchValue();
+ if ( dnToken != null )
+ {
+ dnSepToken = this.scanner.matchSep();
+ }
+ }
+ LdifDnLine dnLine = new LdifDnLine( dnSpecToken.getOffset(), getValueOrNull( dnSpecToken ),
+ getValueOrNull( dnValueTypeToken ), getValueOrNull( dnToken ), getValueOrNull( dnSepToken ) );
+ LdifToken dnErrorToken = null;
+ if ( dnSepToken == null )
+ {
+ dnErrorToken = this.scanner.matchCleanupLine();
+ }
+
+ // save comment lines after dns
+ LdifCommentLine[] commentLines = getCommentLines();
+
+ // check record type: to decide the record type we need the next token
+ // first check keywords 'control' and 'changetype'
+ LdifControlLine controlLine = getControlLine();
+ LdifChangeTypeLine changeTypeLine = getChangeTypeLine();
+ if ( controlLine != null || changeTypeLine != null )
+ {
+
+ LdifChangeRecord record = null;
+
+ // save all parts before changetype line
+ List partList = new ArrayList();
+ if ( dnErrorToken != null )
+ {
+ partList.add( new LdifInvalidPart( dnErrorToken.getOffset(), dnErrorToken.getValue() ) );
+ }
+ for ( int i = 0; i < commentLines.length; i++ )
+ {
+ partList.add( commentLines[i] );
+ }
+ if ( controlLine != null )
+ {
+ partList.add( controlLine );
+ if ( !controlLine.isValid() )
+ {
+ LdifToken errorToken = this.cleanupLine();
+ if ( errorToken != null )
+ {
+ partList.add( new LdifInvalidPart( errorToken.getOffset(), errorToken.getValue() ) );
+ }
+ }
+ }
+
+ // save comments and controls before changetype line
+ while ( changeTypeLine == null && ( commentLines.length > 0 || controlLine != null ) )
+ {
+
+ commentLines = getCommentLines();
+ for ( int i = 0; i < commentLines.length; i++ )
+ {
+ partList.add( commentLines[i] );
+ }
+
+ controlLine = getControlLine();
+ if ( controlLine != null )
+ {
+ partList.add( controlLine );
+ if ( !controlLine.isValid() )
+ {
+ LdifToken errorToken = this.cleanupLine();
+ if ( errorToken != null )
+ {
+ partList.add( new LdifInvalidPart( errorToken.getOffset(), errorToken.getValue() ) );
+ }
+ }
+ }
+
+ changeTypeLine = getChangeTypeLine();
+ }
+
+ if ( changeTypeLine != null )
+ {
+
+ if ( changeTypeLine.isAdd() )
+ {
+ record = new LdifChangeAddRecord( dnLine );
+ append( record, partList );
+ record.setChangeType( changeTypeLine );
+ if ( !changeTypeLine.isValid() )
+ {
+ this.cleanupLine( record );
+ }
+ parseAttrValRecord( record );
+ }
+ else if ( changeTypeLine.isDelete() )
+ {
+ record = new LdifChangeDeleteRecord( dnLine );
+ append( record, partList );
+ record.setChangeType( changeTypeLine );
+ if ( !changeTypeLine.isValid() )
+ {
+ this.cleanupLine( record );
+ }
+ parseChangeDeleteRecord( record );
+ }
+ else if ( changeTypeLine.isModify() )
+ {
+ record = new LdifChangeModifyRecord( dnLine );
+ append( record, partList );
+ record.setChangeType( changeTypeLine );
+ if ( !changeTypeLine.isValid() )
+ {
+ this.cleanupLine( record );
+ }
+ parseChangeModifyRecord( ( LdifChangeModifyRecord ) record );
+ }
+ else if ( changeTypeLine.isModDn() )
+ {
+ record = new LdifChangeModDnRecord( dnLine );
+ append( record, partList );
+ record.setChangeType( changeTypeLine );
+ if ( !changeTypeLine.isValid() )
+ {
+ this.cleanupLine( record );
+ }
+ parseChangeModDnRecord( ( LdifChangeModDnRecord ) record );
+ }
+ else
+ {
+ record = new LdifChangeRecord( dnLine );
+ append( record, partList );
+ record.setChangeType( changeTypeLine );
+ if ( !changeTypeLine.isValid() )
+ {
+ this.cleanupLine( record );
+ }
+ }
+ }
+ else
+ {
+ record = new LdifChangeRecord( dnLine );
+ append( record, partList );
+ }
+
+ model.addContainer( record );
+ }
+ else
+ {
+ // match attr-val-record
+ LdifContentRecord record = new LdifContentRecord( dnLine );
+ if ( dnErrorToken != null )
+ {
+ record.addInvalid( new LdifInvalidPart( dnErrorToken.getOffset(), dnErrorToken.getValue() ) );
+ }
+ for ( int i = 0; i < commentLines.length; i++ )
+ {
+ record.addComment( commentLines[i] );
+ }
+ parseAttrValRecord( record );
+ model.addContainer( record );
+ }
+
+ return true;
+ }
+
+
+ private void append( LdifChangeRecord record, List partList )
+ {
+ for ( Iterator it = partList.iterator(); it.hasNext(); )
+ {
+ Object o = it.next();
+ if ( o instanceof LdifCommentLine )
+ record.addComment( ( LdifCommentLine ) o );
+ if ( o instanceof LdifControlLine )
+ record.addControl( ( LdifControlLine ) o );
+ if ( o instanceof LdifInvalidPart )
+ record.addInvalid( ( LdifInvalidPart ) o );
+ }
+ }
+
+
+ private void parseChangeDeleteRecord( LdifRecord record )
+ {
+ do
+ {
+ if ( checkAndParseEndOfRecord( record ) )
+ {
+ return;
+ }
+
+ if ( !checkAndParseComment( record ) && !checkAndParseOther( record ) )
+ {
+ return;
+ }
+ }
+ while ( true );
+ }
+
+
+ private void parseChangeModDnRecord( LdifChangeModDnRecord record )
+ {
+ // do {
+ if ( checkAndParseEndOfRecord( record ) )
+ {
+ return;
+ }
+
+ // comments
+ checkAndParseComment( record );
+
+ // read newrdn line
+ LdifToken newrdnSpecToken = this.scanner.matchNewrdnSpec();
+ if ( newrdnSpecToken != null )
+ {
+ LdifToken newrdnValueTypeToken = this.scanner.matchValueType();
+ LdifToken newrdnValueToken = this.scanner.matchValue();
+ LdifToken newrdnSepToken = null;
+ if ( newrdnValueTypeToken != null || newrdnValueToken != null )
+ {
+ newrdnSepToken = this.scanner.matchSep();
+ }
+
+ LdifNewrdnLine newrdnLine = new LdifNewrdnLine( newrdnSpecToken.getOffset(),
+ getValueOrNull( newrdnSpecToken ), getValueOrNull( newrdnValueTypeToken ),
+ getValueOrNull( newrdnValueToken ), getValueOrNull( newrdnSepToken ) );
+ record.setNewrdn( newrdnLine );
+
+ if ( newrdnSepToken == null )
+ {
+ this.cleanupLine( record );
+ }
+ }
+
+ if ( newrdnSpecToken == null )
+ {
+ if ( !checkAndParseComment( record ) && !checkAndParseOther( record ) )
+ {
+ return;
+ }
+ }
+
+ // comments
+ checkAndParseComment( record );
+
+ // read deleteoldrdnline
+ LdifToken deleteoldrdnSpecToken = this.scanner.matchDeleteoldrdnSpec();
+ if ( deleteoldrdnSpecToken != null )
+ {
+ LdifToken deleteoldrdnValueTypeToken = this.scanner.matchValueType();
+ LdifToken deleteoldrdnValueToken = this.scanner.matchValue();
+ LdifToken deleteoldrdnSepToken = null;
+ if ( deleteoldrdnValueTypeToken != null || deleteoldrdnValueToken != null )
+ {
+ deleteoldrdnSepToken = this.scanner.matchSep();
+ }
+
+ LdifDeloldrdnLine deloldrdnLine = new LdifDeloldrdnLine( deleteoldrdnSpecToken.getOffset(),
+ getValueOrNull( deleteoldrdnSpecToken ), getValueOrNull( deleteoldrdnValueTypeToken ),
+ getValueOrNull( deleteoldrdnValueToken ), getValueOrNull( deleteoldrdnSepToken ) );
+ record.setDeloldrdn( deloldrdnLine );
+
+ if ( deleteoldrdnSepToken == null )
+ {
+ this.cleanupLine( record );
+ }
+ }
+
+ if ( deleteoldrdnSpecToken == null )
+ {
+ if ( !checkAndParseComment( record ) && !checkAndParseOther( record ) )
+ {
+ return;
+ }
+ }
+
+ // comments
+ checkAndParseComment( record );
+
+ // read newsuperior line
+ LdifToken newsuperiorSpecToken = this.scanner.matchNewsuperiorSpec();
+ if ( newsuperiorSpecToken != null )
+ {
+ LdifToken newsuperiorValueTypeToken = this.scanner.matchValueType();
+ LdifToken newsuperiorValueToken = this.scanner.matchValue();
+ LdifToken newsuperiorSepToken = null;
+ if ( newsuperiorValueTypeToken != null || newsuperiorValueToken != null )
+ {
+ newsuperiorSepToken = this.scanner.matchSep();
+ }
+
+ LdifNewsuperiorLine newsuperiorLine = new LdifNewsuperiorLine( newsuperiorSpecToken.getOffset(),
+ getValueOrNull( newsuperiorSpecToken ), getValueOrNull( newsuperiorValueTypeToken ),
+ getValueOrNull( newsuperiorValueToken ), getValueOrNull( newsuperiorSepToken ) );
+ record.setNewsuperior( newsuperiorLine );
+
+ if ( newsuperiorSepToken == null )
+ {
+ this.cleanupLine( record );
+ }
+ }
+
+ // comments
+ checkAndParseComment( record );
+
+ // eor
+ checkAndParseEndOfRecord( record );
+
+ // comments
+ // checkAndParseComment(record);
+
+ // }
+ // while(true);
+ }
+
+
+ private void parseChangeModifyRecord( LdifChangeModifyRecord record )
+ {
+
+ do
+ {
+ if ( checkAndParseEndOfRecord( record ) )
+ {
+ return;
+ }
+
+ // match mod type
+ LdifToken modSpecTypeSpecToken = this.scanner.matchModTypeSpec();
+ if ( modSpecTypeSpecToken != null )
+ {
+ // read mod type line
+ LdifToken modSpecTypeValueTypeToken = null;
+ LdifToken modSpecTypeAttributeDescriptionToken = null;
+ LdifToken sepToken = null;
+ modSpecTypeValueTypeToken = this.scanner.matchValueType();
+ if ( modSpecTypeValueTypeToken != null )
+ {
+ modSpecTypeAttributeDescriptionToken = this.scanner.matchAttributeDescription();
+ if ( modSpecTypeAttributeDescriptionToken != null )
+ {
+ sepToken = this.scanner.matchSep();
+ }
+ }
+ LdifModSpecTypeLine modSpecTypeLine = new LdifModSpecTypeLine( modSpecTypeSpecToken.getOffset(),
+ getValueOrNull( modSpecTypeSpecToken ), getValueOrNull( modSpecTypeValueTypeToken ),
+ getValueOrNull( modSpecTypeAttributeDescriptionToken ), getValueOrNull( sepToken ) );
+ LdifModSpec modSpec = new LdifModSpec( modSpecTypeLine );
+ record.addModSpec( modSpec );
+
+ // clean line
+ if ( sepToken == null )
+ {
+ this.cleanupLine( modSpec );
+ }
+
+ // comment
+ checkAndParseComment( record );
+
+ // read attr-val lines
+ do
+ {
+ LdifAttrValLine line = this.getAttrValLine();
+ if ( line != null )
+ {
+ modSpec.addAttrVal( line );
+
+ // clean line
+ if ( "".equals( line.getRawNewLine() ) )
+ {
+ this.cleanupLine( record );
+ }
+ }
+ else
+ {
+ if ( !checkAndParseComment( record ) )
+ {
+ break;
+ }
+ }
+ }
+ while ( true );
+
+ // comments
+ checkAndParseComment( record );
+
+ // read sep line
+ LdifToken modSpecSepToken = this.scanner.matchModSep();
+ if ( modSpecSepToken != null )
+ {
+ LdifToken modSpecSepSepToken = this.scanner.matchSep();
+ LdifModSpecSepLine modSpecSepLine = new LdifModSpecSepLine( modSpecSepToken.getOffset(),
+ getValueOrNull( modSpecSepToken ), getValueOrNull( modSpecSepSepToken ) );
+ modSpec.finish( modSpecSepLine );
+ }
+ }
+
+ if ( modSpecTypeSpecToken == null )
+ {
+ if ( !checkAndParseComment( record ) && !checkAndParseOther( record ) )
+ {
+ return;
+ }
+ }
+ }
+ while ( true );
+ }
+
+
+ private void parseAttrValRecord( LdifRecord record )
+ {
+
+ do
+ {
+ if ( checkAndParseEndOfRecord( record ) )
+ {
+ return;
+ }
+
+ // check attr-val line
+ LdifAttrValLine line = this.getAttrValLine();
+ if ( line != null )
+ {
+ if ( record instanceof LdifContentRecord )
+ {
+ ( ( LdifContentRecord ) record ).addAttrVal( line );
+ }
+ else if ( record instanceof LdifChangeAddRecord )
+ {
+ ( ( LdifChangeAddRecord ) record ).addAttrVal( line );
+ }
+
+ // clean line
+ if ( "".equals( line.getRawNewLine() ) )
+ {
+ this.cleanupLine( record );
+ }
+ }
+ else
+ {
+ if ( !checkAndParseComment( record ) && !checkAndParseOther( record ) )
+ {
+ return;
+ }
+ }
+
+ //
+ // // check comment line
+ // if(lineStartToken == null) {
+ // lineStartToken = this.scanner.matchComment();
+ // if(lineStartToken != null) {
+ // LdifToken sepToken = this.scanner.matchSep();
+ // record.addComment(new
+ // LdifCommentLine(lineStartToken.getOffset(),
+ // getValueOrNull(lineStartToken), getValueOrNull(sepToken)));
+ // }
+ // }
+ //
+ // // unknown line
+ // if(lineStartToken == null) {
+ // lineStartToken = this.scanner.matchOther();
+ // if(lineStartToken != null) {
+ // record.addOther(new
+ // LdifInvalidPart(lineStartToken.getOffset(),
+ // lineStartToken.getValue()));
+ // }
+ // }
+
+ // // end of file
+ // if(lineStartToken == null) {
+ // return;
+ // }
+ }
+ while ( true );
+ }
+
+
+ private boolean checkAndParseEndOfRecord( LdifRecord record )
+ {
+ // check end of record
+ LdifToken eorSepToken = this.scanner.matchSep();
+ if ( eorSepToken != null )
+ {
+ record.finish( new LdifSepLine( eorSepToken.getOffset(), getValueOrNull( eorSepToken ) ) );
+ return true;
+ }
+
+ // check end of file
+ LdifToken eofToken = this.scanner.matchEOF();
+ if ( eofToken != null )
+ {
+ record.finish( new LdifEOFPart( eofToken.getOffset() ) );
+ return true;
+ }
+ return false;
+ }
+
+
+ private boolean checkAndParseComment( LdifRecord record )
+ {
+ LdifToken commentToken = this.scanner.matchComment();
+ if ( commentToken != null )
+ {
+ LdifToken sepToken = this.scanner.matchSep();
+ record.addComment( new LdifCommentLine( commentToken.getOffset(), getValueOrNull( commentToken ),
+ getValueOrNull( sepToken ) ) );
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ private boolean checkAndParseOther( LdifRecord record )
+ {
+ LdifToken otherToken = this.scanner.matchOther();
+ if ( otherToken != null )
+ {
+ record.addInvalid( new LdifInvalidPart( otherToken.getOffset(), otherToken.getValue() ) );
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ /**
+ * Checks for version line. If version line is present it is parsed and
+ * added to the given model.
+ *
+ * @param model
+ * the model
+ * @return true if version line was added to the model, false otherwise
+ */
+ private boolean checkAndParseVersion( LdifFile model )
+ {
+ LdifToken versionSpecToken = this.scanner.matchVersionSpec();
+ if ( versionSpecToken != null )
+ {
+
+ LdifToken versionTypeToken = null;
+ LdifToken versionToken = null;
+ LdifToken sepToken = null;
+ versionTypeToken = this.scanner.matchValueType();
+ if ( versionTypeToken != null )
+ {
+ versionToken = this.scanner.matchNumber();
+ if ( versionToken != null )
+ {
+ sepToken = this.scanner.matchSep();
+ }
+ }
+
+ LdifVersionContainer container = new LdifVersionContainer( new LdifVersionLine( versionSpecToken
+ .getOffset(), getValueOrNull( versionSpecToken ), getValueOrNull( versionTypeToken ),
+ getValueOrNull( versionToken ), getValueOrNull( sepToken ) ) );
+ model.addContainer( container );
+
+ // clean line
+ if ( sepToken == null )
+ {
+ this.cleanupLine( container );
+ }
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ /**
+ * Checks for comment lines or empty lines. If such lines are present
+ * they are parsed and added to the given model.
+ *
+ * @param model
+ * the model
+ * @return true if comment or empty lines were added to the model, false
+ * otherwise
+ */
+ private boolean checkAndParseComment( LdifFile model )
+ {
+ LdifToken sepToken = this.scanner.matchSep();
+ LdifToken commentToken = this.scanner.matchComment();
+
+ if ( sepToken != null || commentToken != null )
+ {
+
+ while ( sepToken != null || commentToken != null )
+ {
+
+ if ( sepToken != null )
+ {
+ LdifSepLine sepLine = new LdifSepLine( sepToken.getOffset(), getValueOrNull( sepToken ) );
+ LdifSepContainer sepContainer = new LdifSepContainer( sepLine );
+ model.addContainer( sepContainer );
+ }
+
+ if ( commentToken != null )
+ {
+ LdifCommentContainer commentContainer = null;
+ while ( commentToken != null )
+ {
+ LdifToken commentSepToken = this.scanner.matchSep();
+ LdifCommentLine commentLine = new LdifCommentLine( commentToken.getOffset(),
+ getValueOrNull( commentToken ), getValueOrNull( commentSepToken ) );
+
+ if ( commentContainer == null )
+ {
+ commentContainer = new LdifCommentContainer( commentLine );
+ }
+ else
+ {
+ commentContainer.addComment( commentLine );
+ }
+
+ commentToken = this.scanner.matchComment();
+ }
+ model.addContainer( commentContainer );
+ }
+
+ sepToken = this.scanner.matchSep();
+ commentToken = this.scanner.matchComment();
+ }
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ /**
+ * Checks for other line. If such line is present it is parsed and added
+ * to the given model.
+ *
+ * @param model
+ * the model
+ * @return always true except if EOF reached
+ */
+ private boolean checkAndParseOther( LdifFile model )
+ {
+ LdifToken token = this.scanner.matchOther();
+ if ( token != null )
+ {
+ LdifInvalidPart unknownLine = new LdifInvalidPart( token.getOffset(), getValueOrNull( token ) );
+ LdifInvalidContainer otherContainer = new LdifInvalidContainer( unknownLine );
+ model.addContainer( otherContainer );
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ private LdifControlLine getControlLine()
+ {
+
+ LdifToken controlSpecToken = this.scanner.matchControlSpec();
+ if ( controlSpecToken != null )
+ {
+ LdifToken controlTypeToken = null;
+ LdifToken oidToken = null;
+ LdifToken criticalityToken = null;
+ LdifToken valueTypeToken = null;
+ LdifToken valueToken = null;
+ LdifToken sepToken = null;
+ controlTypeToken = this.scanner.matchValueType();
+ if ( controlTypeToken != null )
+ {
+ oidToken = this.scanner.matchOid();
+ if ( oidToken != null )
+ {
+ criticalityToken = this.scanner.matchCriticality();
+ valueTypeToken = this.scanner.matchValueType();
+ if ( valueTypeToken != null )
+ {
+ valueToken = this.scanner.matchValue();
+ }
+ sepToken = this.scanner.matchSep();
+ }
+ }
+
+ LdifControlLine controlLine = new LdifControlLine( controlSpecToken.getOffset(),
+ getValueOrNull( controlSpecToken ), getValueOrNull( controlTypeToken ), getValueOrNull( oidToken ),
+ getValueOrNull( criticalityToken ), getValueOrNull( valueTypeToken ), getValueOrNull( valueToken ),
+ getValueOrNull( sepToken ) );
+
+ return controlLine;
+ }
+
+ return null;
+ }
+
+
+ private LdifChangeTypeLine getChangeTypeLine()
+ {
+
+ LdifToken changeTypeSpecToken = this.scanner.matchChangeTypeSpec();
+ if ( changeTypeSpecToken != null )
+ {
+ LdifToken changeTypeTypeToken = null;
+ LdifToken changeTypeToken = null;
+ LdifToken sepToken = null;
+ changeTypeTypeToken = this.scanner.matchValueType();
+ if ( changeTypeTypeToken != null )
+ {
+ changeTypeToken = this.scanner.matchChangeType();
+ if ( changeTypeToken != null )
+ {
+ sepToken = this.scanner.matchSep();
+ }
+ }
+
+ LdifChangeTypeLine ctLine = new LdifChangeTypeLine( changeTypeSpecToken.getOffset(),
+ getValueOrNull( changeTypeSpecToken ), getValueOrNull( changeTypeTypeToken ),
+ getValueOrNull( changeTypeToken ), getValueOrNull( sepToken ) );
+
+ return ctLine;
+ }
+
+ return null;
+ }
+
+
+ private LdifAttrValLine getAttrValLine()
+ {
+ LdifToken attrToken = this.scanner.matchAttributeDescription();
+ if ( attrToken != null )
+ {
+ LdifToken valueTypeToken = null;
+ LdifToken valueToken = null;
+ LdifToken sepToken = null;
+ valueTypeToken = this.scanner.matchValueType();
+ if ( valueTypeToken != null )
+ {
+ valueToken = this.scanner.matchValue();
+ if ( valueToken != null )
+ {
+ sepToken = this.scanner.matchSep();
+ }
+ }
+
+ LdifAttrValLine line = new LdifAttrValLine( attrToken.getOffset(), getValueOrNull( attrToken ),
+ getValueOrNull( valueTypeToken ), getValueOrNull( valueToken ), getValueOrNull( sepToken ) );
+
+ return line;
+ }
+
+ return null;
+ }
+
+
+ private LdifCommentLine[] getCommentLines()
+ {
+ List list = new ArrayList( 1 );
+ LdifToken commentToken = this.scanner.matchComment();
+ while ( commentToken != null )
+ {
+ LdifToken sepToken = this.scanner.matchSep();
+ list
+ .add( new LdifCommentLine( commentToken.getOffset(), commentToken.getValue(), getValueOrNull( sepToken ) ) );
+
+ commentToken = this.scanner.matchComment();
+ }
+ return ( LdifCommentLine[] ) list.toArray( new LdifCommentLine[list.size()] );
+ }
+
+
+ private void cleanupLine( LdifContainer container )
+ {
+ LdifToken errorToken = this.scanner.matchCleanupLine();
+ if ( errorToken != null )
+ {
+ container.addInvalid( new LdifInvalidPart( errorToken.getOffset(), errorToken.getValue() ) );
+ }
+ }
+
+
+ private LdifToken cleanupLine()
+ {
+ LdifToken errorToken = this.scanner.matchCleanupLine();
+ return errorToken;
+ }
+
+
+ private static String getValueOrNull( LdifToken token )
+ {
+ return token == null ? null : token.getValue();
+ }
+
+}