| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.guitools.controlpanel.task; |
| | |
| | | import org.opends.server.util.LDIFReader; |
| | | import org.opends.server.util.LDIFWriter; |
| | | import org.opends.server.util.ServerConstants; |
| | | import org.opends.server.util.StaticUtils; |
| | | |
| | | /** |
| | | * An abstract class used to re-factor some code between the different tasks |
| | |
| | | msg = INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_ADD_OBJECTCLASS_ONLINE.get( |
| | | element.getNameOrOID()); |
| | | } |
| | | sb.append(msg+"<br><b>"); |
| | | sb.append(msg).append("<br><b>"); |
| | | sb.append(equiv); |
| | | sb.append("<br>"); |
| | | sb.append("dn: cn=schema<br>"); |
| | | sb.append("changetype: modify<br>"); |
| | | sb.append("add: "+getAttributeName(element)+"<br>"); |
| | | sb.append(getAttributeName(element)+": "+getValueOnline(element)); |
| | | sb.append("add: ").append(getAttributeName(element)).append("<br>"); |
| | | sb.append(getAttributeName(element)).append(": ") |
| | | .append(getValueOnline(element)); |
| | | sb.append("</b><br><br>"); |
| | | getProgressDialog().appendProgressHtml(Utilities.applyFont(sb.toString(), |
| | | ColorAndFontConstants.progressFont)); |
| | |
| | | final List<AttributeType> attributes, |
| | | final List<ObjectClass> objectClasses) throws OpenDsException |
| | | { |
| | | final boolean userSchema; |
| | | final String fileName; |
| | | if (file == null) |
| | | { |
| | | file = ConfigConstants.FILE_USER_SCHEMA_ELEMENTS; |
| | | userSchema = true; |
| | | } |
| | | else |
| | | { |
| | | userSchema = false; |
| | | } |
| | | File f = new File(file); |
| | | if (!f.isAbsolute()) |
| | | { |
| | | f = new File( |
| | | DirectoryServer.getEnvironmentConfig().getSchemaDirectory(userSchema), |
| | | DirectoryServer.getEnvironmentConfig().getSchemaDirectory(), |
| | | file); |
| | | } |
| | | fileName = f.getAbsolutePath(); |
| | | final String fileName = f.getAbsolutePath(); |
| | | final boolean isSchemaFileDefined = isSchemaFileDefined(fileName); |
| | | SwingUtilities.invokeLater(new Runnable() |
| | | { |
| | |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append( |
| | | INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_ADD_SCHEMA_ELEMENT_OFFLINE.get( |
| | | Utils.getStringFromCollection(names, ", "), |
| | | schemaFile)+"<br><b>"); |
| | | Utils.getStringFromCollection(names, ", "), |
| | | schemaFile)) |
| | | .append("<br><b>"); |
| | | for (AttributeType attribute : attributes) |
| | | { |
| | | sb.append( |
| | | getAttributeName(attribute)+": "+getValueOffline(attribute)+"<br>"); |
| | | sb.append(getAttributeName(attribute)).append(": ") |
| | | .append(getValueOffline(attribute)).append("<br>"); |
| | | } |
| | | for (ObjectClass oc : objectClasses) |
| | | { |
| | | sb.append(getAttributeName(oc)+": "+getValueOffline(oc)+"<br>"); |
| | | sb.append(getAttributeName(oc)).append(": ") |
| | | .append(getValueOffline(oc)).append("<br>"); |
| | | } |
| | | sb.append("</b><br><br>"); |
| | | |
| | |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append(INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_ADD_SCHEMA_ENTRY_OFFLINE.get( |
| | | Utils.getStringFromCollection(names, ", "), |
| | | schemaFile)+"<br><b>"); |
| | | schemaFile)).append("<br><b>"); |
| | | for (String line : getSchemaEntryLines()) |
| | | { |
| | | sb.append(line); |
| | |
| | | } |
| | | for (AttributeType attribute : attributes) |
| | | { |
| | | sb.append( |
| | | getAttributeName(attribute)+": "+getValueOffline(attribute)+"<br>"); |
| | | sb.append(getAttributeName(attribute)).append(": ") |
| | | .append(getValueOffline(attribute)).append("<br>"); |
| | | } |
| | | for (ObjectClass oc : objectClasses) |
| | | { |
| | | sb.append(getAttributeName(oc)+": "+getValueOffline(oc)+"<br>"); |
| | | sb.append(getAttributeName(oc)).append(": ") |
| | | .append(getValueOffline(oc)).append("<br>"); |
| | | } |
| | | sb.append("</b><br><br>"); |
| | | getProgressDialog().appendProgressHtml(Utilities.applyFont(sb.toString(), |
| | |
| | | |
| | | /** |
| | | * Returns whether the file defined in the schema element exists or not. |
| | | * @param the path to the schema file. |
| | | * @param schemaFile the path to the schema file. |
| | | * @return <CODE>true</CODE> if the schema file is defined and |
| | | * <CODE>false</CODE> otherwise. |
| | | */ |
| | |
| | | } |
| | | finally |
| | | { |
| | | if (reader != null) |
| | | { |
| | | try |
| | | { |
| | | reader.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | StaticUtils.close(reader); |
| | | } |
| | | |
| | | return schemaDefined; |
| | | } |
| | | |
| | |
| | | new LDIFExportConfig(schemaFile, |
| | | ExistingFileBehavior.OVERWRITE); |
| | | LDIFReader reader = null; |
| | | Entry schemaEntry = null; |
| | | LDIFWriter writer = null; |
| | | try |
| | | { |
| | | reader = new LDIFReader(new LDIFImportConfig(schemaFile)); |
| | | schemaEntry = reader.readEntry(); |
| | | Entry schemaEntry = reader.readEntry(); |
| | | |
| | | for (AttributeType attribute : attributes) |
| | | { |
| | |
| | | getValueOffline(oc))); |
| | | schemaEntry.applyModification(mod); |
| | | } |
| | | LDIFWriter writer = new LDIFWriter(exportConfig); |
| | | writer = new LDIFWriter(exportConfig); |
| | | writer.writeEntry(schemaEntry); |
| | | exportConfig.getWriter().newLine(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | throw new OfflineUpdateException( |
| | | ERR_CTRL_PANEL_ERROR_UPDATING_SCHEMA.get(t.toString()), t); |
| | | } |
| | | finally |
| | | { |
| | | if (reader != null) |
| | | { |
| | | try |
| | | { |
| | | reader.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | if (exportConfig != null) |
| | | { |
| | | try |
| | | { |
| | | exportConfig.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | StaticUtils.close(reader, exportConfig, writer); |
| | | } |
| | | } |
| | | else |
| | |
| | | } |
| | | finally |
| | | { |
| | | if (exportConfig != null) |
| | | { |
| | | try |
| | | { |
| | | exportConfig.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | StaticUtils.close(exportConfig); |
| | | } |
| | | } |
| | | } |