Example usage for org.w3c.dom Element getLocalName

List of usage examples for org.w3c.dom Element getLocalName

Introduction

In this page you can find the example usage for org.w3c.dom Element getLocalName.

Prototype

public String getLocalName();

Source Link

Document

Returns the local part of the qualified name of this node.

Usage

From source file:be.fedict.eid.dss.client.DigitalSignatureServiceClient.java

@SuppressWarnings("unchecked")
private VerificationReportType findVerificationReport(ResponseBaseType responseBase) {

    AnyType optionalOutputs = responseBase.getOptionalOutputs();
    if (null == optionalOutputs) {
        return null;
    }//ww  w .jav a  2 s.c om
    List<Object> optionalOutputContent = optionalOutputs.getAny();
    for (Object optionalOutput : optionalOutputContent) {

        if (optionalOutput instanceof Element) {
            Element optionalOutputElement = (Element) optionalOutput;
            if (DSSConstants.VR_NAMESPACE.equals(optionalOutputElement.getNamespaceURI())
                    && "VerificationReport".equals(optionalOutputElement.getLocalName())) {
                JAXBElement<VerificationReportType> verificationReportElement;
                try {
                    verificationReportElement = (JAXBElement<VerificationReportType>) this.vrUnmarshaller
                            .unmarshal(optionalOutputElement);
                } catch (JAXBException e) {
                    throw new RuntimeException("JAXB error parsing verification report: " + e.getMessage(), e);
                }
                return verificationReportElement.getValue();
            }
        }
    }
    return null;
}

From source file:be.fedict.eid.dss.client.DigitalSignatureServiceClient.java

@SuppressWarnings("unchecked")
private StorageInfo findStorageInfo(SignResponse signeResponse) {

    AnyType optionalOutputs = signeResponse.getOptionalOutputs();
    if (null == optionalOutputs) {
        return null;
    }/*w ww .j  a  v  a 2 s  .co  m*/
    List<Object> optionalOutputContent = optionalOutputs.getAny();
    for (Object optionalOutput : optionalOutputContent) {

        if (optionalOutput instanceof Element) {

            Element optionalOutputElement = (Element) optionalOutput;
            if (DSSConstants.ARTIFACT_NAMESPACE.equals(optionalOutputElement.getNamespaceURI())
                    && "StorageInfo".equals(optionalOutputElement.getLocalName())) {
                JAXBElement<StorageInfo> storageInfoElement;
                try {
                    storageInfoElement = (JAXBElement<StorageInfo>) this.artifactUnmarshaller
                            .unmarshal(optionalOutputElement);
                } catch (JAXBException e) {
                    throw new RuntimeException("JAXB error parsing storage info: " + e.getMessage(), e);
                }
                return storageInfoElement.getValue();
            }
        }
    }

    return null;
}

From source file:com.apporiented.spring.override.AbstractGenericBeanDefinitionParser.java

public final BeanDefinition parse(Element element, ParserContext parserContext) {
    if (!enabled) {
        throw new FatalBeanException("Support for " + element.getTagName()
                + " has been disabled. Please add the required jar files " + "to your classpath.");
    }//from w  w w  .  j  a v  a  2  s .c  o m
    AbstractBeanDefinition definition = parseInternal(element, parserContext);
    if (!parserContext.isNested()) {
        try {
            String id = resolveId(element, definition, parserContext);
            if (!StringUtils.hasText(id)) {
                parserContext.getReaderContext().error("Id is required for element '" + element.getLocalName()
                        + "' when used as a top-level tag", element);
            }
            String[] aliases = resolveAliases(element, definition, parserContext);
            BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
            if (decorator != null) {
                holder = decorator.decorate(element, holder, parserContext);
            }
            registerBeanDefinition(holder, parserContext.getRegistry());
            if (shouldFireEvents()) {
                BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder);
                postProcessComponentDefinition(componentDefinition);
                parserContext.registerComponent(componentDefinition);
            }
        } catch (BeanDefinitionStoreException ex) {
            parserContext.getReaderContext().error(ex.getMessage(), element);
            return null;
        }
    } else if (decorator != null) {
        BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "");
        decorator.decorate(element, holder, parserContext);
    }
    return definition;
}

From source file:com.amalto.workbench.providers.XSDTreeLabelProvider.java

