List of usage examples for javax.xml.namespace QName getNamespaceURI
public String getNamespaceURI()
Get the Namespace URI of this QName
.
From source file:com.evolveum.midpoint.provisioning.ucf.impl.ConnectorInstanceIcfImpl.java
private void convertFromPassword(Set<Attribute> attributes, PropertyDelta<ProtectedStringType> passwordDelta) throws SchemaException { if (passwordDelta == null) { throw new IllegalArgumentException("No password was provided"); }//from w w w.j ava 2 s .co m QName elementName = passwordDelta.getElementName(); if (StringUtils.isBlank(elementName.getNamespaceURI())) { if (!QNameUtil.match(elementName, PasswordType.F_VALUE)) { return; } } else if (!passwordDelta.getElementName().equals(PasswordType.F_VALUE)) { return; } PrismProperty<ProtectedStringType> newPassword = passwordDelta.getPropertyNewMatchingPath(); if (newPassword == null || newPassword.isEmpty()) { LOGGER.trace("Skipping processing password delta. Password delta does not contain new value."); return; } GuardedString guardedPassword = toGuardedString(newPassword.getValue().getValue(), "new password"); attributes.add(AttributeBuilder.build(OperationalAttributes.PASSWORD_NAME, guardedPassword)); }
From source file:com.evolveum.midpoint.provisioning.ucf.impl.ConnectorInstanceIcfImpl.java
private void transformResultsHandlerConfiguration(ResultsHandlerConfiguration resultsHandlerConfiguration, PrismContainer<?> resultsHandlerConfigurationContainer) throws SchemaException { if (resultsHandlerConfigurationContainer == null || resultsHandlerConfigurationContainer.getValue() == null) { return;//from w w w . jav a 2 s . c o m } for (PrismProperty prismProperty : resultsHandlerConfigurationContainer.getValue().getProperties()) { QName propertyQName = prismProperty.getElementName(); if (propertyQName.getNamespaceURI().equals(ConnectorFactoryIcfImpl.NS_ICF_CONFIGURATION)) { String subelementName = propertyQName.getLocalPart(); if (ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ENABLE_NORMALIZING_RESULTS_HANDLER .equals(subelementName)) { resultsHandlerConfiguration.setEnableNormalizingResultsHandler(parseBoolean(prismProperty)); } else if (ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ENABLE_FILTERED_RESULTS_HANDLER .equals(subelementName)) { resultsHandlerConfiguration.setEnableFilteredResultsHandler(parseBoolean(prismProperty)); } else if (ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_FILTERED_RESULTS_HANDLER_IN_VALIDATION_MODE .equals(subelementName)) { resultsHandlerConfiguration .setFilteredResultsHandlerInValidationMode(parseBoolean(prismProperty)); } else if (ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ENABLE_CASE_INSENSITIVE_HANDLER .equals(subelementName)) { resultsHandlerConfiguration.setEnableCaseInsensitiveFilter(parseBoolean(prismProperty)); } else if (ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ENABLE_ATTRIBUTES_TO_GET_SEARCH_RESULTS_HANDLER .equals(subelementName)) { resultsHandlerConfiguration .setEnableAttributesToGetSearchResultsHandler(parseBoolean(prismProperty)); } else { throw new SchemaException("Unexpected element " + propertyQName + " in " + ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ELEMENT_LOCAL_NAME); } } else { throw new SchemaException("Unexpected element " + propertyQName + " in " + ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ELEMENT_LOCAL_NAME); } } }
From source file:com.evolveum.midpoint.provisioning.ucf.impl.ConnectorInstanceIcfImpl.java
private void transformConnectorTimeoutsConfiguration(APIConfiguration apiConfig, PrismContainer<?> connectorTimeoutsContainer) throws SchemaException { if (connectorTimeoutsContainer == null || connectorTimeoutsContainer.getValue() == null) { return;//from w ww .jav a 2 s . c om } for (PrismProperty prismProperty : connectorTimeoutsContainer.getValue().getProperties()) { QName propertQName = prismProperty.getElementName(); if (ConnectorFactoryIcfImpl.NS_ICF_CONFIGURATION.equals(propertQName.getNamespaceURI())) { String opName = propertQName.getLocalPart(); Class<? extends APIOperation> apiOpClass = ConnectorFactoryIcfImpl.resolveApiOpClass(opName); if (apiOpClass != null) { apiConfig.setTimeout(apiOpClass, parseInt(prismProperty)); } else { throw new SchemaException("Unknown operation name " + opName + " in " + ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_TIMEOUTS_XML_ELEMENT_NAME); } } } }
From source file:com.evolveum.midpoint.provisioning.ucf.impl.ConnectorInstanceIcfImpl.java
private void transformConnectorConfiguration(ConfigurationProperties configProps, PrismContainer<?> configurationPropertiesContainer, String connectorConfNs) throws ConfigurationException, SchemaException { if (configurationPropertiesContainer == null || configurationPropertiesContainer.getValue() == null) { throw new SchemaException("No configuration properties container in " + connectorType); }//from w w w . j a va2 s .c o m int numConfingProperties = 0; List<QName> wrongNamespaceProperties = new ArrayList<>(); for (PrismProperty prismProperty : configurationPropertiesContainer.getValue().getProperties()) { QName propertyQName = prismProperty.getElementName(); // All the elements must be in a connector instance // namespace. if (propertyQName.getNamespaceURI() == null || !propertyQName.getNamespaceURI().equals(connectorConfNs)) { LOGGER.warn("Found element with a wrong namespace ({}) in {}", propertyQName.getNamespaceURI(), connectorType); wrongNamespaceProperties.add(propertyQName); } else { numConfingProperties++; // Local name of the element is the same as the name // of ICF configuration property String propertyName = propertyQName.getLocalPart(); ConfigurationProperty property = configProps.getProperty(propertyName); if (property == null) { throw new ConfigurationException("Unknown configuration property " + propertyName); } // Check (java) type of ICF configuration property, // behave accordingly Class<?> type = property.getType(); if (type.isArray()) { property.setValue(convertToIcfArray(prismProperty, type.getComponentType())); // property.setValue(prismProperty.getRealValuesArray(type.getComponentType())); } else { // Single-valued property are easy to convert property.setValue(convertToIcfSingle(prismProperty, type)); // property.setValue(prismProperty.getRealValue(type)); } } } // empty configuration is OK e.g. when creating a new resource using wizard if (numConfingProperties == 0 && !wrongNamespaceProperties.isEmpty()) { throw new SchemaException("No configuration properties found. Wrong namespace? (expected: " + connectorConfNs + ", present e.g. " + wrongNamespaceProperties.get(0) + ")"); } }
From source file:nl.knaw.huygens.tei.xpath.XPathUtil.java
public static Map<String, String> getNamespaceInfo(String xml) { Map<String, String> namespaces = Maps.newIdentityHashMap(); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); try {//from w ww. j a v a 2s . c o m XMLStreamReader xreader = inputFactory.createXMLStreamReader(IOUtils.toInputStream(xml, "UTF-8")); while (xreader.hasNext()) { if (xreader.next() == XMLStreamConstants.START_ELEMENT) { QName qName = xreader.getName(); if (qName != null) { addNamespace(namespaces, qName.getPrefix(), qName.getNamespaceURI()); for (int i = 0; i < xreader.getAttributeCount(); i++) { addNamespace(namespaces, xreader.getAttributePrefix(i), xreader.getAttributeNamespace(i)); } } } } } catch (XMLStreamException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return namespaces; }
From source file:nl.meertens.cmdi.FindProfiles.java
public static void main(String[] args) throws FileNotFoundException { Boolean debug = false;//from w w w . j av a 2s.co m Boolean verbose = false; String dir = "."; String ext = "cmdi"; // check command line OptionParser parser = new OptionParser("dve:?*"); OptionSet options = parser.parse(args); if (options.has("d")) debug = true; if (options.has("v")) verbose = true; if (options.has("e")) ext = (String) options.valueOf("e"); if (options.has("?")) { showHelp(); System.exit(0); } List arg = options.nonOptionArguments(); if (arg.size() > 1) { System.err.println("!FTL: only one source <DIR> argument is allowed!"); showHelp(); System.exit(1); } if (arg.size() == 1) dir = (String) arg.get(0); Set<String> profiles = new HashSet<String>(); Pattern cr_rest = Pattern.compile("^.*" + CR_URI + "rest/registry/profiles/", Pattern.DOTALL); Pattern cr_ext = Pattern.compile("/xsd.*$", Pattern.DOTALL); XMLInputFactory2 xmlif = (XMLInputFactory2) XMLInputFactory2.newInstance(); xmlif.configureForConvenience(); Collection<File> inputs = FileUtils.listFiles(new File(dir), new String[] { ext }, true); int e = 0; int i = 0; int s = inputs.size(); for (File input : inputs) { i++; if (verbose) System.err.println("?INF: " + i + "/" + s + ": " + input); int state = START; int sdepth = 0; int depth = 0; XMLStreamReader2 xmlr = null; FileInputStream in = null; String profile = null; try { in = new FileInputStream(input); xmlr = (XMLStreamReader2) xmlif.createXMLStreamReader(in); while (state != STOP && state != ERROR) { int eventType = xmlr.getEventType(); QName qn = null; switch (eventType) { case XMLEvent2.START_ELEMENT: depth++; qn = xmlr.getName(); break; case XMLEvent2.END_ELEMENT: qn = xmlr.getName(); break; } switch (state) { case START: switch (eventType) { case XMLEvent2.START_ELEMENT: if (qn.getNamespaceURI().equals(CMD_NS) && qn.getLocalPart().equals("CMD")) { state = OPEN_CMD; sdepth = depth; String prof = xmlr.getAttributeValue(XSI_NS, "schemaLocation"); if (prof != null) { if (prof.contains(CR_URI)) { prof = cr_rest.matcher(prof).replaceFirst(""); prof = cr_ext.matcher(prof).replaceFirst(""); profile = prof; if (verbose || debug) System.out.println("?" + (debug ? "DBG" : "INF") + ": " + input + ": xsi:schemaLocation[" + prof + "]"); } else System.err.println("!WRN: " + input + ": xsi:schemaLocation[" + prof + "] doesn't contain a reference to a CMD profile in CR!"); } } else { System.err.println("!ERR: " + input + ": no cmd:CMD root found!"); state = ERROR; } break; case XMLEvent2.END_DOCUMENT: System.err.println("!ERR: " + input + ": no XML content found!"); state = ERROR; break; } break; case OPEN_CMD: switch (eventType) { case XMLEvent2.START_ELEMENT: if (qn.getNamespaceURI().equals(CMD_NS) && qn.getLocalPart().equals("Header")) { state = OPEN_HEADER; sdepth = depth; } else { System.err.println("!ERR: " + input + ": no cmd:CMD/cmd:Header found!"); state = ERROR; } break; case XMLEvent2.END_ELEMENT: if (qn.getNamespaceURI().equals(CMD_NS) && qn.getLocalPart().equals("CMD") && sdepth == depth) { System.err.println("!ERR: " + input + ": no cmd:CMD/cmd:Header found!"); state = ERROR; } break; } break; case OPEN_HEADER: switch (eventType) { case XMLEvent2.START_ELEMENT: if (qn.getNamespaceURI().equals(CMD_NS) && qn.getLocalPart().equals("MdProfile") && sdepth + 1 == depth) { state = OPEN_MDPROFILE; } break; case XMLEvent2.END_ELEMENT: if (qn.getNamespaceURI().equals(CMD_NS) && qn.getLocalPart().equals("Header") && sdepth == depth) { System.err.println("!" + (profile == null ? "ERR" : "WRN") + ": " + input + ": no cmd:CMD/cmd:Header/cmd:MdProfile found!"); state = ERROR; } break; } break; case OPEN_MDPROFILE: switch (eventType) { case XMLEvent2.CHARACTERS: String prof = xmlr.getText(); prof = cr_rest.matcher(prof).replaceFirst(""); prof = cr_ext.matcher(prof).replaceFirst(""); if (verbose || debug) System.out.println( "?" + (debug ? "DBG" : "INF") + ": " + input + ": MdProfile[" + prof + "]"); if (profile == null) profile = prof; else if (!prof.equals(profile)) System.out.println("!WRN: " + input + ": MdProfile[" + prof + "] and xsi:schemaLocation[" + profile + "] contradict!"); state = STOP; break; default: state = STOP; break; } break; } switch (eventType) { case XMLEvent2.END_ELEMENT: depth--; break; } eventType = xmlr.next(); } } catch (Exception ex) { System.err.println("!ERR: " + input + ": " + ex); ex.printStackTrace(System.err); state = ERROR; } finally { try { xmlr.close(); in.close(); } catch (Exception ex) { System.err.println("!ERR: " + input + ": " + ex); ex.printStackTrace(System.err); state = ERROR; } } if (profile != null) profiles.add(profile); if (state == ERROR) e++; } for (String profile : profiles) { System.out.println(profile); } System.exit(e); }
From source file:org.apache.abdera.protocol.server.ProviderHelper.java
/** * Return false if the element contains any extension elements that are not supported *//*w ww . jav a2 s.c o m*/ public static boolean checkElementNamespaces(Element element, List<String> ignore) { List<QName> attrs = element.getExtensionAttributes(); for (QName qname : attrs) { String ns = qname.getNamespaceURI(); if (!ignore.contains(ns)) return false; } if (element instanceof ExtensibleElement) { ExtensibleElement ext = (ExtensibleElement) element; List<Element> extensions = ext.getExtensions(); for (Element el : extensions) { QName qname = el.getQName(); String ns = qname.getNamespaceURI(); if (!ignore.contains(ns)) return false; if (!checkElementNamespaces(el, ignore)) return false; } } return true; }
From source file:org.apache.abdera.util.AbstractStreamWriter.java
public StreamWriter writeAttribute(QName qname, String value) { if (value == null) return this; return writeAttribute(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix(), value); }
From source file:org.apache.abdera.util.AbstractStreamWriter.java
public StreamWriter startElement(QName qname) { return startElement(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix()); }
From source file:org.apache.abdera.util.AbstractStreamWriter.java
public StreamWriter writeAttribute(QName qname, Date value) { return writeAttribute(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix(), value); }