CPD Results

The following document contains the results of PMD's CPD 4.3.

Duplications

File Line
org/deegree/protocol/wfs/query/xml/QueryXMLAdapter.java 212
org/deegree/protocol/wfs/query/xml/QueryXMLAdapter.java 305
    private Query parseAdHocQuery200( OMElement queryEl )
                            throws OWSException {

        // <xsd:attribute name="handle" type="xsd:string"/>
        String handle = getNodeAsString( queryEl, new XPath( "@handle", nsContext ), null );

        // <xsd:attribute name="aliases" type="fes:AliasesType"/>
        String[] aliases = null;
        String aliasesStr = getNodeAsString( queryEl, new XPath( "@aliases", nsContext ), null );
        if ( aliasesStr != null ) {
            aliases = StringUtils.split( aliasesStr, " " );
        }

        // <xsd:attribute name="typeNames" type="fes:TypeNamesListType" use="required"/>
        String typeNameStr = getRequiredNodeAsString( queryEl, new XPath( "@typeNames", nsContext ) );
        String[] tokens = StringUtils.split( typeNameStr, " " );
        if ( aliases != null && aliases.length != tokens.length ) {
            String msg = "Number of entries in 'aliases' and 'typeNames' attributes does not match.";
            throw new OWSException( msg, INVALID_PARAMETER_VALUE, "aliases" );
        }
        TypeName[] typeNames = new TypeName[tokens.length];
        for ( int i = 0; i < tokens.length; i++ ) {
            String alias = aliases != null ? aliases[i] : null;
            String token = tokens[i];
            if ( token.startsWith( "schema-element(" ) && token.endsWith( ")" ) ) {
                String prefixedName = token.substring( 15, token.length() - 1 );
                QName qName = resolveQName( queryEl, prefixedName );
                typeNames[i] = new TypeName( qName, alias, true );
            } else {
                QName qName = resolveQName( queryEl, token );
                typeNames[i] = new TypeName( qName, alias, false );
            }
        }

        // <xsd:attribute name="srsName" type="xsd:anyURI"/>
        ICRS crs = null;
        String srsName = getNodeAsString( queryEl, new XPath( "@srsName", nsContext ), null );
        if ( srsName != null ) {
            crs = CRSManager.getCRSRef( srsName );
        }

        // <xsd:attribute name="featureVersion" type="xsd:string"/>
        String featureVersion = getNodeAsString( queryEl, new XPath( "@featureVersion", nsContext ), null );

        // <xsd:element ref="fes:AbstractProjectionClause" minOccurs="0" maxOccurs="unbounded"/>
        List<OMElement> propertyNameEls = getElements( queryEl, new XPath( "wfs200:PropertyName", nsContext ) );
File Line
org/deegree/protocol/wfs/query/xml/QueryXMLAdapter.java 261
org/deegree/protocol/wfs/query/xml/QueryXMLAdapter.java 360
            projectionClauses.add( propName );
        }

        // <xsd:element ref="fes:AbstractSelectionClause" minOccurs="0"/>
        Filter filter = null;
        OMElement filterEl = queryEl.getFirstChildWithName( new QName( FES_20_NS, "Filter" ) );
        if ( filterEl != null ) {
            filter = parseFilter200( filterEl );
        }

        // <xsd:element ref="fes:AbstractSortingClause" minOccurs="0"/>
        List<SortProperty> sortProps = new ArrayList<SortProperty>();
        // <xsd:element name="SortBy" type="fes:SortByType" substitutionGroup="fes:AbstractSortingClause"/>
        OMElement sortByEl = getElement( queryEl, new XPath( "fes:SortBy", nsContext ) );
        if ( sortByEl != null ) {
            List<OMElement> sortPropertyEls = getRequiredElements( sortByEl, new XPath( "fes:SortProperty", nsContext ) );
            for ( OMElement sortPropertyEl : sortPropertyEls ) {
                OMElement propNameEl = getRequiredElement( sortPropertyEl, new XPath( "fes:ValueReference", nsContext ) );
                ValueReference valRef = new ValueReference( propNameEl.getText(), getNamespaceContext( propNameEl ) );
                String sortOrder = getNodeAsString( sortPropertyEl, new XPath( "fes:SortOrder", nsContext ), "ASC" );
                SortProperty sortProp = new SortProperty( valRef, sortOrder.equals( "ASC" ) );
                sortProps.add( sortProp );
            }
        }