@Override
public Image getImage(Object obj) {

    if (obj instanceof XSDElementDeclaration) {
        // top declaration
        XSDElementDeclaration decl = (XSDElementDeclaration) obj;
        // check if concept or "just" element
        boolean isConcept = false;
        EList l = decl.getIdentityConstraintDefinitions();
        for (Iterator iter = l.iterator(); iter.hasNext();) {
            XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
            if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
                isConcept = true;//from   w w  w.j  av  a2 s. c o  m
                break;
            }
        }
        // display approprite image
        if (isConcept) {
            return ImageCache.getCreatedImage(EImage.CONCEPT.getPath());
        } else {
            return ImageCache.getCreatedImage(EImage.ELEMENT_ONLY.getPath());
            /*
             * if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) return
             * PlatformUI.getWorkbench().getSharedImages().getCreatedImage(ISharedImages.IMG_OBJ_FOLDER); else
             * return ImageCache.getCreatedImage( "icons/elements_obj_+.gif");
             */
        }
    }

    if (obj instanceof XSDParticle) {
        XSDParticle xsdParticle = (XSDParticle) obj;

        XSDTerm xsdTerm = xsdParticle.getTerm();
        if (xsdTerm instanceof XSDElementDeclaration) {
            // get Type of Parent Group
            List<Object> realKeyInfos = Util.getRealKeyInfos(entity, xsdParticle);
            if (realKeyInfos != null && realKeyInfos.size() > 0) {
                return ImageCache.getCreatedImage(EImage.PRIMARYKEY.getPath());
            }
            if (XSDUtil.hasFKInfo((XSDElementDeclaration) xsdTerm)) {
                return ImageCache.getCreatedImage(EImage.FK_OBJ.getPath());
            }

            XSDConcreteComponent xsdConcreteComponent = xsdParticle.getContainer();
            if (xsdConcreteComponent instanceof XSDModelGroup) {
                return ImageCache.getCreatedImage(EImage.SCHEMAELEMENT.getPath());
            }
            /*
             * if(((XSDElementDeclaration) xsdTerm).getAnonymousTypeDefinition() instanceof
             * XSDComplexTypeDefinition) return ImageCache.getCreatedImage( EImage.COMPLEXTYPE.getPath()); else
             * return ImageCache.getCreatedImage( EImage.SIMPLETYPE.getPath());
             */

        } else if (xsdTerm instanceof XSDModelGroup) {
            int type = ((XSDModelGroup) xsdTerm).getCompositor().getValue();
            switch (type) {
            case XSDCompositor.ALL:
                return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
            case XSDCompositor.CHOICE:
                return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
            case XSDCompositor.SEQUENCE:
                return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
            }
        } else if (xsdTerm instanceof XSDWildcard) {
            return ImageCache.getCreatedImage("icons/wildcard.gif");//$NON-NLS-1$
        } else {
            log.info(Messages.bind(Messages.XSDTreeLabelProvider_27, xsdTerm.getClass().getName()));
            return ImageCache.getCreatedImage("icons/error.gif");//$NON-NLS-1$
        }
    }

    if (obj instanceof XSDSimpleTypeDefinition) {
        return ImageCache.getCreatedImage(EImage.SIMPLETYPE.getPath());
    }

    if (obj instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) obj;
        XSDComplexTypeContent ctc = ctd.getContent();
        if (ctc instanceof XSDParticle) {
            if (((XSDParticle) ctc).getTerm() instanceof XSDModelGroup) {
                int type = ((XSDModelGroup) ((XSDParticle) ctc).getTerm()).getCompositor().getValue();
                switch (type) {
                case XSDCompositor.ALL:
                    return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
                case XSDCompositor.CHOICE:
                    return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
                case XSDCompositor.SEQUENCE:
                    return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
                }
            }
        } else {
            // simple Type!!!
            log.info(Messages.bind(Messages.XSDTreeLabelProvider_28, ctc.getClass().getName()));
            return ImageCache.getCreatedImage("icons/error.gif");//$NON-NLS-1$
        }
    }

    if (obj instanceof XSDModelGroup) {
        int type = ((XSDModelGroup) obj).getCompositor().getValue();
        switch (type) {
        case XSDCompositor.ALL:
            return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
        case XSDCompositor.CHOICE:
            return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
        case XSDCompositor.SEQUENCE:
            return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
        }
    }

    if (obj instanceof XSDFacet) {
        return ImageCache.getCreatedImage(EImage.FACET.getPath());
    }

    if (obj instanceof XSDIdentityConstraintDefinition) {
        XSDIdentityConstraintDefinition identity = (XSDIdentityConstraintDefinition) obj;
        if (identity.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
            return ImageCache.getCreatedImage(EImage.KEYS.getPath());
        }
        return ImageCache.getCreatedImage(EImage.PRIMARYKEY.getPath());
    }

    if (obj instanceof XSDXPathDefinition) {
        XSDXPathDefinition xpath = (XSDXPathDefinition) obj;
        if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
            return ImageCache.getCreatedImage("icons/field.gif");//$NON-NLS-1$
        }
        return ImageCache.getCreatedImage("icons/selector.gif");//$NON-NLS-1$
    }

    if (obj instanceof XSDAttributeGroupDefinition) {
        return ImageCache.getCreatedImage("icons/attribute_group.gif");//$NON-NLS-1$
    }

    if (obj instanceof XSDAttributeUse) {
        XSDAttributeUse att = (XSDAttributeUse) obj;
        if ("xmlns".equals(att.getAttributeDeclaration().getTargetNamespace())) {//$NON-NLS-1$
            return ImageCache.getCreatedImage(EImage.ANNOTATION.getPath());
        }
        if (att.getUse().equals(XSDAttributeUseCategory.REQUIRED_LITERAL)) {
            return ImageCache.getCreatedImage("icons/attribute_mandatory.gif");//$NON-NLS-1$
        } else {
            return ImageCache.getCreatedImage("icons/attribute.gif");//$NON-NLS-1$
        }
    }

    if (obj instanceof XSDAttributeDeclaration) {
        XSDAttributeDeclaration attributeDec = (XSDAttributeDeclaration) obj;
        if ("xmlns".equals(attributeDec.getTargetNamespace())) //$NON-NLS-1$
        {
            return ImageCache.getCreatedImage(EImage.ANNOTATION.getPath());
        } else {
            return ImageCache.getCreatedImage("icons/attribute.gif");//$NON-NLS-1$
        }
    }

    if (obj instanceof XSDAnnotation) {
        return ImageCache.getCreatedImage(EImage.ANNOTATION.getPath());
    }

    if (obj instanceof Element) {
        try {
            Element e = (Element) obj;
            if (e.getLocalName().equals("documentation")) {//$NON-NLS-1$
                return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
            } else if (e.getLocalName().equals("appinfo")) {//$NON-NLS-1$
                String source = e.getAttribute("source");//$NON-NLS-1$
                if (source != null) {
                    if (source.startsWith("X_Label_")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.LABEL.getPath());
                    } else if (source.equals("X_ForeignKey")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.FK_OBJ.getPath());
                    } else if (source.equals("X_Visible_Rule")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.ROUTINE.getPath());
                    } else if (source.equals("X_Default_Value_Rule")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.ROUTINE.getPath());
                    } else if (source.equals("X_ForeignKeyInfo")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
                    } else if (source.equals("X_ForeignKeyInfoFormat")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
                        // fix bug 0013194 by rhou.
                    } else if (source.equals("X_FKIntegrity")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
                    } else if (source.equals("X_FKIntegrity_Override")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
                    } else if (source.equals("X_Retrieve_FKinfos")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
                    } else if (source.equals("X_SourceSystem")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SOURCESYSTEM.getPath());
                    } else if (source.equals("X_TargetSystem")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.TARGETSYSTEM.getPath());
                    } else if (source.startsWith("X_Description_")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
                    } else if (source.equals("X_Write")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Deny_Create")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Deny_LogicalDelete")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Deny_PhysicalDelete")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Lookup_Field")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.BROWSE.getPath());
                    } else if (source.equals("X_Hide")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Schematron")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.ROUTINE.getPath());
                    } else if (source.equals("X_Workflow")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.WORKFLOW_PROCESS.getPath());
                    } else if (source.equals("X_AutoExpand")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.DEFAULT.getPath());
                    }
                    if (source.equals("X_ForeignKey_Filter")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.FILTER_PS.getPath());
                    } else if (source.startsWith("X_Display_Format_")) {//$NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.THIN_MIN_VIEW.getPath());
                    } else {
                        return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
                    }
                } else {
                    return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
                }
            } else {
                return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
            }
        } catch (Exception e) {

            log.error(e.getMessage(), e);
        }
    }

    return ImageCache.getCreatedImage("icons/small_warn.gif");//$NON-NLS-1$
    // return PlatformUI.getWorkbench().getSharedImages().getCreatedImage(ISharedImages.IMG_OBJ_ELEMENT);
}

