001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2006-2008 Sun Microsystems, Inc. 025 * Portions Copyright 2012-2015 ForgeRock AS 026 * 027 */ 028package org.opends.server.schema; 029 030import static org.opends.server.schema.SchemaConstants.*; 031 032import java.util.List; 033 034import org.forgerock.i18n.LocalizableMessage; 035import org.forgerock.opendj.config.server.ConfigChangeResult; 036import org.forgerock.opendj.config.server.ConfigException; 037import org.forgerock.opendj.ldap.schema.Schema; 038import org.forgerock.opendj.ldap.schema.SchemaOptions; 039import org.forgerock.opendj.ldap.schema.Syntax; 040import org.forgerock.util.Option; 041import org.opends.server.admin.server.ConfigurationChangeListener; 042import org.opends.server.admin.std.server.JPEGAttributeSyntaxCfg; 043import org.opends.server.api.AttributeSyntax; 044import org.opends.server.core.ServerContext; 045 046/** 047 * This class implements the JPEG attribute syntax. This is actually 048 * two specifications - JPEG and JFIF. As an extension we allow JPEG 049 * and Exif, which is what most digital cameras use. We only check for 050 * valid JFIF and Exif headers. 051 */ 052public class JPEGSyntax 053 extends AttributeSyntax<JPEGAttributeSyntaxCfg> 054 implements ConfigurationChangeListener<JPEGAttributeSyntaxCfg> 055{ 056 057 /** The current configuration for this JPEG syntax. */ 058 private volatile JPEGAttributeSyntaxCfg config; 059 060 private ServerContext serverContext; 061 062 /** 063 * Creates a new instance of this syntax. Note that the only thing that 064 * should be done here is to invoke the default constructor for the 065 * superclass. All initialization should be performed in the 066 * <CODE>initializeSyntax</CODE> method. 067 */ 068 public JPEGSyntax() 069 { 070 super(); 071 } 072 073 /** {@inheritDoc} */ 074 @Override 075 public void initializeSyntax(JPEGAttributeSyntaxCfg configuration, ServerContext serverContext) 076 throws ConfigException 077 { 078 this.config = configuration; 079 this.serverContext = serverContext; 080 updateNewSchema(); 081 config.addJPEGChangeListener(this); 082 } 083 084 /** Update the option in new schema if it changes from current value. */ 085 private void updateNewSchema() 086 { 087 Option<Boolean> option = SchemaOptions.ALLOW_MALFORMED_JPEG_PHOTOS; 088 if (config.isStrictFormat() == serverContext.getSchemaNG().getOption(option)) 089 { 090 SchemaUpdater schemaUpdater = serverContext.getSchemaUpdater(); 091 schemaUpdater.updateSchema( 092 schemaUpdater.getSchemaBuilder().setOption(option, !config.isStrictFormat()).toSchema()); 093 } 094 } 095 096 /** {@inheritDoc} */ 097 @Override 098 public Syntax getSDKSyntax(Schema schema) 099 { 100 return schema.getSyntax(SchemaConstants.SYNTAX_JPEG_OID); 101 } 102 103 /** 104 * Retrieves the common name for this attribute syntax. 105 * 106 * @return The common name for this attribute syntax. 107 */ 108 @Override 109 public String getName() 110 { 111 return SYNTAX_JPEG_NAME; 112 } 113 114 /** 115 * Retrieves the OID for this attribute syntax. 116 * 117 * @return The OID for this attribute syntax. 118 */ 119 @Override 120 public String getOID() 121 { 122 return SYNTAX_JPEG_OID; 123 } 124 125 /** 126 * Retrieves a description for this attribute syntax. 127 * 128 * @return A description for this attribute syntax. 129 */ 130 @Override 131 public String getDescription() 132 { 133 return SYNTAX_JPEG_DESCRIPTION; 134 } 135 136 /** {@inheritDoc} */ 137 @Override 138 public boolean isConfigurationChangeAcceptable( 139 JPEGAttributeSyntaxCfg configuration, 140 List<LocalizableMessage> unacceptableReasons) 141 { 142 // The configuration will always be acceptable. 143 return true; 144 } 145 146 /** {@inheritDoc} */ 147 @Override 148 public ConfigChangeResult applyConfigurationChange( 149 JPEGAttributeSyntaxCfg configuration) 150 { 151 this.config = configuration; 152 updateNewSchema(); 153 return new ConfigChangeResult(); 154 } 155} 156