File Line
org/deegree/protocol/wfs/getfeature/kvp/GetFeatureKVPAdapter.java 195
org/deegree/protocol/wfs/getfeature/kvp/GetFeatureKVPAdapter.java 354
                    queries.add( new FeatureIdQuery( null, typeName, featureVersion, srs, projectionClauses, null, fids ) );
                }
            }
        } else if ( bboxStr != null ) {
            if ( typeNames == null ) {
                // TODO make new exception
                throw new Exception( "The TYPENAME keyword is mandatory if BBOX is present!" );
            }

            String[] coordList = bboxStr.split( "," );
            ICRS bboxCrs = null;
            if ( coordList.length % 2 == 1 ) {
                bboxCrs = CRSManager.getCRSRef( coordList[coordList.length - 1] );
            }

            Envelope bbox = createEnvelope( bboxStr, bboxCrs );
            for ( int i = 0; i < typeNames.length; i++ ) {
                TypeName typeName = typeNames[i];
                PropertyName[] projectionClauses = null;
                if ( propertyNames != null ) {
                    projectionClauses = propertyNames[i];
                }
                queries.add( new BBoxQuery( null, new TypeName[] { typeName }, featureVersion, srs, projectionClauses,
File Line
org/deegree/protocol/wfs/transaction/xml/TransactionXmlReader100.java 112
org/deegree/protocol/wfs/transaction/xml/TransactionXmlReader110.java 117
            throw new XMLParsingException( xmlStream, msg );
        }

        TransactionAction operation = null;
        String localName = xmlStream.getLocalName();
        if ( "Delete".equals( localName ) ) {
            operation = readDelete( xmlStream );
        } else if ( "Insert".equals( localName ) ) {
            operation = readInsert( xmlStream );
        } else if ( "Native".equals( localName ) ) {
            operation = readNative( xmlStream );
        } else if ( "Update".equals( localName ) ) {
            operation = readUpdate( xmlStream );
        } else {
            throw new XMLParsingException( xmlStream, "Unexpected operation element " + localName + "." );
        }
        return operation;
    }

    /**
     * Returns the object representation of a <code>wfs:Delete</code> element. Consumes all corresponding events from
     * the given <code>XMLStream</code>.
     * 
     * @param xmlStream
     *            cursor must point at the <code>START_ELEMENT</code> event (&lt;wfs:Delete&gt;), points at the
     *            corresponding <code>END_ELEMENT</code> event (&lt;/wfs:Delete&gt;) afterwards
     * @return corresponding {@link Delete} object
     * @throws XMLStreamException
     * @throws XMLParsingException
     */
    Delete readDelete( XMLStreamReader xmlStream )
                            throws XMLStreamException {

        // optional: '@handle'
        String handle = xmlStream.getAttributeValue( null, "handle" );

        // required: '@typeName'
        QName ftName = getRequiredAttributeValueAsQName( xmlStream, null, "typeName" );
File Line
org/deegree/protocol/wfs/describefeaturetype/xml/DescribeFeatureTypeXMLAdapter.java 124
org/deegree/protocol/wfs/describefeaturetype/xml/DescribeFeatureTypeXMLAdapter.java 171
        String outputFormat = rootElement.getAttributeValue( new QName( "outputFormat" ) );

        // 'wfs:TypeName' elements (minOccurs=0, maxOccurs=unbounded)
        QName[] typeNames = getNodesAsQNames( rootElement, new XPath( "wfs:TypeName", nsContext ) );
        String[] typeNames2 = getNodesAsStrings( rootElement, new XPath( "wfs:TypeName", nsContext ) );
        // TODO remove null namespace hack
        for ( int i = 0; i < typeNames.length; i++ ) {
            if ( typeNames[i] == null ) {
                typeNames[i] = mangleTypeName( typeNames2[i] );
            } else if ( WFSConstants.WFS_NS.equals( typeNames[i].getNamespaceURI() ) ) {
                typeNames[i] = new QName( typeNames[i].getLocalPart() );
            }
        }

        return new DescribeFeatureType( VERSION_100, null, outputFormat, typeNames, null );
File Line
org/deegree/protocol/wfs/capabilities/WFS100CapabilitiesAdapter.java 108
org/deegree/protocol/wfs/capabilities/WFS110CapabilitiesAdapter.java 33
    }

    @Override
    public List<WFSFeatureType> parseFeatureTypeList() {
        List<OMElement> ftEls = getElements( rootElement, new XPath( "wfs:FeatureTypeList/wfs:FeatureType", nsContext ) );
        List<WFSFeatureType> fts = new ArrayList<WFSFeatureType>( ftEls.size() );
        for ( OMElement ftEl : ftEls ) {
            fts.add( parseFeatureType( ftEl ) );
        }
        return fts;
    }

    private WFSFeatureType parseFeatureType( OMElement ftEl ) {

        // <xsd:element name="Name" type="xsd:QName"/>
        OMElement nameEl = getRequiredElement( ftEl, new XPath( "wfs:Name", nsContext ) );
        String prefixedName = nameEl.getText().trim();
        QName ftName = parseQName( prefixedName, nameEl );

        // <xsd:element ref="wfs:Title" minOccurs="0"/>
        List<LanguageString> titles = Collections.emptyList();
        String title = getNodeAsString( ftEl, new XPath( "wfs:Title", nsContext ), null );
File Line
org/deegree/protocol/wfs/transaction/xml/TransactionXmlReader100.java 228
org/deegree/protocol/wfs/transaction/xml/TransactionXmlReader110.java 276
    public PropertyReplacement readProperty( XMLStreamReader xmlStream )
                            throws XMLStreamException {
        xmlStream.require( START_ELEMENT, WFS_NS, "Property" );
        xmlStream.nextTag();
        xmlStream.require( START_ELEMENT, WFS_NS, "Name" );
        QName propName = getElementTextAsQName( xmlStream );
        xmlStream.nextTag();

        PropertyReplacement replacement = null;
        if ( new QName( WFS_NS, "Value" ).equals( xmlStream.getName() ) ) {
            replacement = new PropertyReplacement( new ValueReference( propName ), xmlStream, null );
        } else {
            xmlStream.require( END_ELEMENT, WFS_NS, "Property" );
            replacement = new PropertyReplacement( new ValueReference( propName ), null, null );
            xmlStream.nextTag();
        }
        return replacement;
    }
}
File Line
org/deegree/protocol/wfs/getfeature/xml/GetFeatureXMLAdapter.java 145
org/deegree/protocol/wfs/getfeature/xml/GetFeatureXMLAdapter.java 217
        StandardPresentationParams presentationParams = parseStandardPresentationParameters100( rootElement );

        List<OMElement> queryElements = getRequiredElements( rootElement, new XPath( "*", nsContext ) );
        // check if all child elements are 'wfs:Query' elements (required for CITE)
        for ( OMElement omElement : queryElements ) {
            if ( !new QName( WFSConstants.WFS_NS, "Query" ).equals( omElement.getQName() ) ) {
                String msg = "Child element '" + omElement.getQName() + "' is not allowed.";
                throw new XMLParsingException( this, omElement, msg );
            }
        }

        List<Query> queries = new ArrayList<Query>();

        for ( OMElement queryEl : queryElements ) {
            List<PropertyName> propNames = new ArrayList<PropertyName>();
            List<OMElement> propertyNameElements = getElements( queryEl, new XPath( "ogc:PropertyName", nsContext ) );
File Line
org/deegree/protocol/wfs/getfeature/kvp/GetFeatureKVPAdapter.java 218
org/deegree/protocol/wfs/getfeature/kvp/GetFeatureKVPAdapter.java 382
                                            null, bbox ) );
            }
        } else if ( filterStr != null || typeNames != null ) {
            if ( typeNames == null ) {
                // TODO make new exception
                throw new Exception( "The FILTER element requires the TYPENAME element" );
            }

            int length = typeNames.length;

            String[] filters = getFilters( filterStr );

            for ( int i = 0; i < length; i++ ) {
                Filter filter = null;
                if ( filters != null ) {

                    StringReader sr = new StringReader( filters[i] );
                    XMLAdapter adapter = new XMLAdapter( sr );
                    XMLStreamReaderWrapper streamWrapper = new XMLStreamReaderWrapper(
                                                                                       adapter.getRootElement().getXMLStreamReaderWithoutCaching(),
                                                                                       adapter.getSystemId() );
                    try {
                        streamWrapper.nextTag();
                        filter = Filter100XMLDecoder.parse( streamWrapper );
File Line
org/deegree/protocol/wfs/lockfeature/xml/LockFeatureXMLAdapter.java 127
org/deegree/protocol/wfs/lockfeature/xml/LockFeatureXMLAdapter.java 177
    public LockFeature parse100() {

        String handle = getNodeAsString( rootElement, new XPath( "@handle", nsContext ), null );
        BigInteger expiryInMinutes = getNodeAsBigInt( rootElement, new XPath( "@expiry", nsContext ), null );
        BigInteger expiryInSeconds = convertToSeconds( expiryInMinutes );

        String lockActionStr = rootElement.getAttributeValue( new QName( "lockAction" ) );
        Boolean lockAll = parseLockAction( lockActionStr );

        List<OMElement> lockElements = getRequiredElements( rootElement, new XPath( "wfs:Lock", nsContext ) );
        List<Query> queries = new ArrayList<Query>( lockElements.size() );
        for ( OMElement lockElement : lockElements ) {
            queries.add( parseLock100( lockElement ) );
File Line
org/deegree/protocol/wfs/transaction/xml/TransactionXmlReader100.java 80
org/deegree/protocol/wfs/transaction/xml/TransactionXmlReader110.java 84
class TransactionXmlReader100 extends AbstractTransactionXmlReader {

    @Override
    public Transaction read( XMLStreamReader xmlStream )
                            throws XMLStreamException {
        xmlStream.require( START_ELEMENT, WFS_NS, "Transaction" );

        // optional: '@handle'
        String handle = getAttributeValue( xmlStream, "handle" );

        // optional: '@releaseAction'
        String releaseActionString = getAttributeValue( xmlStream, "releaseAction" );
        ReleaseAction releaseAction = parseReleaseAction( releaseActionString );

        // optional: 'wfs:LockId'
        String lockId = null;
        requireNextTag( xmlStream, START_ELEMENT );
        if ( xmlStream.getName().equals( new QName( WFS_NS, "LockId" ) ) ) {
            lockId = xmlStream.getElementText().trim();
            requireNextTag( xmlStream, START_ELEMENT );
        }

        LazyTransactionActionsReader iterable = new LazyTransactionActionsReader( xmlStream, this );
        return new Transaction( VERSION_100, handle, lockId, releaseAction, iterable, null );
File Line
org/deegree/protocol/wfs/getfeature/kvp/GetFeatureKVPAdapter.java 392
org/deegree/protocol/wfs/lockfeature/kvp/LockFeatureKVPAdapter.java 201
            String[] filters = getFilters( filterStr );

            for ( int i = 0; i < length; i++ ) {
                Filter filter = null;
                if ( filters != null ) {

                    StringReader sr = new StringReader( filters[i] );
                    XMLAdapter adapter = new XMLAdapter( sr );
                    XMLStreamReaderWrapper streamWrapper = new XMLStreamReaderWrapper(
                                                                                       adapter.getRootElement().getXMLStreamReaderWithoutCaching(),
                                                                                       adapter.getSystemId() );
                    try {
                        streamWrapper.nextTag();
                        filter = Filter110XMLDecoder.parse( streamWrapper );
                    } catch ( XMLParsingException e ) {
                        e.printStackTrace();
                        // TODO raise exception
                    } catch ( XMLStreamException e ) {
                        e.printStackTrace();
                        // TODO raise exception
                    }
                }
File Line
org/deegree/protocol/wfs/getfeaturewithlock/kvp/GetFeatureWithLockKVPAdapter.java 149
org/deegree/protocol/wfs/lockfeature/kvp/LockFeatureKVPAdapter.java 250
                                       lockAll );
    }

    private static BigInteger convertToSeconds( BigInteger expiryInMinutes ) {
        if ( expiryInMinutes == null ) {
            return null;
        }
        return expiryInMinutes.multiply( BigInteger.valueOf( 60 ) );
    }

    private static Boolean parseLockAction( String lockActionString ) {
        Boolean lockAll = null;
        if ( lockActionString != null ) {
            if ( "SOME".equals( lockActionString ) ) {
                lockAll = false;
            } else if ( "ALL".equals( lockActionString ) ) {
                lockAll = true;
            } else {
                String msg = "Invalid value (=" + lockActionString
                             + ") for lock action parameter. Valid values are 'ALL' or 'SOME'.";
                throw new InvalidParameterValueException( msg, "lockAction" );
            }
        }
        return lockAll;
    }
}
File Line
org/deegree/protocol/wfs/query/kvp/QueryKVPAdapter.java 392
org/deegree/protocol/wfs/query/kvp/QueryKVPAdapter.java 413
org/deegree/protocol/wfs/query/kvp/QueryKVPAdapter.java 437
                TypeName[] typeNames = new TypeName[0];
                if ( !typeNamesList.isEmpty() ) {
                    typeNames = typeNamesList.get( i );
                }
                ICRS srsName = null;
                if ( !srsNames.isEmpty() ) {
                    srsName = srsNames.get( i );
                }
                PropertyName[] projectionClauses = null;
                if ( !projectionClausesList.isEmpty() ) {
                    projectionClauses = projectionClausesList.get( i );
                }
                SortProperty[] sortBy = null;
                if ( !sortByList.isEmpty() ) {
                    sortBy = sortByList.get( i );
                }
                queries.add( new FeatureIdQuery( null, typeNames, null, srsName, projectionClauses, sortBy, resourceIds ) );