From source file:eu.europa.ec.markt.dss.validation.xades.XAdESSignature.java

@Override
public byte[] getArchiveTimestampData(int index, Document originalData) throws IOException {

    try {// w  w  w .j av  a2s.  c  om
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();

        XMLStructure s = new DOMStructure(signatureElement);
        XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM", new XMLDSigRI());
        DOMXMLSignature signature = (DOMXMLSignature) factory.unmarshalXMLSignature(s);

        DOMSignContext signContext = new DOMSignContext(new SpecialPrivateKey(), signatureElement);
        signContext.putNamespacePrefix(XMLSignature.XMLNS, "ds");
        signContext.setProperty("javax.xml.crypto.dsig.cacheReference", true);
        signContext.setURIDereferencer(new OneExternalFileURIDereferencer("detached-file", originalData));

        // TODO naramsda: check ! Don't let met publish that without further test !!
        // DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        // dbf.setNamespaceAware(true);
        // org.w3c.dom.Document xmlDoc = dbf.newDocumentBuilder().newDocument();
        // signature.marshal(xmlDoc.createElement("test"), "ds", signContext);

        for (Object o : signature.getSignedInfo().getReferences()) {
            DOMReference r = (DOMReference) o;
            InputStream data = r.getDigestInputStream();
            if (data != null) {
                IOUtils.copy(data, buffer);
            }
        }

        List<Node> timeStampNodesXadesA = new LinkedList<Node>();

        Element signedInfo = XMLUtils.getElement(signatureElement, "./ds:SignedInfo");
        timeStampNodesXadesA.add(signedInfo);

        Element signatureValue = XMLUtils.getElement(signatureElement, "./ds:SignatureValue");
        timeStampNodesXadesA.add(signatureValue);

        Element keyInfo = XMLUtils.getElement(signatureElement, "./ds:KeyInfo");
        timeStampNodesXadesA.add(keyInfo);

        Element unsignedSignaturePropertiesNode = getUnsignedSignatureProperties(signatureElement);

        NodeList unsignedProperties = unsignedSignaturePropertiesNode.getChildNodes();
        int count = 0;
        for (int i = 0; i < unsignedProperties.getLength(); i++) {
            if (unsignedProperties.item(i).getNodeType() == Node.ELEMENT_NODE) {
                Element unsignedProperty = (Element) unsignedProperties.item(i);
                if ("ArchiveTimeStamp".equals(unsignedProperty.getLocalName())) {
                    if (count == index) {
                        LOG.info("We only need data up to ArchiveTimeStamp index " + index);
                        break;
                    }
                    count++;
                }
                timeStampNodesXadesA.add(unsignedProperty);
            }
        }

        buffer.write(getC14nValue(timeStampNodesXadesA));

        return buffer.toByteArray();
        //        } catch (ParserConfigurationException e) {
        //            throw new IOException("Error when computing the archive data", e);
    } catch (MarshalException e) {
        throw new IOException("Error when computing the archive data", e);
    } catch (XPathExpressionException e) {
        throw new EncodingException(MSG.ARCHIVE_TIMESTAMP_DATA_ENCODING);
    }
}

