Example usage for javax.xml.namespace QName getLocalPart

List of usage examples for javax.xml.namespace QName getLocalPart

Introduction

In this page you can find the example usage for javax.xml.namespace QName getLocalPart.

Prototype

public String getLocalPart() 

Source Link

Document

Get the local part of this QName.

Usage

From source file:org.jasig.springframework.security.portlet.authentication.PortletXmlMappableAttributesRetriever.java

/**
 * Loads the portlet.xml file using the configured <tt>ResourceLoader</tt> and
 * parses the role-name elements from it, using these as the set of <tt>mappableAttributes</tt>.
 *///  ww  w. j  a  v a 2 s .  c o m
public void afterPropertiesSet() throws Exception {
    Resource portletXml = resourceLoader.getResource("/WEB-INF/portlet.xml");
    Document doc = getDocument(portletXml.getInputStream());

    final XPathExpression roleNamesExpression;
    if (portletConfig == null) {
        final XPathFactory xPathFactory = XPathFactory.newInstance();

        final XPath xPath = xPathFactory.newXPath();
        roleNamesExpression = xPath.compile("/portlet-app/portlet/security-role-ref/role-name");
    } else {
        final XPathFactory xPathFactory = XPathFactory.newInstance();
        xPathFactory.setXPathVariableResolver(new XPathVariableResolver() {
            @Override
            public Object resolveVariable(QName variableName) {
                if ("portletName".equals(variableName.getLocalPart())) {
                    return portletConfig.getPortletName();
                }

                return null;
            }
        });
        final XPath xPath = xPathFactory.newXPath();
        roleNamesExpression = xPath
                .compile("/portlet-app/portlet[portlet-name=$portletName]/security-role-ref/role-name");
    }

    final NodeList securityRoles = (NodeList) roleNamesExpression.evaluate(doc, XPathConstants.NODESET);
    final Set<String> roleNames = new HashSet<String>();

    for (int i = 0; i < securityRoles.getLength(); i++) {
        Element secRoleElt = (Element) securityRoles.item(i);
        String roleName = secRoleElt.getTextContent().trim();
        roleNames.add(roleName);
        logger.info("Retrieved role-name '" + roleName + "' from portlet.xml");
    }

    if (roleNames.isEmpty()) {
        logger.info("No security-role-ref elements found in " + portletXml
                + (portletConfig == null ? "" : " for portlet " + portletConfig.getPortletName()));
    }

    mappableAttributes = Collections.unmodifiableSet(roleNames);
}

From source file:com.evolveum.midpoint.web.util.SchrodingerComponentInitListener.java

private String qnameToString(QName qname) {
    if (qname == null) {
        return null;
    }// w  w w  .j av  a  2  s.c o m

    return StringUtils.join(new Object[] { qname.getNamespaceURI(), qname.getLocalPart() }, "#");
}

From source file:com.bradmcevoy.property.BeanPropertySource.java

@Override
public Object getProperty(QName name, Resource r) throws NotAuthorizedException {
    PropertyDescriptor pd = getPropertyDescriptor(r, name.getLocalPart());
    if (pd == null) {
        throw new IllegalArgumentException("no prop: " + name.getLocalPart() + " on " + r.getClass());
    }//w  ww  . j  a v a2  s  .c  o m
    try {
        return pd.getReadMethod().invoke(r, NOARGS);
    } catch (Exception ex) {
        if (ex.getCause() instanceof NotAuthorizedException) {
            NotAuthorizedException na = (NotAuthorizedException) ex.getCause();
            throw na;
        } else {
            throw new RuntimeException(name.toString(), ex);
        }
    }
}

From source file:com.autentia.xml.namespace.QNameBuilder.java

private QName discoverQNameAndCachesIt(Class<?> classType, String classTypeNameSuffix, String prefixSuffix,
        QNamesCache cache) {//from   w ww  .j  a  v  a  2s.c  o m
    QName qName = cache.getQNameFor(classType);
    if (qName == null) {
        qName = discoverQNameFromJaxb(classType);

        final String localPart = (isNotBlank(qName.getLocalPart()) ? qName.getLocalPart()
                : discoverLocalPartFor(classType)) + classTypeNameSuffix;
        final String namespaceUri = isNotBlank(qName.getNamespaceURI()) ? qName.getNamespaceURI()
                : discoverNamespaceUriFor(classType, localPart);
        final String prefix = isNotBlank(qName.getPrefix()) ? qName.getPrefix()
                : discoverPrefixFor(classType, prefixSuffix);
        qName = new QName(namespaceUri, localPart, prefix);

        cache.putQNameFor(classType, qName);
    }
    return qName;
}

From source file:com.evolveum.midpoint.gui.api.component.DisplayNamePanel.java

private String getRelationLabel() {
    QName relation = getRelation();
    if (relation == null) {
        return "";
    }//  w ww.ja v a  2s.c o m
    // TODO: localization?
    return relation.getLocalPart();
}

