List of usage examples for org.dom4j Attribute getValue
String getValue();
From source file:org.alfresco.web.config.forms.FormElementReader.java
License:Open Source License
@SuppressWarnings("unchecked") private void parseFieldTags(Element formElement, FormConfigElement result) { // xpath expressions. for (Object fieldObj : formElement.selectNodes("./appearance/field")) { Element fieldElem = (Element) fieldObj; List<Attribute> fieldAttributes = fieldElem.selectNodes("./@*"); List<String> fieldAttributeNames = new ArrayList<String>(); List<String> fieldAttributeValues = new ArrayList<String>(); // With special handling for the mandatory "id" attribute. String fieldIdValue = null; for (Attribute nextAttr : fieldAttributes) { String nextAttributeName = nextAttr.getName(); String nextAttributeValue = nextAttr.getValue(); if (nextAttributeName.equals(ATTR_NAME_ID)) { fieldIdValue = nextAttributeValue; } else { fieldAttributeNames.add(nextAttributeName); fieldAttributeValues.add(nextAttributeValue); }/*from w w w . j a v a2s.co m*/ } if (fieldIdValue == null) { throw new ConfigException("<field> node missing mandatory id attribute."); } result.addField(fieldIdValue, fieldAttributeNames, fieldAttributeValues); List<Element> controlObjs = fieldElem.selectNodes("./control"); if (!controlObjs.isEmpty()) { // We are assuming that there is only one <control> child element Element controlElem = controlObjs.get(0); String templateValue = controlElem.attributeValue(ATTR_TEMPLATE); List<String> controlParamNames = new ArrayList<String>(); List<String> controlParamValues = new ArrayList<String>(); for (Object paramObj : controlElem.selectNodes("./control-param")) { Element paramElem = (Element) paramObj; controlParamNames.add(paramElem.attributeValue(ATTR_NAME)); controlParamValues.add(paramElem.getTextTrim()); } result.addControlForField(fieldIdValue, templateValue, controlParamNames, controlParamValues); } // Delegate the reading of the <constraint-handlers> tag(s) to the reader. ConstraintHandlersElementReader constraintHandlersElementReader = new ConstraintHandlersElementReader(); for (Object constraintHandlerObj : fieldElem.selectNodes("./constraint-handlers")) { // There need only be one <constraint-handlers> element, but there is nothing // to prevent the use of multiple such elements. Element constraintHandlers = (Element) constraintHandlerObj; ConfigElement confElem = constraintHandlersElementReader.parse(constraintHandlers); ConstraintHandlersConfigElement constraintHandlerCE = (ConstraintHandlersConfigElement) confElem; // This ConstraintHandlersConfigElement contains the config data for all // <constraint> elements under the current <constraint-handlers> element. Map<String, ConstraintHandlerDefinition> constraintItems = constraintHandlerCE.getItems(); for (String key : constraintItems.keySet()) { ConstraintHandlerDefinition defn = constraintItems.get(key); result.addConstraintForField(fieldIdValue, defn.getType(), defn.getMessage(), defn.getMessageId(), defn.getValidationHandler(), defn.getEvent()); } } } }
From source file:org.alfresco.web.config.header.HeaderItemsElementReader.java
License:Open Source License
@SuppressWarnings("unchecked") private void parseItemTags(Element itemsElement, HeaderItemsConfigElement result) { HeaderItem lastItem;// ww w . ja va 2s . c om // xpath expressions. for (Object itemObj : itemsElement.selectNodes("./item")) { Element itemElem = (Element) itemObj; String itemText = itemElem.getTextTrim(); List<Attribute> itemAttributes = itemElem.selectNodes("./@*"); List<String> itemAttributeNames = new ArrayList<String>(); List<String> itemAttributeValues = new ArrayList<String>(); // Special handling for the mandatory "id" and optional condition & permission attributes String itemGeneratedId = null; String itemGroupCondition = this.group_condition; String itemGroupPermission = this.group_permission; for (Attribute nextAttr : itemAttributes) { String nextAttributeName = nextAttr.getName(); String nextAttributeValue = nextAttr.getValue(); // If the item specifies a condition or permission, it's overriding an optional group default if (nextAttributeName.equals(ATTR_CONDITION)) { itemGroupCondition = null; } else if (nextAttributeName.equals(ATTR_PERMISSION)) { itemGroupPermission = null; } else if (nextAttributeName.equals(ATTR_ID)) { itemGeneratedId = this.generateUniqueItemId(nextAttributeValue); } itemAttributeNames.add(nextAttributeName); itemAttributeValues.add(nextAttributeValue); } if (itemGeneratedId == null) { throw new ConfigException("<item> node missing mandatory id attribute."); } // If the group condition was set and not overridden, add it to the item here if (itemGroupCondition != null) { itemAttributeNames.add(ATTR_CONDITION); itemAttributeValues.add(itemGroupCondition); } // If the group permission was set and not overridden, add it to the item here if (itemGroupPermission != null) { itemAttributeNames.add(ATTR_PERMISSION); itemAttributeValues.add(itemGroupPermission); } lastItem = result.addItem(itemGeneratedId, itemAttributeNames, itemAttributeValues, itemText); // Go through ant of the <container-group> tags under <item> for (Object obj : itemElem.selectNodes("./container-group")) { Element containerElement = (Element) obj; HeaderItemsElementReader containerReader = new HeaderItemsElementReader(lastItem.getId()); HeaderItemsConfigElement containerCE = (HeaderItemsConfigElement) containerReader .parse(containerElement); lastItem.addContainedItem(containerCE.getId(), containerCE); } } }
From source file:org.apache.directory.studio.connection.core.io.ConnectionIO.java
License:Apache License
/** * Reads a connection from the given Element. * * @param element the element/* w ww. j a va2 s . c om*/ * @return the corresponding connection * @throws ConnectionIOException if an error occurs when converting values */ private static ConnectionParameter readConnection(Element element) throws ConnectionIOException { ConnectionParameter connection = new ConnectionParameter(); // ID Attribute idAttribute = element.attribute(ID_TAG); if (idAttribute != null) { connection.setId(idAttribute.getValue()); } // Name Attribute nameAttribute = element.attribute(NAME_TAG); if (nameAttribute != null) { connection.setName(nameAttribute.getValue()); } // Host Attribute hostAttribute = element.attribute(HOST_TAG); if (hostAttribute != null) { connection.setHost(hostAttribute.getValue()); } // Port Attribute portAttribute = element.attribute(PORT_TAG); if (portAttribute != null) { try { connection.setPort(Integer.parseInt(portAttribute.getValue())); } catch (NumberFormatException e) { throw new ConnectionIOException("Unable to parse 'Port' of connection '" + connection.getName() //$NON-NLS-1$ + "' as int value. Port value :" + portAttribute.getValue()); //$NON-NLS-1$ } } // Timeout Attribute timeoutAttribute = element.attribute(TIMEOUT_TAG); if (timeoutAttribute != null) { try { connection.setTimeout(Long.parseLong(timeoutAttribute.getValue())); } catch (NumberFormatException e) { throw new ConnectionIOException("Unable to parse 'Timeout' of connection '" + connection.getName() //$NON-NLS-1$ + "' as int value. Timeout value :" + timeoutAttribute.getValue()); //$NON-NLS-1$ } } // Encryption Method Attribute encryptionMethodAttribute = element.attribute(ENCRYPTION_METHOD_TAG); if (encryptionMethodAttribute != null) { try { connection.setEncryptionMethod(EncryptionMethod.valueOf(encryptionMethodAttribute.getValue())); } catch (IllegalArgumentException e) { throw new ConnectionIOException("Unable to parse 'Encryption Method' of connection '" //$NON-NLS-1$ + connection.getName() + "' as int value. Encryption Method value :" //$NON-NLS-1$ + encryptionMethodAttribute.getValue()); } } // Network Provider Attribute networkProviderAttribute = element.attribute(NETWORK_PROVIDER_TAG); if (networkProviderAttribute != null) { try { connection.setNetworkProvider(NetworkProvider.valueOf(networkProviderAttribute.getValue())); } catch (IllegalArgumentException e) { throw new ConnectionIOException("Unable to parse 'Network Provider' of connection '" //$NON-NLS-1$ + connection.getName() + "' as int value. Network Provider value :" //$NON-NLS-1$ + networkProviderAttribute.getValue()); } } else { connection.setNetworkProvider(ConnectionCorePlugin.getDefault().getDefaultNetworkProvider()); } // Auth Method Attribute authMethodAttribute = element.attribute(AUTH_METHOD_TAG); if (authMethodAttribute != null) { try { connection.setAuthMethod(AuthenticationMethod.valueOf(authMethodAttribute.getValue())); } catch (IllegalArgumentException e) { throw new ConnectionIOException("Unable to parse 'Authentication Method' of connection '" //$NON-NLS-1$ + connection.getName() + "' as int value. Authentication Method value :" //$NON-NLS-1$ + authMethodAttribute.getValue()); } } // Bind Principal Attribute bindPrincipalAttribute = element.attribute(BIND_PRINCIPAL_TAG); if (bindPrincipalAttribute != null) { connection.setBindPrincipal(bindPrincipalAttribute.getValue()); } // Bind Password Attribute bindPasswordAttribute = element.attribute(BIND_PASSWORD_TAG); if (bindPasswordAttribute != null) { connection.setBindPassword(bindPasswordAttribute.getValue()); } // SASL Realm Attribute saslRealmAttribute = element.attribute(SASL_REALM_TAG); if (saslRealmAttribute != null) { connection.setSaslRealm(saslRealmAttribute.getValue()); } // SASL Quality of Protection Attribute saslQopAttribute = element.attribute(SASL_QOP_TAG); if (saslQopAttribute != null) { if ("AUTH_INT_PRIV".equals(saslQopAttribute.getValue())) //$NON-NLS-1$ { // Used for legacy setting (before we used SaslQop enum from Shared) connection.setSaslQop(SaslQoP.AUTH_CONF); } else { try { connection.setSaslQop(SaslQoP.valueOf(saslQopAttribute.getValue())); } catch (IllegalArgumentException e) { throw new ConnectionIOException("Unable to parse 'SASL Quality of Protection' of connection '" //$NON-NLS-1$ + connection.getName() + "' as int value. SASL Quality of Protection value :" //$NON-NLS-1$ + saslQopAttribute.getValue()); } } } // SASL Security Strength Attribute saslSecStrengthAttribute = element.attribute(SASL_SEC_STRENGTH_TAG); if (saslSecStrengthAttribute != null) { try { connection .setSaslSecurityStrength(SaslSecurityStrength.valueOf(saslSecStrengthAttribute.getValue())); } catch (IllegalArgumentException e) { throw new ConnectionIOException("Unable to parse 'SASL Security Strength' of connection '" //$NON-NLS-1$ + connection.getName() + "' as int value. SASL Security Strength value :" //$NON-NLS-1$ + saslSecStrengthAttribute.getValue()); } } // SASL Mutual Authentication Attribute saslMutualAuthAttribute = element.attribute(SASL_MUTUAL_AUTH_TAG); if (saslMutualAuthAttribute != null) { connection.setSaslMutualAuthentication(Boolean.parseBoolean(saslMutualAuthAttribute.getValue())); } // KRB5 Credentials Conf Attribute krb5CredentialsConf = element.attribute(KRB5_CREDENTIALS_CONF_TAG); if (krb5CredentialsConf != null) { try { connection.setKrb5CredentialConfiguration( Krb5CredentialConfiguration.valueOf(krb5CredentialsConf.getValue())); } catch (IllegalArgumentException e) { throw new ConnectionIOException("Unable to parse 'KRB5 Credentials Conf' of connection '" //$NON-NLS-1$ + connection.getName() + "' as int value. KRB5 Credentials Conf value :" //$NON-NLS-1$ + krb5CredentialsConf.getValue()); } } // KRB5 Configuration Attribute krb5Config = element.attribute(KRB5_CONFIG_TAG); if (krb5Config != null) { try { connection.setKrb5Configuration(Krb5Configuration.valueOf(krb5Config.getValue())); } catch (IllegalArgumentException e) { throw new ConnectionIOException("Unable to parse 'KRB5 Configuration' of connection '" //$NON-NLS-1$ + connection.getName() + "' as int value. KRB5 Configuration value :" //$NON-NLS-1$ + krb5Config.getValue()); } } // KRB5 Configuration File Attribute krb5ConfigFile = element.attribute(KRB5_CONFIG_FILE_TAG); if (krb5ConfigFile != null) { connection.setKrb5ConfigurationFile(krb5ConfigFile.getValue()); } // KRB5 REALM Attribute krb5Realm = element.attribute(KRB5_REALM_TAG); if (krb5Realm != null) { connection.setKrb5Realm(krb5Realm.getValue()); } // KRB5 KDC Host Attribute krb5KdcHost = element.attribute(KRB5_KDC_HOST_TAG); if (krb5KdcHost != null) { connection.setKrb5KdcHost(krb5KdcHost.getValue()); } // KRB5 KDC Port Attribute krb5KdcPort = element.attribute(KRB5_KDC_PORT_TAG); if (krb5KdcPort != null) { try { connection.setKrb5KdcPort(Integer.valueOf(krb5KdcPort.getValue())); } catch (NumberFormatException e) { throw new ConnectionIOException( "Unable to parse 'KRB5 KDC Port' of connection '" + connection.getName() //$NON-NLS-1$ + "' as int value. KRB5 KDC Port value :" + krb5KdcPort.getValue()); //$NON-NLS-1$ } } // Read Only Attribute readOnly = element.attribute(READ_ONLY_TAG); if (readOnly != null) { connection.setReadOnly(Boolean.parseBoolean(readOnly.getValue())); } // Extended Properties Element extendedPropertiesElement = element.element(EXTENDED_PROPERTIES_TAG); if (extendedPropertiesElement != null) { for (Object elementObject : extendedPropertiesElement.elements(EXTENDED_PROPERTY_TAG)) { Element extendedPropertyElement = (Element) elementObject; Attribute keyAttribute = extendedPropertyElement.attribute(KEY_TAG); Attribute valueAttribute = extendedPropertyElement.attribute(VALUE_TAG); if (keyAttribute != null && valueAttribute != null) { connection.setExtendedProperty(keyAttribute.getValue(), valueAttribute.getValue()); } } } return connection; }
From source file:org.apache.directory.studio.connection.core.io.ConnectionIO.java
License:Apache License
/** * Reads a connection folder from the given Element. * * @param element the element//from w w w .j a v a 2 s.c o m * @return the corresponding connection folder */ private static ConnectionFolder readConnectionFolder(Element element) { ConnectionFolder connectionFolder = new ConnectionFolder(); // ID Attribute idAttribute = element.attribute(ID_TAG); if (idAttribute != null) { connectionFolder.setId(idAttribute.getValue()); } // Name Attribute nameAttribute = element.attribute(NAME_TAG); if (nameAttribute != null) { connectionFolder.setName(nameAttribute.getValue()); } // Connections Element connectionsElement = element.element(CONNECTIONS_TAG); if (connectionsElement != null) { for (Iterator<?> i = connectionsElement.elementIterator(CONNECTION_TAG); i.hasNext();) { Element connectionElement = (Element) i.next(); Attribute connectionIdAttribute = connectionElement.attribute(ID_TAG); if (connectionIdAttribute != null) { connectionFolder.addConnectionId(connectionIdAttribute.getValue()); } } } // Sub-folders Element foldersElement = element.element(SUB_FOLDERS_TAG); if (foldersElement != null) { for (Iterator<?> i = foldersElement.elementIterator(SUB_FOLDER_TAG); i.hasNext();) { Element folderElement = (Element) i.next(); Attribute folderIdAttribute = folderElement.attribute(ID_TAG); if (folderIdAttribute != null) { connectionFolder.addSubFolderId(folderIdAttribute.getValue()); } } } return connectionFolder; }
From source file:org.apache.directory.studio.ldapbrowser.core.BrowserConnectionIO.java
License:Apache License
/** * Reads a browser connection from the given Element. * * @param element/* w w w .jav a2s . c o m*/ * the element * @param browserConnectionMap * the map of browser connections * * @throws ConnectionIOException * if an error occurs when converting values */ private static void readBrowserConnection(Element element, Map<String, IBrowserConnection> browserConnectionMap) throws ConnectionIOException { // ID Attribute idAttribute = element.attribute(ID_TAG); if (idAttribute != null) { String id = idAttribute.getValue(); IBrowserConnection browserConnection = browserConnectionMap.get(id); if (browserConnection != null) { Element searchesElement = element.element(SEARCHES_TAG); if (searchesElement != null) { for (Iterator<?> i = searchesElement.elementIterator(SEARCH_PARAMETER_TAG); i.hasNext();) { Element searchParameterElement = (Element) i.next(); SearchParameter searchParameter = readSearch(searchParameterElement, browserConnection); ISearch search = new Search(browserConnection, searchParameter); browserConnection.getSearchManager().addSearch(search); } } Element bookmarksElement = element.element(BOOKMARKS_TAG); if (bookmarksElement != null) { for (Iterator<?> i = bookmarksElement.elementIterator(BOOKMARK_PARAMETER_TAG); i.hasNext();) { Element bookmarkParameterElement = (Element) i.next(); BookmarkParameter bookmarkParameter = readBookmark(bookmarkParameterElement, browserConnection); IBookmark bookmark = new Bookmark(browserConnection, bookmarkParameter); browserConnection.getBookmarkManager().addBookmark(bookmark); } } } } }
From source file:org.apache.directory.studio.ldapbrowser.core.BrowserConnectionIO.java
License:Apache License
private static SearchParameter readSearch(Element searchParameterElement, IBrowserConnection browserConnection) throws ConnectionIOException { SearchParameter searchParameter = new SearchParameter(); // Name//ww w . j ava2s . c o m Attribute nameAttribute = searchParameterElement.attribute(NAME_TAG); if (nameAttribute != null) { searchParameter.setName(nameAttribute.getValue()); } // Search base Attribute searchBaseAttribute = searchParameterElement.attribute(SEARCH_BASE_TAG); if (searchBaseAttribute != null) { try { searchParameter.setSearchBase(new Dn(searchBaseAttribute.getValue())); } catch (LdapInvalidDnException e) { throw new ConnectionIOException( NLS.bind(BrowserCoreMessages.BrowserConnectionIO_UnableToParseSearchBase, new String[] { searchParameter.getName(), searchBaseAttribute.getValue() })); } } // Filter Attribute filterAttribute = searchParameterElement.attribute(FILTER_TAG); if (filterAttribute != null) { searchParameter.setFilter(filterAttribute.getValue()); } // Returning Attributes Element returningAttributesElement = searchParameterElement.element(RETURNING_ATTRIBUTES_TAG); if (returningAttributesElement != null) { List<String> returningAttributes = new ArrayList<String>(); for (Iterator<?> i = returningAttributesElement.elementIterator(RETURNING_ATTRIBUTE_TAG); i .hasNext();) { Element returningAttributeElement = (Element) i.next(); Attribute valueAttribute = returningAttributeElement.attribute(VALUE_TAG); if (valueAttribute != null) { returningAttributes.add(valueAttribute.getValue()); } } searchParameter .setReturningAttributes(returningAttributes.toArray(new String[returningAttributes.size()])); } // Scope Attribute scopeAttribute = searchParameterElement.attribute(SCOPE_TAG); if (scopeAttribute != null) { try { searchParameter.setScope(convertSearchScope(scopeAttribute.getValue())); } catch (IllegalArgumentException e) { throw new ConnectionIOException(NLS.bind(BrowserCoreMessages.BrowserConnectionIO_UnableToParseScope, new String[] { searchParameter.getName(), scopeAttribute.getValue() })); } } // Time limit Attribute timeLimitAttribute = searchParameterElement.attribute(TIME_LIMIT_TAG); if (timeLimitAttribute != null) { try { searchParameter.setTimeLimit(Integer.parseInt(timeLimitAttribute.getValue())); } catch (NumberFormatException e) { throw new ConnectionIOException( NLS.bind(BrowserCoreMessages.BrowserConnectionIO_UnableToParseTimeLimit, new String[] { searchParameter.getName(), timeLimitAttribute.getValue() })); } } // Count limit Attribute countLimitAttribute = searchParameterElement.attribute(COUNT_LIMIT_TAG); if (countLimitAttribute != null) { try { searchParameter.setCountLimit(Integer.parseInt(countLimitAttribute.getValue())); } catch (NumberFormatException e) { throw new ConnectionIOException( NLS.bind(BrowserCoreMessages.BrowserConnectionIO_UnableToParseCountLimit, new String[] { searchParameter.getName(), countLimitAttribute.getValue() })); } } // Alias dereferencing method Attribute aliasesDereferencingMethodAttribute = searchParameterElement .attribute(ALIASES_DEREFERENCING_METHOD_TAG); if (aliasesDereferencingMethodAttribute != null) { try { searchParameter.setAliasesDereferencingMethod(Connection.AliasDereferencingMethod .valueOf(aliasesDereferencingMethodAttribute.getValue())); } catch (IllegalArgumentException e) { throw new ConnectionIOException( NLS.bind(BrowserCoreMessages.BrowserConnectionIO_UnableToParseAliasesDereferencingMethod, new String[] { searchParameter.getName(), aliasesDereferencingMethodAttribute.getValue() })); } } // Referrals handling method Attribute referralsHandlingMethodAttribute = searchParameterElement .attribute(REFERRALS_HANDLING_METHOD_TAG); if (referralsHandlingMethodAttribute != null) { try { searchParameter.setReferralsHandlingMethod( Connection.ReferralHandlingMethod.valueOf(referralsHandlingMethodAttribute.getValue())); } catch (IllegalArgumentException e) { throw new ConnectionIOException(NLS.bind( BrowserCoreMessages.BrowserConnectionIO_UnableToParseReferralsHandlingMethod, new String[] { searchParameter.getName(), referralsHandlingMethodAttribute.getValue() })); } } // Controls Element controlsElement = searchParameterElement.element(CONTROLS_TAG); if (controlsElement != null) { for (Iterator<?> i = controlsElement.elementIterator(CONTROL_TAG); i.hasNext();) { Element controlElement = (Element) i.next(); Attribute valueAttribute = controlElement.attribute(VALUE_TAG); if (valueAttribute != null) { byte[] bytes = Base64.decode(valueAttribute.getValue().toCharArray()); ByteArrayInputStream bais = null; ObjectInputStream ois = null; try { bais = new ByteArrayInputStream(bytes); ois = new ObjectInputStream(bais); StudioControl control = (StudioControl) ois.readObject(); searchParameter.getControls().add(control); ois.close(); } catch (Exception e) { throw new ConnectionIOException( NLS.bind(BrowserCoreMessages.BrowserConnectionIO_UnableToParseControl, new String[] { searchParameter.getName(), valueAttribute.getValue() })); } } } } return searchParameter; }
From source file:org.apache.directory.studio.ldapbrowser.core.BrowserConnectionIO.java
License:Apache License
private static BookmarkParameter readBookmark(Element bookmarkParameterElement, IBrowserConnection browserConnection) throws ConnectionIOException { BookmarkParameter bookmarkParameter = new BookmarkParameter(); // Name/*from ww w .j a v a2s . co m*/ Attribute nameAttribute = bookmarkParameterElement.attribute(NAME_TAG); if (nameAttribute != null) { bookmarkParameter.setName(nameAttribute.getValue()); } // Dn Attribute dnAttribute = bookmarkParameterElement.attribute(DN_TAG); if (dnAttribute != null) { try { bookmarkParameter.setDn(new Dn(dnAttribute.getValue())); } catch (LdapInvalidDnException e) { throw new ConnectionIOException(NLS.bind(BrowserCoreMessages.BrowserConnectionIO_UnableToParseDn, new String[] { bookmarkParameter.getName(), dnAttribute.getValue() })); } } return bookmarkParameter; }
From source file:org.apache.directory.studio.ldapservers.LdapServersManagerIO.java
License:Apache License
/** * Reads an LDAP Server element.//from w ww. j a v a 2 s . co m * * @param element * the element * @return * the corresponding {@link LdapServer} */ private static LdapServer readLdapServer(Element element) { LdapServer server = new LdapServer(); // ID Attribute idAttribute = element.attribute(ID_ATTRIBUTE); if (idAttribute != null) { server.setId(idAttribute.getValue()); } // Name Attribute nameAttribute = element.attribute(NAME_ATTRIBUTE); if (nameAttribute != null) { server.setName(nameAttribute.getValue()); } // Adapter ID Attribute adapterIdAttribute = element.attribute(ADAPTER_ID_ATTRIBUTE); if (adapterIdAttribute != null) { // Getting the id String adapterId = adapterIdAttribute.getValue(); // Looking for the correct LDAP Server Adapter Extension object LdapServerAdapterExtension ldapServerAdapterExtension = LdapServerAdapterExtensionsManager.getDefault() .getLdapServerAdapterExtensionById(adapterId); if (ldapServerAdapterExtension != null) { // The Adapter Extension has been found // Assigning it to the server server.setLdapServerAdapterExtension(ldapServerAdapterExtension); } else { // The Adapter Extension has not been found // Creating an "unknown" Adapter Extension UnknownLdapServerAdapterExtension unknownLdapServerAdapterExtension = new UnknownLdapServerAdapterExtension(); // Adapter Id unknownLdapServerAdapterExtension.setId(adapterId); // Adapter Name Attribute adapterNameAttribute = element.attribute(ADAPTER_NAME_ATTRIBUTE); if (adapterNameAttribute != null) { unknownLdapServerAdapterExtension.setName(adapterNameAttribute.getValue()); } // Adapter Vendor Attribute adapterVendorAttribute = element.attribute(ADAPTER_VENDOR_ATTRIBUTE); if (adapterVendorAttribute != null) { unknownLdapServerAdapterExtension.setVendor(adapterVendorAttribute.getValue()); } // Adapter Version Attribute adapterVersionAttribute = element.attribute(ADAPTER_VERSION_ATTRIBUTE); if (adapterVersionAttribute != null) { unknownLdapServerAdapterExtension.setVersion(adapterVersionAttribute.getValue()); } // Assigning the "unknown" Adapter Extension to the server server.setLdapServerAdapterExtension(unknownLdapServerAdapterExtension); } } else { // TODO No Adapter ID, throw an error ? } // Configuration Parameters Element configurationParametersElement = element.element(CONFIGURATION_PARAMETERS_TAG); if (configurationParametersElement != null) { for (Iterator<?> i = configurationParametersElement.elementIterator(ENTRY_TAG); i.hasNext();) { readConfigurationParameter(server, (Element) i.next()); } } return server; }
From source file:org.apache.directory.studio.ldapservers.LdapServersManagerIO.java
License:Apache License
/** * Reads a configuration parameter./*from w w w . j a va2 s .c o m*/ * * @param server the server * @param element the element */ private static void readConfigurationParameter(LdapServer server, Element element) { // Key Attribute keyAttribute = element.attribute(KEY_ATTRIBUTE); String key = null; if (keyAttribute != null) { key = keyAttribute.getValue(); // Value Attribute valueAttribute = element.attribute(VALUE_ATTRIBUTE); String value = null; if (valueAttribute != null) { value = valueAttribute.getValue(); } // Type Attribute typeAttribute = element.attribute(TYPE_ATTRIBUTE); String type = null; if (typeAttribute != null) { type = typeAttribute.getValue(); } // Integer value if ((type != null) && (type.equalsIgnoreCase(Integer.class.getCanonicalName()))) { server.putConfigurationParameter(key, Integer.parseInt(value)); } // Boolean value else if ((type != null) && (type.equalsIgnoreCase(Boolean.class.getCanonicalName()))) { server.putConfigurationParameter(key, Boolean.parseBoolean(value)); } // String value (default type) else { server.putConfigurationParameter(key, value); } } }
From source file:org.apache.directory.studio.schemaeditor.model.io.ProjectsImporter.java
License:Apache License
/** * Reads a project./*from w w w . j a v a2 s . co m*/ * * @param element * the element * @param project * the project * @param path * the path * @throws ProjectsImportException * if an error occurs when importing the project */ private static void readProject(Element element, Project project, String path) throws ProjectsImportException { // Name Attribute nameAttribute = element.attribute(NAME_TAG); if ((nameAttribute != null) && (!nameAttribute.getValue().equals(""))) //$NON-NLS-1$ { project.setName(nameAttribute.getValue()); } // Type Attribute typeAttribute = element.attribute(TYPE_TAG); if ((typeAttribute != null) && (!typeAttribute.getValue().equals(""))) //$NON-NLS-1$ { try { project.setType(ProjectType.valueOf(typeAttribute.getValue())); } catch (IllegalArgumentException e) { throw new ProjectsImportException(Messages.getString("ProjectsImporter.NotConvertableValue")); //$NON-NLS-1$ } } // If project is an Online Schema Project if (project.getType().equals(ProjectType.ONLINE)) { // Connection Attribute connectionAttribute = element.attribute(CONNECTION_TAG); if ((connectionAttribute != null) && (!connectionAttribute.getValue().equals(""))) //$NON-NLS-1$ { project.setConnection(PluginUtils.getConnection(connectionAttribute.getValue())); } // Schema Connector Attribute schemaConnectorAttribute = element.attribute(SCHEMA_CONNECTOR_TAG); if ((schemaConnectorAttribute != null) && (!schemaConnectorAttribute.getValue().equals(""))) //$NON-NLS-1$ { String schemaConnectorId = schemaConnectorAttribute.getValue(); SchemaConnector schemaConnector = null; List<SchemaConnector> schemaConnectors = PluginUtils.getSchemaConnectors(); for (SchemaConnector sc : schemaConnectors) { if (sc.getId().equalsIgnoreCase(schemaConnectorId)) { schemaConnector = sc; } } if (schemaConnector == null) { throw new ProjectsImportException( NLS.bind(Messages.getString("ProjectsImporter.NoSchemaConnectorIDFound"), new String[] //$NON-NLS-1$ { schemaConnectorId })); //$NON-NLS-1$ } project.setSchemaConnector(schemaConnector); } // SchemaBackup Element schemaBackupElement = element.element(SCHEMA_BACKUP_TAG); if (schemaBackupElement != null) { Element schemasElement = schemaBackupElement.element(SCHEMAS_TAG); if (schemasElement != null) { Schema[] schemas = null; try { schemas = XMLSchemaFileImporter.readSchemas(schemasElement, path); for (Schema schema : schemas) { schema.setProject(project); } } catch (XMLSchemaFileImportException e) { throw new ProjectsImportException( Messages.getString("ProjectsImporter.NotConvertableSchema")); //$NON-NLS-1$ } project.setInitialSchema(Arrays.asList(schemas)); } } } // Schemas Element schemasElement = element.element(SCHEMAS_TAG); if (schemasElement != null) { Schema[] schemas = null; try { schemas = XMLSchemaFileImporter.readSchemas(schemasElement, path); } catch (XMLSchemaFileImportException e) { throw new ProjectsImportException(Messages.getString("ProjectsImporter.NotConvertableSchema")); //$NON-NLS-1$ } for (Schema schema : schemas) { schema.setProject(project); project.getSchemaHandler().addSchema(schema); } } }