From source file:com.amalto.workbench.providers.XSDTreeLabelProvider.java

@Override
public String getText(Object obj) {

    // log.info("getText   "+obj.getClass().getName());

    if (obj instanceof XSDElementDeclaration) {
        String name = ((XSDElementDeclaration) obj).getName();
        if (((XSDElementDeclaration) obj).isAbstract()) {
            name += Messages.XSDTreeLabelProvider_0;
        }/*w w w  .j a  v  a 2s . com*/
        String tail = ((XSDElementDeclaration) obj).getTargetNamespace() != null ? " : "//$NON-NLS-1$
                + ((XSDElementDeclaration) obj).getTargetNamespace() : "";//$NON-NLS-1$
        return name + tail;
    }

    if (obj instanceof XSDParticle) {
        XSDParticle xsdParticle = (XSDParticle) obj;
        XSDParticleContent content = xsdParticle.getContent();
        XSDTerm xsdTerm = xsdParticle.getTerm();
        String name = "";//$NON-NLS-1$
        if (content instanceof XSDElementDeclaration) {
            XSDElementDeclaration decl = (XSDElementDeclaration) content;
            name += (decl.getName() == null ? "" : decl.getName());//$NON-NLS-1$
            if (decl.getTypeDefinition() == null) {
                name += " [" + ((XSDElementDeclaration) xsdTerm).getName() + "]";//$NON-NLS-1$//$NON-NLS-2$
            }
        } else if (content instanceof XSDModelGroup) {
            // log.info("SHOULD NOT HAPPEN????");
            if (xsdParticle.getContainer() instanceof XSDComplexTypeDefinition) {
                String ctdName = ((XSDComplexTypeDefinition) xsdParticle.getContainer()).getName();
                name = (ctdName != null ? ctdName : "");//$NON-NLS-1$
            }

        } else {
            name = "[Any]";//$NON-NLS-1$
        }
        if (!((xsdParticle.getMinOccurs() == 1) && (xsdParticle.getMaxOccurs() == 1))) {
            name += "  [";//$NON-NLS-1$
            name += xsdParticle.getMinOccurs();
            name += "...";//$NON-NLS-1$
            name += (xsdParticle.getMaxOccurs() == -1) ? "many" : "" + xsdParticle.getMaxOccurs();//$NON-NLS-1$//$NON-NLS-2$
            name += "]";//$NON-NLS-1$
        }
        return name;
    }

    if (obj instanceof XSDSimpleTypeDefinition) {
        return getSimpleTypeDefinition((XSDSimpleTypeDefinition) obj);
    }

    if (obj instanceof XSDModelGroup) {
        // return the name of the complex type definition
        XSDParticle particle = (XSDParticle) (((XSDModelGroup) obj).getContainer());
        XSDComplexTypeDefinition complexTypeDefinition = (XSDComplexTypeDefinition) particle.getContainer();
        String name = complexTypeDefinition.getName();
        if (name == null) {
            name = "anonymous type ";//$NON-NLS-1$
        }
        // return the occurrence
        if (!((particle.getMinOccurs() == 1) && (particle.getMaxOccurs() == 1))) {
            name += "  [";//$NON-NLS-1$
            name += particle.getMinOccurs();
            name += "...";//$NON-NLS-1$
            name += (particle.getMaxOccurs() == -1) ? "many" : "" + particle.getMaxOccurs();//$NON-NLS-1$//$NON-NLS-2$
            name += "]";//$NON-NLS-1$
        }
        // get extend type
        XSDTypeDefinition extendType = complexTypeDefinition.getBaseTypeDefinition();
        String extendTypeName = ""; //$NON-NLS-1$
        if (extendType != null && extendType != complexTypeDefinition
                && !"anyType".equals(extendType.getName())) { //$NON-NLS-1$
            extendTypeName = ":" + extendType.getName(); //$NON-NLS-1$
        }
        XSDSchema schema = particle.getSchema();
        String tail = ""; //$NON-NLS-1$
        if (schema != null && schema.getTargetNamespace() != null) {
            tail = " : "//$NON-NLS-1$
                    + schema.getTargetNamespace();
        }
        return name + tail + extendTypeName;

    }

    if (obj instanceof XSDFacet) {
        return ((XSDFacet) obj).getFacetName() + ": " + ((XSDFacet) obj).getLexicalValue();//$NON-NLS-1$
    }

    if (obj instanceof XSDIdentityConstraintDefinition) {
        return ((XSDIdentityConstraintDefinition) obj).getName();
    }

    if (obj instanceof XSDXPathDefinition) {
        XSDXPathDefinition xpath = (XSDXPathDefinition) obj;
        return xpath.getValue();
    }

    if (obj instanceof XSDAttributeGroupDefinition) {
        XSDAttributeGroupDefinition attributeGroupDefinition = (XSDAttributeGroupDefinition) obj;
        String name = (attributeGroupDefinition.getName() == null ? "" : attributeGroupDefinition.getName());//$NON-NLS-1$
        if (attributeGroupDefinition.getContents().size() == 0) {
            name += " [" + attributeGroupDefinition.getResolvedAttributeGroupDefinition().getName() + "]";//$NON-NLS-1$//$NON-NLS-2$
        }
        return name;
    }

    if (obj instanceof XSDAttributeUse) {
        XSDAttributeUse attributeUse = (XSDAttributeUse) obj;
        String name = attributeUse.getAttributeDeclaration().getName();
        if (name == null) {
            name = " [" + attributeUse.getAttributeDeclaration().getResolvedAttributeDeclaration().getName() //$NON-NLS-1$
                    + "]";//$NON-NLS-1$
        }
        return name;
    }

    if (obj instanceof XSDAttributeDeclaration) {
        XSDAttributeDeclaration attributeDec = (XSDAttributeDeclaration) obj;
        String name = attributeDec.getName();
        if (name == null) {
            name = attributeDec.getAliasName();
            if (name == null) {
                name = " [null]"; //$NON-NLS-1$
            }
        }
        return name;
    }

    if (obj instanceof XSDAnnotation) {
        // XSDAnnotation annotation = (XSDAnnotation) obj;
        return "Annotations";//$NON-NLS-1$
    }

    if (obj instanceof Element) {
        try {
            Element e = (Element) obj;
            if (e.getLocalName().equals("documentation")) {//$NON-NLS-1$
                return "Documentation: " + e.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$
            } else if (e.getLocalName().equals("appinfo")) {//$NON-NLS-1$
                String source = e.getAttribute("source");//$NON-NLS-1$
                if (source != null) {
                    if (source.startsWith("X_Label_")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_1,
                                Util.iso2lang.get(source.substring(8).toLowerCase()),
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_ForeignKey")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_2,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_ForeignKey_NotSep")) {//$NON-NLS-1$
                        Boolean v = Boolean.valueOf(e.getChildNodes().item(0).getNodeValue());
                        return Messages.bind(Messages.XSDTreeLabelProvider_3,
                                Messages.SimpleXpathInputDialog_sepFkTabPanel, v);
                    } else if (source.equals("X_Visible_Rule")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_4,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Default_Value_Rule")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_5,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_ForeignKeyInfo")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_6,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_ForeignKeyInfoFormat")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_20,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_PrimaryKeyInfo")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_7,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_SourceSystem")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_8,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_TargetSystem")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_9,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.startsWith("X_Description_")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_10,
                                Util.iso2lang.get(source.substring(14).toLowerCase()),
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Write")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_11,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Deny_Create")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_12,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Deny_LogicalDelete")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_13,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Deny_PhysicalDelete")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_14,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Lookup_Field")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_15,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Workflow")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_16,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Hide")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_17,
                                e.getChildNodes().item(0).getNodeValue());
                        // add by ymli; bugId 0009157
                    } else if (source.equals("X_AutoExpand")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_18,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.startsWith("X_Facet")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_19, source.substring(2, 7),
                                source.substring(8), e.getChildNodes().item(0).getNodeValue());
                        // made schematron show:Schematron: schematron
                    } else if (source.startsWith("X_Display_Format_")) {//$NON-NLS-1$
                        return source + ": " + e.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$
                    } else if (source.equals("X_Schematron")) {//$NON-NLS-1$

                        String pattern = (String) e.getFirstChild().getUserData("pattern_name");//$NON-NLS-1$
                        if (pattern == null) {
                            Element el = Util.parse(e.getChildNodes().item(0).getNodeValue())
                                    .getDocumentElement();
                            if (el.getAttributes().getNamedItem("name") != null) { //$NON-NLS-1$
                                pattern = el.getAttributes().getNamedItem("name").getTextContent();//$NON-NLS-1$
                            }
                        }
                        return Messages.bind(Messages.XSDTreeLabelProvider_21,
                                (pattern == null ? Messages.XSDTreeLabelProvider_22 : pattern));// e.getChildNodes().item(0).getNodeValue();
                        // end
                    } else if (source.equals("X_Retrieve_FKinfos")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_23,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_FKIntegrity")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_24,
                                e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_FKIntegrity_Override")) {//$NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_25,
                                e.getChildNodes().item(0).getNodeValue());
                    }

                    if (source.equals("X_ForeignKey_Filter")) {//$NON-NLS-1$
                        String nodeValue = e.getChildNodes().item(0).getNodeValue();
                        if (nodeValue.startsWith("$CFFP:")) {//$NON-NLS-1$
                            nodeValue = StringEscapeUtils.unescapeXml(nodeValue).substring(6);
                        }
                        return Messages.bind(Messages.XSDTreeLabelProvider_26, nodeValue);
                    } else {
                        return source + ": " + Util.nodeToString((Element) obj);//$NON-NLS-1$
                    }
                } else {
                    return Util.nodeToString((Element) obj);
                }
            } else {
                return Util.nodeToString((Element) obj);
            }
        } catch (Exception e) {

            log.error(e.getMessage(), e);
        }
    }

    if (obj == null) {
        return "NULL";//$NON-NLS-1$
    }
    return "?? " + obj.getClass().getName() + " : " + obj.toString();//$NON-NLS-1$//$NON-NLS-2$

}