From source file:io.twipple.springframework.data.clusterpoint.convert.DefaultClusterpointTypeMapperTest.java

@Test
public void testWriteType() throws Exception {
    ClusterpointDocument document = new ClusterpointDocument();
    mapper.writeType(MockEntity.class, document);

    QName typeAlias = document.getTypeAlias();
    assertNotNull(typeAlias);//from ww w. j  a va2s  .  c  o  m
    assertEquals("urn:io-twipple-springframework-data-clusterpoint-convert", typeAlias.getNamespaceURI());
    assertEquals("MockEntity", typeAlias.getLocalPart());
    assertEquals("mock", typeAlias.getPrefix());
}

From source file:com.nortal.jroad.wsdl.XTeeWsdlDefinition.java

private void addXroadHeaderPart(Definition definition, Message message, QName partName) {
    Part part = definition.createPart();
    part.setElementName(partName);/*from  ww  w .j av a2 s .co  m*/
    part.setName(partName.getLocalPart());
    message.addPart(part);
}

From source file:com.bradmcevoy.http.webdav.PropFindXmlGeneratorHelper.java

private void sendErrorProperties(Response.Status status, XmlWriter writer, Map<String, String> mapOfNamespaces,
        List<NameAndError> properties) {
    //            log.debug( "sendUnknownProperties: " + properties.size() );
    if (!properties.isEmpty()) {
        XmlWriter.Element elPropStat = writer.begin(WebDavProtocol.NS_DAV.getPrefix(), "propstat").open();
        XmlWriter.Element elProp = writer.begin(WebDavProtocol.NS_DAV.getPrefix(), "prop").open();
        for (NameAndError ne : properties) {
            QName qname = ne.getName();
            String prefix = mapOfNamespaces.get(qname.getNamespaceURI());
            writer.writeProperty(prefix, qname.getLocalPart());
        }/*from ww  w.jav a2 s.  c  o  m*/
        elProp.close();
        writer.writeProperty(WebDavProtocol.NS_DAV.getPrefix(), "status", status.toString());
        elPropStat.close();
    }
}

From source file:edu.cornell.mannlib.vivo.orcid.controller.OrcidConfirmationState.java

private String getElementFromOrcidIdentifier(String elementName) {
    OrcidProfile orcidProfile = getOrcidProfile();
    if (orcidProfile == null) {
        return "";
    }/*  ww w .j a  v a2s.  co m*/

    OrcidId id = orcidProfile.getOrcidIdentifier();
    if (id == null) {
        log.warn("There is no ORCID Identifier in the profile.");
        return "";
    }

    List<JAXBElement<String>> idElements = id.getContent();
    if (idElements != null) {
        for (JAXBElement<String> idElement : idElements) {
            QName name = idElement.getName();
            if (name != null && elementName.equals(name.getLocalPart())) {
                String value = idElement.getValue();
                if (value != null) {
                    return value;
                }
            }
        }
    }
    log.warn("Didn't find the element '' in the ORCID Identifier: " + idElements);
    return "";
}

From source file:com.centeractive.ws.builder.core.WsdlParser.java

public SoapBuilderFinder binding() {
    return new SoapBuilderFinder() {
        private String namespaceURI;
        private String localPart;
        private String prefix;

        @Override/*  w  w w .  j  a va  2 s .c  o  m*/
        public SoapBuilderFinder namespaceURI(String namespaceURI) {
            this.namespaceURI = namespaceURI;
            return this;
        }

        @Override
        public SoapBuilderFinder localPart(String localPart) {
            this.localPart = localPart;
            return this;
        }

        @Override
        public SoapBuilderFinder prefix(String prefix) {
            this.prefix = prefix;
            return this;
        }

        @Override
        public SoapBuilder builder() {
            validate();
            return getBuilder(getBindingName(), SoapContext.DEFAULT);
        }

        @Override
        public SoapBuilder builder(SoapContext context) {
            validate();
            return getBuilder(getBindingName(), context);
        }

        @Override
        public SoapOperationFinder operation() {
            return builder().operation();
        }

        private QName getBindingName() {
            List<QName> result = new ArrayList<QName>();
            for (QName bindingName : soapFacade.getBindingNames()) {
                if (bindingName.getLocalPart().equals(localPart)) {
                    if (namespaceURI != null) {
                        if (!bindingName.getNamespaceURI().equals(namespaceURI)) {
                            continue;
                        }
                    }
                    if (prefix != null) {
                        if (!bindingName.getPrefix().equals(prefix)) {
                            continue;
                        }
                    }
                    result.add(bindingName);
                }
            }
            if (result.isEmpty()) {
                throw new SoapBuilderException("Binding not found");
            }
            if (result.size() > 1) {
                throw new SoapBuilderException("Found more than one binding " + result);
            }
            return result.iterator().next();
        }

        private void validate() {
            if (StringUtils.isBlank(localPart)) {
                throw new SoapBuilderException("Specify at least localPart of the binding's QName");
            }
        }
    };
}