001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.ldap.codec.api; 021 022import org.apache.directory.api.ldap.model.schema.AttributeType; 023import org.apache.directory.api.ldap.model.schema.LdapSyntax; 024import org.apache.directory.api.ldap.model.schema.SchemaManager; 025import org.apache.directory.api.util.Strings; 026 027/** 028 * An implementation of the BinaryAttributeDetector interface. It's not 029 * schema aware, so it only uses the list of binary Attributes. 030 * 031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 032 */ 033public class SchemaBinaryAttributeDetector implements BinaryAttributeDetector 034{ 035 /** The schemaManager to use */ 036 private SchemaManager schemaManager; 037 038 039 protected SchemaBinaryAttributeDetector() 040 { 041 } 042 043 044 public SchemaBinaryAttributeDetector( SchemaManager schemaManager ) 045 { 046 this.schemaManager = schemaManager; 047 } 048 049 /** 050 * @param schemaManager the schemaManager to set 051 */ 052 public void setSchemaManager( SchemaManager schemaManager ) 053 { 054 this.schemaManager = schemaManager; 055 } 056 057 058 /** 059 * {@inheritDoc} 060 */ 061 public boolean isBinary( String attributeId ) 062 { 063 String attrId = Strings.toLowerCase( attributeId ); 064 065 if ( attrId.endsWith( ";binary" ) ) 066 { 067 return true; 068 } 069 070 if ( schemaManager != null ) 071 { 072 AttributeType attributeType = schemaManager.getAttributeType( attrId ); 073 074 if ( attributeType == null ) 075 { 076 return false; 077 } 078 079 LdapSyntax ldapSyntax = attributeType.getSyntax(); 080 081 return ( ( ldapSyntax != null ) && !ldapSyntax.isHumanReadable() ); 082 } 083 084 return false; 085 } 086}