From source file:org.brekka.stillingar.spring.config.ConfigurationServiceBeanDefinitionParser.java

/**
 * @param element//  ww  w. jav  a2s .  c o m
 * @return
 */
protected ManagedList<Object> prepareBaseDirectoryList(Element element) {
    ManagedList<Object> list = new ManagedList<Object>();
    Element locationElement = selectSingleChildElement(element, "location", true);
    if (locationElement != null) {
        List<Element> selectChildElements = selectChildElements(locationElement, "*");
        for (Element location : selectChildElements) {
            String tag = location.getLocalName();
            if ("environment-variable".equals(tag)) {
                list.add(prepareLocation(location.getTextContent(), EnvironmentVariableDirectory.class));
            } else if ("system-property".equals(tag)) {
                list.add(prepareLocation(location.getTextContent(), SystemPropertyDirectory.class));
            } else if ("home".equals(tag)) {
                list.add(prepareHomeLocation(element, location.getAttribute("path")));
            } else if ("platform".equals(tag)) {
                list.add(preparePlatformLocation(location.getTextContent()));
            } else if ("webapp".equals(tag)) {
                list.add(prepareWebappLocation(element, location.getAttribute("path")));
            } else if ("resource".equals(tag)) {
                list.add(prepareResourceLocation(element, location.getAttribute("location")));
            } else {
                throw new IllegalArgumentException(String.format("Unknown location type '%s'", tag));
            }
        }
    } else {
        list.add(prepareHomeLocation(element, null));
        PlatformDirectory[] values = PlatformDirectory.values();
        for (PlatformDirectory platformDirectory : values) {
            list.add(platformDirectory);
        }
        // home, webapp (if available) and platforms
        if (ClassUtils.isPresent("org.springframework.web.context.WebApplicationContext",
                this.getClass().getClassLoader())) {
            list.add(prepareWebappLocation(element, null));
        }
    }
    return list;
}

