List of usage examples for org.w3c.dom Element getAttributeNS
public String getAttributeNS(String namespaceURI, String localName) throws DOMException;
From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.dataConnector.StoredIDDataConnectorBeanDefinitionParser.java
/** {@inheritDoc} */ protected void doParse(String pluginId, Element pluginConfig, Map<QName, List<Element>> pluginConfigChildren, BeanDefinitionBuilder pluginBuilder, ParserContext parserContext) { super.doParse(pluginId, pluginConfig, pluginConfigChildren, pluginBuilder, parserContext); processConnectionManagement(pluginId, pluginConfig, pluginConfigChildren, pluginBuilder, parserContext); long queryTimeout = 5 * 1000; if (pluginConfig.hasAttributeNS(null, "queryTimeout")) { queryTimeout = SpringConfigurationUtils.parseDurationToMillis( "queryTimeout on relational database connector " + pluginId, pluginConfig.getAttributeNS(null, "queryTimeout"), 0); }/*w w w .j a v a2 s . c om*/ log.debug("Data connector {} SQL query timeout: {}ms", queryTimeout); pluginBuilder.addPropertyValue("queryTimeout", queryTimeout); String generatedAttributeId = "storedId"; if (pluginConfig.hasAttributeNS(null, "generatedAttributeID")) { generatedAttributeId = DatatypeHelper .safeTrimOrNullString(pluginConfig.getAttributeNS(null, "generatedAttributeID")); } pluginBuilder.addPropertyValue("generatedAttribute", generatedAttributeId); log.debug("Data connector {} generated attribute ID: {}", pluginId, generatedAttributeId); String sourceAttribute = DatatypeHelper .safeTrimOrNullString(pluginConfig.getAttributeNS(null, "sourceAttributeID")); log.debug("Data connector {} source attribute ID: {}", pluginId, sourceAttribute); pluginBuilder.addPropertyValue("sourceAttribute", sourceAttribute); String salt = DatatypeHelper.safeTrimOrNullString(pluginConfig.getAttributeNS(null, "salt")); log.debug("Data connector {} salt: {}", pluginId, salt); pluginBuilder.addPropertyValue("salt", salt.getBytes()); }
From source file:manchester.synbiochem.datacapture.SeekConnector.java
private void addExtra(Study s) { Element doc;/*from www.ja v a 2 s.c o m*/ try { log.info("populating extra structure for " + s.url); String u = s.url.toString().replaceAll("^.*//[^/]*/", ""); doc = get(u + ".xml").getDocumentElement(); } catch (Exception e) { log.warn("problem retrieving information from assay " + s.url, e); return; } try { for (Element inv : getElements(doc, SEEK, "associated", "investigations", "investigation")) { s.investigationName = inv.getAttributeNS(XLINK, "title"); s.investigationUrl = new URL(inv.getAttributeNS(XLINK, "href")); break; } for (Element prj : getElements(doc, SEEK, "associated", "projects", "project")) { String name = prj.getAttributeNS(XLINK, "title"); if (!name.equalsIgnoreCase("synbiochem")) { s.projectName = name; s.projectUrl = new URL(prj.getAttributeNS(XLINK, "href")); break; } } } catch (Exception e) { log.warn("problem when filling in information from assay " + s.url, e); } if (s.investigationName == null) s.investigationName = "UNKNOWN"; if (s.projectName == null) { s.projectName = "SynBioChem"; try { s.projectUrl = new URL(DEFAULT_PROJECT); } catch (MalformedURLException e) { // Should be unreachable } } }
From source file:com.amalto.core.storage.record.XmlDOMDataRecordReader.java
private void _read(MetadataRepository repository, DataRecord dataRecord, ComplexTypeMetadata type, Element element) {/* ww w .j av a 2 s . c o m*/ // TODO Don't use getChildNodes() but getNextSibling() calls (but cause regressions -> see TMDM-5410). String tagName = element.getTagName(); NodeList children = element.getChildNodes(); NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); if (!type.hasField(attribute.getNodeName())) { continue; } FieldMetadata field = type.getField(attribute.getNodeName()); dataRecord.set(field, StorageMetadataUtils.convert(attribute.getNodeValue(), field)); } for (int i = 0; i < children.getLength(); i++) { Node currentChild = children.item(i); if (currentChild instanceof Element) { Element child = (Element) currentChild; if (METADATA_NAMESPACE.equals(child.getNamespaceURI())) { DataRecordMetadataHelper.setMetadataValue(dataRecord.getRecordMetadata(), child.getLocalName(), child.getTextContent()); } else { if (!type.hasField(child.getTagName())) { continue; } FieldMetadata field = type.getField(child.getTagName()); if (field.getType() instanceof ContainedComplexTypeMetadata) { ComplexTypeMetadata containedType = (ComplexTypeMetadata) field.getType(); String xsiType = child.getAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type"); //$NON-NLS-1$ if (xsiType.startsWith("java:")) { //$NON-NLS-1$ // Special format for 'java:' type names (used in Castor XML to indicate actual class name) xsiType = ClassRepository.format(StringUtils .substringAfterLast(StringUtils.substringAfter(xsiType, "java:"), ".")); //$NON-NLS-1$ //$NON-NLS-2$ } if (!xsiType.isEmpty()) { for (ComplexTypeMetadata subType : containedType.getSubTypes()) { if (subType.getName().equals(xsiType)) { containedType = subType; break; } } } DataRecord containedRecord = new DataRecord(containedType, UnsupportedDataRecordMetadata.INSTANCE); dataRecord.set(field, containedRecord); _read(repository, containedRecord, containedType, child); } else if (ClassRepository.EMBEDDED_XML.equals(field.getType().getName())) { try { dataRecord.set(field, Util.nodeToString(element)); } catch (TransformerException e) { throw new RuntimeException(e); } } else { _read(repository, dataRecord, type, child); } } } else if (currentChild instanceof Text) { StringBuilder builder = new StringBuilder(); for (int j = 0; j < element.getChildNodes().getLength(); j++) { String nodeValue = element.getChildNodes().item(j).getNodeValue(); if (nodeValue != null) { builder.append(nodeValue.trim()); } } String textContent = builder.toString(); if (!textContent.isEmpty()) { FieldMetadata field = type.getField(tagName); if (field instanceof ReferenceFieldMetadata) { ComplexTypeMetadata actualType = ((ReferenceFieldMetadata) field).getReferencedType(); String mdmType = element.getAttributeNS(SkipAttributeDocumentBuilder.TALEND_NAMESPACE, "type"); //$NON-NLS-1$ if (!mdmType.isEmpty()) { actualType = repository.getComplexType(mdmType); } if (actualType == null) { throw new IllegalArgumentException("Type '" + mdmType + "' does not exist."); } dataRecord.set(field, StorageMetadataUtils.convert(textContent, field, actualType)); } else { dataRecord.set(field, StorageMetadataUtils.convert(textContent, field, type)); } } } } }
From source file:edu.internet2.middleware.shibboleth.common.config.relyingparty.saml.AbstractSAMLProfileConfigurationBeanDefinitionParser.java
/** {@inheritDoc} */ protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { builder.setLazyInit(true);//w w w . j a va2 s .co m Map<QName, List<Element>> children = XMLHelper.getChildElements(element); List<Element> audienceElems = children .get(new QName(SAMLRelyingPartyNamespaceHandler.NAMESPACE, "Audience")); if (audienceElems != null && audienceElems.size() > 0) { LazyList<String> audiences = new LazyList<String>(); for (Element audienceElem : audienceElems) { audiences.add(DatatypeHelper.safeTrimOrNullString(audienceElem.getTextContent())); } builder.addPropertyValue("audiences", audiences); } String secCredRef = DatatypeHelper .safeTrimOrNullString(element.getAttributeNS(null, "signingCredentialRef")); if (secCredRef != null) { builder.addDependsOn(secCredRef); builder.addPropertyReference("signingCredential", secCredRef); } long lifetime = 300000L; if (element.hasAttributeNS(null, "assertionLifetime")) { lifetime = SpringConfigurationUtils.parseDurationToMillis( "'assertionLifetime' on profile configuration of type " + XMLHelper.getXSIType(element), element.getAttributeNS(null, "assertionLifetime"), 0); } builder.addPropertyValue("assertionLifetime", lifetime); String artifactType = DatatypeHelper .safeTrimOrNullString(element.getAttributeNS(null, "outboundArtifactType")); if (artifactType != null) { byte[] artifactTypeBytes = DatatypeHelper.intToByteArray(Integer.parseInt(artifactType)); byte[] trimmedArtifactTypeBytes = { artifactTypeBytes[2], artifactTypeBytes[3] }; builder.addPropertyValue("outboundArtifactType", trimmedArtifactTypeBytes); } CryptoOperationRequirementLevel signRequests = CryptoOperationRequirementLevel.conditional; if (element.hasAttributeNS(null, "signRequests")) { signRequests = CryptoOperationRequirementLevel.valueOf(element.getAttributeNS(null, "signRequests")); } builder.addPropertyValue("signRequests", signRequests); CryptoOperationRequirementLevel signResponses = getSignResponsesDefault(); if (element.hasAttributeNS(null, "signResponses")) { signResponses = CryptoOperationRequirementLevel.valueOf(element.getAttributeNS(null, "signResponses")); } builder.addPropertyValue("signResponses", signResponses); CryptoOperationRequirementLevel signAssertions = getSignAssertionsDefault(); if (element.hasAttributeNS(null, "signAssertions")) { signAssertions = CryptoOperationRequirementLevel .valueOf(element.getAttributeNS(null, "signAssertions")); } builder.addPropertyValue("signAssertions", signAssertions); String secPolRef = DatatypeHelper.safeTrimOrNullString(element.getAttributeNS(null, "securityPolicyRef")); if (secPolRef != null) { builder.addDependsOn(secPolRef); builder.addPropertyReference("profileSecurityPolicy", secPolRef); } }
From source file:manchester.synbiochem.datacapture.SeekConnector.java
private void addExtra(Assay a) { Element doc;/*from www . j a v a 2s. co m*/ try { log.info("populating extra structure for " + a.url); String u = a.url.toString().replaceAll("^.*//[^/]*/", ""); doc = get(u + ".xml").getDocumentElement(); } catch (Exception e) { log.warn("problem retrieving information from assay " + a.url, e); return; } try { for (Element inv : getElements(doc, SEEK, "associated", "investigations", "investigation")) { a.investigationName = inv.getAttributeNS(XLINK, "title"); a.investigationUrl = new URL(inv.getAttributeNS(XLINK, "href")); break; } for (Element std : getElements(doc, SEEK, "associated", "studies", "study")) { a.studyName = std.getAttributeNS(XLINK, "title"); a.studyUrl = new URL(std.getAttributeNS(XLINK, "href")); break; } for (Element prj : getElements(doc, SEEK, "associated", "projects", "project")) { String name = prj.getAttributeNS(XLINK, "title"); if (!name.equalsIgnoreCase("synbiochem")) { a.projectName = name; a.projectUrl = new URL(prj.getAttributeNS(XLINK, "href")); break; } } } catch (Exception e) { log.warn("problem when filling in information from assay " + a.url, e); } if (a.investigationName == null) a.investigationName = "UNKNOWN"; if (a.studyName == null) a.studyName = "UNKNOWN"; if (a.projectName == null) { a.projectName = "SynBioChem"; try { a.projectUrl = new URL(DEFAULT_PROJECT); } catch (MalformedURLException e) { // Should be unreachable } } }
From source file:edu.internet2.middleware.shibboleth.common.config.resource.SVNResourceBeanDefinitionParser.java
/** * Gets the value of the {@value #RESOURCE_FILE_ATTRIB_NAME} attribute. * /*from ww w. j av a2 s. co m*/ * @param configElement resource configuration element * * @return value of the attribute * * @throws BeanCreationException thrown if the attribute is missing or contains an empty string */ protected String getResourceFile(Element configElement) throws BeanCreationException { if (!configElement.hasAttributeNS(null, RESOURCE_FILE_ATTRIB_NAME)) { log.error("SVN resource definition missing required '" + RESOURCE_FILE_ATTRIB_NAME + "' attribute"); throw new BeanCreationException( "SVN resource definition missing required '" + RESOURCE_FILE_ATTRIB_NAME + "' attribute"); } String filename = DatatypeHelper .safeTrimOrNullString(configElement.getAttributeNS(null, RESOURCE_FILE_ATTRIB_NAME)); if (filename == null) { log.error("SVN resource definition attribute '" + RESOURCE_FILE_ATTRIB_NAME + "' may not be an empty string"); throw new BeanCreationException("SVN resource definition attribute '" + RESOURCE_FILE_ATTRIB_NAME + "' may not be an empty string"); } return filename; }
From source file:edu.internet2.middleware.shibboleth.common.config.resource.SVNResourceBeanDefinitionParser.java
/** * Gets the value of the {@value #REPOSITORY_URL_ATTRIB_NAME} attribute. * /*from www.j a va 2 s. c o m*/ * @param configElement resource configuration element * * @return value of the attribute * * @throws BeanCreationException thrown if the attribute is missing or contains an invalid SVN URL */ protected SVNURL getRespositoryUrl(Element configElement) throws BeanCreationException { if (!configElement.hasAttributeNS(null, REPOSITORY_URL_ATTRIB_NAME)) { log.error("SVN resource definition missing required '" + REPOSITORY_URL_ATTRIB_NAME + "' attribute"); throw new BeanCreationException( "SVN resource definition missing required '" + REPOSITORY_URL_ATTRIB_NAME + "' attribute"); } String repositoryUrl = DatatypeHelper .safeTrimOrNullString(configElement.getAttributeNS(null, REPOSITORY_URL_ATTRIB_NAME)); try { return SVNURL.parseURIDecoded(repositoryUrl); } catch (SVNException e) { log.error("SVN remote repository URL " + repositoryUrl + " is not valid", e); throw new BeanCreationException("SVN remote repository URL " + repositoryUrl + " is not valid", e); } }
From source file:edu.internet2.middleware.shibboleth.common.config.resource.SVNResourceBeanDefinitionParser.java
/** * Gets the value of the {@value #REPOSITORY_URL_ATTRIB_NAME} attribute. * /* w ww . ja v a2s. c om*/ * @param configElement resource configuration element * * @return value of the attribute * * @throws BeanCreationException thrown if the attribute is missing or contains an invalid directory path */ protected File getWorkingCopyDirectory(Element configElement) throws BeanCreationException { if (!configElement.hasAttributeNS(null, WORKING_COPY_DIR_ATTRIB_NAME)) { log.error("SVN resource definition missing required '" + WORKING_COPY_DIR_ATTRIB_NAME + "' attribute"); throw new BeanCreationException( "SVN resource definition missing required '" + WORKING_COPY_DIR_ATTRIB_NAME + "' attribute"); } File directory = new File(DatatypeHelper .safeTrimOrNullString(configElement.getAttributeNS(null, WORKING_COPY_DIR_ATTRIB_NAME))); if (directory == null) { log.error("SVN working copy directory may not be null"); throw new BeanCreationException("SVN working copy directory may not be null"); } if (!directory.exists()) { boolean created = directory.mkdirs(); if (!created) { log.error("SVN working copy direction " + directory.getAbsolutePath() + " does not exist and could not be created"); throw new BeanCreationException("SVN working copy direction " + directory.getAbsolutePath() + " does not exist and could not be created"); } } if (!directory.isDirectory()) { log.error("SVN working copy location " + directory.getAbsolutePath() + " is not a directory"); throw new BeanCreationException( "SVN working copy location " + directory.getAbsolutePath() + " is not a directory"); } if (!directory.canRead()) { log.error("SVN working copy directory " + directory.getAbsolutePath() + " can not be read by this process"); throw new BeanCreationException("SVN working copy directory " + directory.getAbsolutePath() + " can not be read by this process"); } if (!directory.canWrite()) { log.error("SVN working copy directory " + directory.getAbsolutePath() + " can not be written to by this process"); throw new BeanCreationException("SVN working copy directory " + directory.getAbsolutePath() + " can not be written to by this process"); } return directory; }
From source file:edu.internet2.middleware.shibboleth.common.config.security.PKIXValidationOptionsBeanDefinitionParser.java
/** {@inheritDoc} */ protected void doParse(Element element, BeanDefinitionBuilder builder) { if (element.hasAttributeNS(null, "processEmptyCRLs")) { Attr attr = element.getAttributeNodeNS(null, "processEmptyCRLs"); builder.addPropertyValue("processEmptyCRLs", XMLHelper.getAttributeValueAsBoolean(attr)); }//from w w w. j a va 2 s. c o m if (element.hasAttributeNS(null, "processExpiredCRLs")) { Attr attr = element.getAttributeNodeNS(null, "processExpiredCRLs"); builder.addPropertyValue("processExpiredCRLs", XMLHelper.getAttributeValueAsBoolean(attr)); } if (element.hasAttributeNS(null, "processCredentialCRLs")) { Attr attr = element.getAttributeNodeNS(null, "processCredentialCRLs"); builder.addPropertyValue("processCredentialCRLs", XMLHelper.getAttributeValueAsBoolean(attr)); } if (element.hasAttributeNS(null, "defaultVerificationDepth")) { Integer depth = new Integer( DatatypeHelper.safeTrim(element.getAttributeNS(null, "defaultVerificationDepth"))); builder.addPropertyValue("defaultVerificationDepth", depth); } }
From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.attributeDefinition.TemplateAttributeDefinitionBeanDefinitionParser.java
/** {@inheritDoc} */ protected void doParse(String pluginId, Element pluginConfig, Map<QName, List<Element>> pluginConfigChildren, BeanDefinitionBuilder pluginBuilder, ParserContext parserContext) { super.doParse(pluginId, pluginConfig, pluginConfigChildren, pluginBuilder, parserContext); if (pluginConfigChildren.containsKey(TEMPLATE_ELEMENT_NAME)) { Element templateElement = pluginConfigChildren.get(TEMPLATE_ELEMENT_NAME).get(0); String attributeTemplate = DatatypeHelper.safeTrimOrNullString(templateElement.getTextContent()); pluginBuilder.addPropertyValue("attributeTemplate", attributeTemplate); }/*from w ww.ja va 2 s. com*/ List<String> sourceAttributes = new ArrayList<String>(); for (Element element : pluginConfigChildren.get(SOURCE_ATTRIBUTE_ELEMENT_NAME)) { sourceAttributes.add(DatatypeHelper.safeTrimOrNullString(element.getTextContent())); } pluginBuilder.addPropertyValue("sourceAttributes", sourceAttributes); String velocityEngineRef = pluginConfig.getAttributeNS(null, "velocityEngine"); pluginBuilder.addPropertyReference("velocityEngine", velocityEngineRef); }