Examples of LdifModSpec


Examples of org.apache.directory.studio.ldifparser.model.container.LdifModSpec

                    }
                }
                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 )
            {
View Full Code Here

Examples of org.apache.directory.studio.ldifparser.model.container.LdifModSpec

    {
        if ( container == null || offset < container.getOffset()
            || offset > container.getOffset() + container.getLength() )
            return null;

        LdifModSpec innerContainer = null;
        LdifPart[] parts = container.getParts();
        if ( parts.length > 0 )
        {
            int partIndex = -1;
View Full Code Here

Examples of org.apache.directory.studio.ldifparser.model.container.LdifModSpec

                        {
                            LdifPart part = parts[p];

                            if ( part instanceof LdifModSpec )
                            {
                                LdifModSpec spec = ( LdifModSpec ) part;
                                partList.addAll( Arrays.asList( getParts( new LdifContainer[]
                                    { spec }, offset, length ) ) );
                            }
                            else
                            {
View Full Code Here

Examples of org.apache.directory.studio.ldifparser.model.container.LdifModSpec

            // check what to do
            if ( oldAttribute != null && newAttribute == null )
            {
                // attribute only exists in the old entry: delete all values
                LdifModSpec modSpec;
                if ( isReplaceForced )
                {
                    // replace (empty value list)
                    modSpec = LdifModSpec.createReplace( attributeDescription );
                }
                else
                // addDelForced or default
                {
                    // delete all
                    modSpec = LdifModSpec.createDelete( attributeDescription );
                }
                modSpec.finish( LdifModSpecSepLine.create() );
                record.addModSpec( modSpec );
            }
            else if ( oldAttribute == null && newAttribute != null )
            {
                // attribute only exists in the new entry: add all values
                LdifModSpec modSpec;
                if ( isReplaceForced )
                {
                    // replace (all values)
                    modSpec = LdifModSpec.createReplace( attributeDescription );
                }
                else
                // addDelForced or default
                {
                    // add (all new values)
                    modSpec = LdifModSpec.createAdd( attributeDescription );
                }
                for ( IValue value : newAttribute.getValues() )
                {
                    modSpec.addAttrVal( computeDiffCreateAttrValLine( value ) );
                }
                modSpec.finish( LdifModSpecSepLine.create() );
                record.addModSpec( modSpec );
            }
            else if ( oldAttribute != null && newAttribute != null && !oldValues.equals( newValues ) )
            {
                // attribute exists in both entries, check modifications
                if ( isReplaceForced )
                {
                    // replace (all new values)
                    LdifModSpec modSpec = LdifModSpec.createReplace( attributeDescription );
                    for ( IValue value : newAttribute.getValues() )
                    {
                        modSpec.addAttrVal( computeDiffCreateAttrValLine( value ) );
                    }
                    modSpec.finish( LdifModSpecSepLine.create() );
                    record.addModSpec( modSpec );
                }
                else
                {
                    // compute diff
                    List<LdifAttrValLine> toDel = new ArrayList<LdifAttrValLine>();
                    List<LdifAttrValLine> toAdd = new ArrayList<LdifAttrValLine>();

                    for ( Map.Entry<String, LdifAttrValLine> entry : oldAttrValLines.entrySet() )
                    {
                        if ( !newValues.contains( entry.getKey() ) )
                        {
                            toDel.add( entry.getValue() );
                        }
                    }
                    for ( Map.Entry<String, LdifAttrValLine> entry : newAttrValLines.entrySet() )
                    {
                        if ( !oldValues.contains( entry.getKey() ) )
                        {
                            toAdd.add( entry.getValue() );
                        }
                    }

                    /*
                     *  we use add/del in the following cases:
                     *  - add/del is forced in the connection configuration
                     *  - only values to add
                     *  - only values to delete
                     *  - the sum of adds and deletes is smaller or equal than the number of replaces
                     * 
                     *  we use replace in the following cases:
                     *  - the number of replaces is smaller to the sum of adds and deletes
                     *  - for attributes with X-ORDERED 'VALUES'
                     */
                    if ( isAddDelForced || ( toAdd.size() + toDel.size() <= newAttrValLines.size() && !isOrderedValue )
                        || ( !toDel.isEmpty() && toAdd.isEmpty() ) || ( !toAdd.isEmpty() && toDel.isEmpty() ) )
                    {
                        // add/del del/add
                        LdifModSpec addModSpec = LdifModSpec.createAdd( attributeDescription );
                        for ( LdifAttrValLine attrValLine : toAdd )
                        {
                            addModSpec.addAttrVal( attrValLine );
                        }
                        addModSpec.finish( LdifModSpecSepLine.create() );
                        LdifModSpec delModSpec = LdifModSpec.createDelete( attributeDescription );
                        for ( LdifAttrValLine attrValLine : toDel )
                        {
                            delModSpec.addAttrVal( attrValLine );
                        }
                        delModSpec.finish( LdifModSpecSepLine.create() );

                        if ( modifyAddDeleteOrder == ModifyOrder.DELETE_FIRST )
                        {
                            if ( delModSpec.getAttrVals().length > 0 )
                            {
                                record.addModSpec( delModSpec );
                            }
                            if ( addModSpec.getAttrVals().length > 0 )
                            {
                                record.addModSpec( addModSpec );
                            }
                        }
                        else
                        {
                            if ( addModSpec.getAttrVals().length > 0 )
                            {
                                record.addModSpec( addModSpec );
                            }
                            if ( delModSpec.getAttrVals().length > 0 )
                            {
                                record.addModSpec( delModSpec );
                            }
                        }
                    }
                    else
                    {
                        // replace (all new values)
                        LdifModSpec modSpec = LdifModSpec.createReplace( attributeDescription );
                        for ( LdifAttrValLine attrValLine : newAttrValLines.values() )
                        {
                            modSpec.addAttrVal( attrValLine );
                        }
                        modSpec.finish( LdifModSpecSepLine.create() );
                        record.addModSpec( modSpec );
                    }
                }
            }

View Full Code Here

Examples of org.apache.directory.studio.ldifparser.model.container.LdifModSpec

        }

        // modspecs
        if ( innerContainer instanceof LdifModSpec )
        {
            LdifModSpec modSpec = ( LdifModSpec ) innerContainer;
            String att = modSpec.getModSpecType().getRawAttributeDescription();
            if ( att != null && att.startsWith( prefix ) )
            {
                proposalList.add( new CompletionProposal( att, offset - prefix.length(), prefix.length(), att.length(),
                    null, null, null, null ) );
            }
View Full Code Here

Examples of org.apache.directory.studio.ldifparser.model.container.LdifModSpec


    public void update()
    {
        LdifContainer[] containers = getSelectedLdifContainers();
        LdifModSpec modSpec = getSelectedLdifModSpec();
        LdifPart[] parts = getSelectedLdifParts();

        super
            .setEnabled( parts.length == 1
                && ( parts[0] instanceof LdifAttrValLine || modSpec != null )
View Full Code Here

Examples of org.apache.directory.studio.ldifparser.model.container.LdifModSpec

    protected void doRun()
    {

        LdifContainer[] containers = getSelectedLdifContainers();
        LdifModSpec modSpec = getSelectedLdifModSpec();
        LdifPart[] parts = getSelectedLdifParts();
        if ( parts.length == 1
            && ( parts[0] instanceof LdifAttrValLine || parts[0] instanceof LdifModSpecTypeLine )
            && containers.length == 1
            && ( containers[0] instanceof LdifContentRecord || containers[0] instanceof LdifChangeAddRecord || containers[0] instanceof LdifChangeModifyRecord ) )
        {
            try
            {
                LdifValueLineBase line = ( LdifValueLineBase ) parts[0];
                String attributeDescription = null;
                String oldValue = null;
                if ( modSpec != null && line instanceof LdifModSpecTypeLine )
                {
                    LdifModSpecTypeLine oldLine = ( LdifModSpecTypeLine ) line;
                    attributeDescription = oldLine.getUnfoldedAttributeDescription();
                    oldValue = null;
                }
                else
                {
                    LdifAttrValLine oldLine = ( LdifAttrValLine ) line;
                    attributeDescription = oldLine.getUnfoldedAttributeDescription();
                    oldValue = oldLine.getValueAsString();
                }

                Schema schema = editor.getConnection() != null ? editor.getConnection().getSchema()
                    : Schema.DEFAULT_SCHEMA;
                IBrowserConnection dummyConnection = new DummyConnection( schema );

                IEntry dummyEntry = null;
                if ( containers[0] instanceof LdifContentRecord )
                {
                    dummyEntry = ModelConverter.ldifContentRecordToEntry( ( LdifContentRecord ) containers[0],
                        dummyConnection );
                }
                else if ( containers[0] instanceof LdifChangeAddRecord )
                {
                    dummyEntry = ModelConverter.ldifChangeAddRecordToEntry( ( LdifChangeAddRecord ) containers[0],
                        dummyConnection );
                }
                else if ( containers[0] instanceof LdifChangeModifyRecord )
                {
                    dummyEntry = new DummyEntry( new LdapDN(), dummyConnection );
                }

                AttributeWizard wizard = new AttributeWizard( Messages
                    .getString( "EditLdifAttributeAction.EditAttributeDescription" ), true, false, //$NON-NLS-1$
                    attributeDescription, dummyEntry );
                WizardDialog dialog = new WizardDialog( Display.getDefault().getActiveShell(), wizard );
                dialog.setBlockOnOpen( true );
                dialog.create();
                if ( dialog.open() == Dialog.OK )
                {
                    String newAttributeDescription = wizard.getAttributeDescription();

                    if ( newAttributeDescription != null )
                    {
                        IDocument document = editor.getDocumentProvider().getDocument( editor.getEditorInput() );

                        if ( modSpec != null )
                        {
                            LdifModSpecTypeLine oldTypeLine = modSpec.getModSpecType();
                            LdifModSpecTypeLine newTypeLine = null;
                            if ( oldTypeLine.isAdd() )
                            {
                                newTypeLine = LdifModSpecTypeLine.createAdd( newAttributeDescription );
                            }
                            else if ( oldTypeLine.isDelete() )
                            {
                                newTypeLine = LdifModSpecTypeLine.createDelete( newAttributeDescription );
                            }
                            else if ( oldTypeLine.isReplace() )
                            {
                                newTypeLine = LdifModSpecTypeLine.createReplace( newAttributeDescription );
                            }

                            LdifAttrValLine[] oldAttrValLines = modSpec.getAttrVals();
                            LdifAttrValLine[] newAttrValLines = new LdifAttrValLine[oldAttrValLines.length];
                            for ( int i = 0; i < oldAttrValLines.length; i++ )
                            {
                                LdifAttrValLine oldAttrValLine = oldAttrValLines[i];
                                newAttrValLines[i] = LdifAttrValLine.create( newAttributeDescription, oldAttrValLine
                                    .getValueAsString() );

                            }

                            LdifModSpecSepLine newSepLine = LdifModSpecSepLine.create();

                            String text = newTypeLine.toFormattedString( Utils.getLdifFormatParameters() );
                            for ( int j = 0; j < newAttrValLines.length; j++ )
                            {
                                text += newAttrValLines[j].toFormattedString( Utils.getLdifFormatParameters() );
                            }
                            text += newSepLine.toFormattedString( Utils.getLdifFormatParameters() );
                            try
                            {
                                document.replace( modSpec.getOffset(), modSpec.getLength(), text );
                            }
                            catch ( BadLocationException e )
                            {
                                e.printStackTrace();
                            }
View Full Code Here

Examples of org.apache.directory.studio.ldifparser.model.container.LdifModSpec

            {

                if ( container instanceof LdifChangeModifyRecord && innerContainer instanceof LdifModSpec
                    && ( part instanceof LdifAttrValLine || part instanceof LdifModSpecTypeLine ) )
                {
                    LdifModSpec modSpec = ( LdifModSpec ) innerContainer;
                    String att = modSpec.getModSpecType().getUnfoldedAttributeDescription();
                    c.text += att + ": "; //$NON-NLS-1$
                }
            }
        }
View Full Code Here

Examples of org.apache.directory.studio.ldifparser.model.container.LdifModSpec

                        ldifEditor.selectAndReveal( line.getOffset() + line.getRawAttributeDescription().length()
                            + line.getRawValueType().length(), line.getRawValue().length() );
                    }
                    else if ( element instanceof LdifModSpec )
                    {
                        LdifModSpec modSpec = ( LdifModSpec ) element;
                        ldifEditor.selectAndReveal( modSpec.getOffset(), modSpec.getModSpecType().getLength() );
                    }
                }
            }
        } );
View Full Code Here

Examples of org.apache.directory.studio.ldifparser.model.container.LdifModSpec

                        // line.getLength(), DEFAULT_TEXT_ATTRIBUTE);
                    }
                }
                else if ( parts[i] instanceof LdifModSpec )
                {
                    LdifModSpec modSpec = ( LdifModSpec ) parts[i];
                    this.highlight( new LdifContainer[]
                        { modSpec }, presentation, damage );

                }
                else if ( parts[i] instanceof LdifInvalidPart )
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.