From source file:gov.nij.bundles.intermediaries.ers.EntityResolutionMessageHandler.java

/**
 * This method takes the ER response and converts the Java objects to the Merge Response XML.
 * /*from   w ww .j a v a 2  s  .co m*/
 * @param entityContainerNode
 * @param results
 * @param recordLimit
 * @param attributeParametersNode
 * @return
 * @throws ParserConfigurationException
 * @throws XPathExpressionException
 * @throws TransformerException
 */
private Document createResponseMessage(Node entityContainerNode, EntityResolutionResults results,
        Node attributeParametersNode, int recordLimit) throws Exception {

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);

    Document resultDocument = dbf.newDocumentBuilder().newDocument();

    Element entityMergeResultMessageElement = resultDocument.createElementNS(
            EntityResolutionNamespaceContext.MERGE_RESULT_NAMESPACE, "EntityMergeResultMessage");
    resultDocument.appendChild(entityMergeResultMessageElement);

    Element entityContainerElement = resultDocument
            .createElementNS(EntityResolutionNamespaceContext.MERGE_RESULT_NAMESPACE, "EntityContainer");
    entityMergeResultMessageElement.appendChild(entityContainerElement);

    NodeList inputEntityNodes = (NodeList) xpath.evaluate("er-ext:Entity", entityContainerNode,
            XPathConstants.NODESET);
    Collection<Element> inputEntityElements = null;
    if (attributeParametersNode == null) {
        inputEntityElements = new ArrayList<Element>();
    } else {
        inputEntityElements = TreeMultiset
                .create(new EntityElementComparator((Element) attributeParametersNode));
        //inputEntityElements = new ArrayList<Element>();
    }

    for (int i = 0; i < inputEntityNodes.getLength(); i++) {
        inputEntityElements.add((Element) inputEntityNodes.item(i));
    }

    if (attributeParametersNode == null) {
        LOG.warn("Attribute Parameters element was null, so records will not be sorted");
    }
    //Collections.sort((List<Element>) inputEntityElements, new EntityElementComparator((Element) attributeParametersNode));

    if (inputEntityElements.size() != inputEntityNodes.getLength()) {
        LOG.error("Lost elements in ER output sorting.  Input count=" + inputEntityNodes.getLength()
                + ", output count=" + inputEntityElements.size());
    }

    for (Element e : inputEntityElements) {
        Node clone = resultDocument.adoptNode(e.cloneNode(true));
        resultDocument.renameNode(clone, EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE,
                e.getLocalName());
        entityContainerElement.appendChild(clone);
    }

    Element mergedRecordsElement = resultDocument
            .createElementNS(EntityResolutionNamespaceContext.MERGE_RESULT_NAMESPACE, "MergedRecords");
    entityMergeResultMessageElement.appendChild(mergedRecordsElement);

    if (results != null) {

        List<RecordWrapper> records = results.getRecords();

        // Loop through RecordWrappers to extract info to create merged records
        for (RecordWrapper record : records) {
            LOG.debug("  !#!#!#!# Record 1, id=" + record.getExternalId() + ", externals="
                    + record.getRelatedIds());

            // Create Merged Record Container
            Element mergedRecordElement = resultDocument.createElementNS(
                    EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "MergedRecord");
            mergedRecordsElement.appendChild(mergedRecordElement);

            // Create Original Record Reference for 'first record'
            Element originalRecordRefElement = resultDocument.createElementNS(
                    EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "OriginalRecordReference");
            originalRecordRefElement.setAttributeNS(EntityResolutionNamespaceContext.STRUCTURES_NAMESPACE,
                    "ref", record.getExternalId());
            mergedRecordElement.appendChild(originalRecordRefElement);

            // Loop through and add any related records
            for (String relatedRecordId : record.getRelatedIds()) {
                originalRecordRefElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "OriginalRecordReference");
                originalRecordRefElement.setAttributeNS(EntityResolutionNamespaceContext.STRUCTURES_NAMESPACE,
                        "ref", relatedRecordId);
                mergedRecordElement.appendChild(originalRecordRefElement);
            }

            // Create Merge Quality Element
            Element mergeQualityElement = resultDocument.createElementNS(
                    EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "MergeQuality");
            mergedRecordElement.appendChild(mergeQualityElement);
            Set<AttributeStatistics> stats = results.getStatisticsForRecord(record.getExternalId());
            for (AttributeStatistics stat : stats) {
                Element stringDistanceStatsElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE,
                        "StringDistanceStatistics");
                mergeQualityElement.appendChild(stringDistanceStatsElement);
                Element xpathElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "AttributeXPath");
                stringDistanceStatsElement.appendChild(xpathElement);
                Node contentNode = resultDocument.createTextNode(stat.getAttributeName());
                xpathElement.appendChild(contentNode);
                Element meanElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE,
                        "StringDistanceMeanInRecord");
                stringDistanceStatsElement.appendChild(meanElement);
                contentNode = resultDocument.createTextNode(String.valueOf(stat.getAverageStringDistance()));
                meanElement.appendChild(contentNode);
                Element sdElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE,
                        "StringDistanceStandardDeviationInRecord");
                stringDistanceStatsElement.appendChild(sdElement);
                contentNode = resultDocument
                        .createTextNode(String.valueOf(stat.getStandardDeviationStringDistance()));
                sdElement.appendChild(contentNode);

            }
        }

    } else {

        for (Element e : inputEntityElements) {

            String id = e.getAttributeNS(EntityResolutionNamespaceContext.STRUCTURES_NAMESPACE, "id");

            Element mergedRecordElement = resultDocument.createElementNS(
                    EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "MergedRecord");
            mergedRecordsElement.appendChild(mergedRecordElement);

            Element originalRecordRefElement = resultDocument.createElementNS(
                    EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "OriginalRecordReference");
            originalRecordRefElement.setAttributeNS(EntityResolutionNamespaceContext.STRUCTURES_NAMESPACE,
                    "ref", id);
            mergedRecordElement.appendChild(originalRecordRefElement);

            Element mergeQualityElement = resultDocument.createElementNS(
                    EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "MergeQuality");
            mergedRecordElement.appendChild(mergeQualityElement);
            XPath xp = XPathFactory.newInstance().newXPath();
            xp.setNamespaceContext(new EntityResolutionNamespaceContext());
            NodeList attributeParameterNodes = (NodeList) xp.evaluate("er-ext:AttributeParameter",
                    attributeParametersNode, XPathConstants.NODESET);
            for (int i = 0; i < attributeParameterNodes.getLength(); i++) {
                String attributeName = xp.evaluate("er-ext:AttributeXPath", attributeParametersNode);
                Element stringDistanceStatsElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE,
                        "StringDistanceStatistics");
                mergeQualityElement.appendChild(stringDistanceStatsElement);
                Element xpathElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "AttributeXPath");
                stringDistanceStatsElement.appendChild(xpathElement);
                Node contentNode = resultDocument.createTextNode(attributeName);
                xpathElement.appendChild(contentNode);
                Element meanElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE,
                        "StringDistanceMeanInRecord");
                stringDistanceStatsElement.appendChild(meanElement);
                contentNode = resultDocument.createTextNode("0.0");
                meanElement.appendChild(contentNode);
                Element sdElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE,
                        "StringDistanceStandardDeviationInRecord");
                stringDistanceStatsElement.appendChild(sdElement);
                contentNode = resultDocument.createTextNode("0.0");
                sdElement.appendChild(contentNode);
            }

        }

    }

    Element recordLimitExceededElement = resultDocument.createElementNS(
            EntityResolutionNamespaceContext.MERGE_RESULT_NAMESPACE, "RecordLimitExceededIndicator");
    recordLimitExceededElement.setTextContent(new Boolean(results == null).toString());
    entityMergeResultMessageElement.appendChild(recordLimitExceededElement);

    return resultDocument;

}

