use of com.google.cloud.servicedirectory.v1.Namespace in project ldapchai by ldapchai.
the class NmasResponseSet method readDisplayString.
private static String readDisplayString(final Element questionElement, final Locale locale) {
final Namespace xmlNamespace = Namespace.getNamespace("xml", "http://www.w3.org/XML/1998/namespace");
// someday ResoureBundle won't suck and this will be a 5 line method.
// see if the node has any localized displays.
final List displayChildren = questionElement.getChildren("display");
// if no locale specified, or if no localized text is available, just use the default.
if (locale == null || displayChildren == null || displayChildren.size() < 1) {
return questionElement.getText();
}
// convert the xml 'display' elements to a map of locales/strings
final Map<Locale, String> localizedStringMap = new HashMap<Locale, String>();
for (final Object loopDisplayChild : displayChildren) {
final Element loopDisplay = (Element) loopDisplayChild;
final Attribute localeAttr = loopDisplay.getAttribute("lang", xmlNamespace);
if (localeAttr != null) {
final String localeStr = localeAttr.getValue();
final String displayStr = loopDisplay.getText();
final Locale localeKey = parseLocaleString(localeStr);
localizedStringMap.put(localeKey, displayStr);
}
}
final Locale matchedLocale = localeResolver(locale, localizedStringMap.keySet());
if (matchedLocale != null) {
return localizedStringMap.get(matchedLocale);
}
// none found, so just return the default string.
return questionElement.getText();
}
use of com.google.cloud.servicedirectory.v1.Namespace in project jspwiki by apache.
the class WebContainerAuthorizer method getRoles.
/**
* Protected method that extracts the roles from JSPWiki's web application
* deployment descriptor. Each Role is constructed by using the String
* representation of the Role, for example
* <code>new Role("Administrator")</code>.
* @param webxml the web application deployment descriptor
* @return an array of Role objects
*/
protected Role[] getRoles(final Document webxml) {
final Set<Role> roles = new HashSet<>();
final Element root = webxml.getRootElement();
final Namespace jeeNs = Namespace.getNamespace("j", J2EE_SCHEMA_25_NAMESPACE);
// Get roles referred to by constraints
final String constrainsSelector = "//j:web-app/j:security-constraint/j:auth-constraint/j:role-name";
final List<Element> constraints = XPathFactory.instance().compile(constrainsSelector, Filters.element(), null, jeeNs).evaluate(root);
for (final Element constraint : constraints) {
final String role = constraint.getTextTrim();
roles.add(new Role(role));
}
// Get all defined roles
final String rolesSelector = "//j:web-app/j:security-role/j:role-name";
final List<Element> nodes = XPathFactory.instance().compile(rolesSelector, Filters.element(), null, jeeNs).evaluate(root);
for (final Element node : nodes) {
final String role = node.getTextTrim();
roles.add(new Role(role));
}
return roles.toArray(new Role[0]);
}
use of com.google.cloud.servicedirectory.v1.Namespace in project wildfly-camel by wildfly-extras.
the class WildFlyCamelConfigPlugin method addProperty.
private static void addProperty(Element systemProperties, Map<String, Element> propertiesByName, String name, String value) {
Namespace namespace = systemProperties.getNamespace();
if (!propertiesByName.containsKey(name)) {
systemProperties.addContent(new Text(" "));
systemProperties.addContent(new Element("property", namespace).setAttribute("name", name).setAttribute("value", value));
systemProperties.addContent(new Text("\n "));
}
}
use of com.google.cloud.servicedirectory.v1.Namespace in project CodenameOne by codenameone.
the class JDomModelETL method writePom.
private void writePom(File pomFile) throws IOException {
Element rootElement = document.getRootElement();
if (modelETLRequest.isAddSchema()) {
String modelVersion = model.getModelVersion();
Namespace pomNamespace = Namespace.getNamespace("", "http://maven.apache.org/POM/" + modelVersion);
rootElement.setNamespace(pomNamespace);
Namespace xsiNamespace = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
rootElement.addNamespaceDeclaration(xsiNamespace);
if (rootElement.getAttribute("schemaLocation", xsiNamespace) == null) {
rootElement.setAttribute("schemaLocation", "http://maven.apache.org/POM/" + modelVersion + " http://maven.apache.org/maven-v" + modelVersion.replace('.', '_') + ".xsd", xsiNamespace);
}
// the empty namespace is considered equal to the POM namespace, so match them up to avoid extra xmlns=""
ElementFilter elementFilter = new ElementFilter(Namespace.getNamespace(""));
for (Iterator<?> i = rootElement.getDescendants(elementFilter); i.hasNext(); ) {
Element e = (Element) i.next();
e.setNamespace(pomNamespace);
}
}
try (Writer writer = WriterFactory.newXmlWriter(pomFile)) {
if (intro != null) {
writer.write(intro);
}
printDocumentToWriter(document, writer, modelETLRequest.getLineSeparator());
if (outtro != null) {
writer.write(outtro);
}
}
}
use of com.google.cloud.servicedirectory.v1.Namespace in project pom-manipulation-ext by release-engineering.
the class Utils method getNamespacesInScope.
/**
* Get the Namespaces that are in-scope on this Element. Element has the
* most complex rules for the namespaces-in-scope.
* <p>
* The scope is built up from a number of sources following the rules of
* XML namespace inheritence as follows:
* <ul>
* <li>The {@link Namespace#XML_NAMESPACE} is added
* <li>The element's namespace is added (commonly
* {@link Namespace#NO_NAMESPACE})
* <li>All the attributes are inspected and their Namespaces are included
* <li>If the element has a parent then the parent's Namespace scope is
* inspected, and any prefixes in the parent scope that are not yet bound
* in this Element's scope are included.
* <li>If the default Namespace (the no-prefix namespace) has not been
* encountered for this Element then {@link Namespace#NO_NAMESPACE} is
* included.
* </ul>
* The Element's Namespace scope consist of it's inherited Namespaces and
* any modifications to that scope derived from the Element itself. If the
* element is detached then it's inherited scope consists of just
* If an element has no parent then
* <p>
* Note that the Element's Namespace will always be reported first.
* {@inheritDoc}
*/
// Copied from JDOM2
static List<Namespace> getNamespacesInScope(Element element) {
// The assumption here is that all namespaces are valid,
// that there are no namespace collisions on this element
// This method is also the 'anchor' of the three getNamespaces*() methods
// It does not make reference to this Element instance's other
// getNamespace*() methods
TreeMap<String, Namespace> namespaces = new TreeMap<>();
namespaces.put(Namespace.XML_NAMESPACE.getPrefix(), Namespace.XML_NAMESPACE);
namespaces.put(element.getNamespacePrefix(), element.getNamespace());
if (element.getAdditionalNamespaces() != null) {
for (Namespace ns : element.getAdditionalNamespaces()) {
if (!namespaces.containsKey(ns.getPrefix())) {
namespaces.put(ns.getPrefix(), ns);
}
}
}
if (element.getAttributes() != null) {
for (Attribute att : element.getAttributes()) {
Namespace ns = att.getNamespace();
if (!namespaces.containsKey(ns.getPrefix())) {
namespaces.put(ns.getPrefix(), ns);
}
}
}
// Right, we now have all the namespaces that are current on this Element.
// Include any other namespaces that are inherited.
final Element pnt = element.getParentElement();
if (pnt != null) {
for (Namespace ns : getNamespacesInScope(pnt)) {
if (!namespaces.containsKey(ns.getPrefix())) {
namespaces.put(ns.getPrefix(), ns);
}
}
}
if (pnt == null && !namespaces.containsKey("")) {
// we are the root element, and there is no 'default' namespace.
namespaces.put(Namespace.NO_NAMESPACE.getPrefix(), Namespace.NO_NAMESPACE);
}
ArrayList<Namespace> al = new ArrayList<>(namespaces.size());
al.add(element.getNamespace());
namespaces.remove(element.getNamespacePrefix());
al.addAll(namespaces.values());
return Collections.unmodifiableList(al);
}
Aggregations