From source file:de.interactive_instruments.ShapeChange.Target.ReplicationSchema.ReplicationXmlSchema.java

/**
 * Process a class property./* w  w w .java2 s.  c  om*/
 *
 * @param pi
 *            property to process
 * @param sequenceOrChoice
 *            element to which the property element shall be appended
 * @return
 */
public void processLocalProperty(PropertyInfo pi, Element sequenceOrChoice) {

    if (includeProperty(pi)) {

        Element piElement = addProperty(pi);

        if (piElement.getLocalName().equals("attribute") || piElement.getLocalName().equals("attributeGroup")) {

            sequenceOrChoice.getParentNode().appendChild(piElement);

        } else {

            sequenceOrChoice.appendChild(piElement);
        }
    }
}

From source file:de.betterform.xml.xforms.Container.java

private void addModelElements(Node parent, List<Element> models) {
    for (Node it = parent.getFirstChild(); it != null; it = it.getNextSibling()) {
        if (it.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }//from  w  w  w . j  a  v a 2 s .co m

        if (NamespaceConstants.XFORMS_NS.equals(it.getNamespaceURI())) {
            Element el = (Element) it;
            if (XFormsConstants.MODEL.equals(el.getLocalName())) {
                models.add(el);
            }
            // Model is a top level XForms element so we don't need to go in recursion here
            else {
                addModelElements(it, models);
            }
        } else {
            addModelElements(it, models);
        }
    }
}