Package org.jdom

Examples of org.jdom.Attribute


    }

    private static final class NamedAttributeOp implements NamedNodeOperator {
        public List operate(Object node, String localName, Namespace namespace)
        {
            Attribute attr = null;
            if (node instanceof Element) {
                Element element = (Element)node;
                attr = element.getAttribute(localName, namespace);
            } else if (node instanceof ProcessingInstruction) {
                ProcessingInstruction pi = (ProcessingInstruction)node;
                if ("target".equals(localName))
                    attr = new Attribute("target", pi.getTarget());
                else if ("data".equals(localName))
                    attr = new Attribute("data", pi.getData());
                else
                    attr = new Attribute(localName, pi.getValue(localName));
            } else if (node instanceof DocType) {
                DocType doctype = (DocType)node;
                if ("publicId".equals(localName))
                    attr = new Attribute("publicId", doctype.getPublicID());
                else if ("systemId".equals(localName))
                    attr = new Attribute("systemId", doctype.getSystemID());
                else if ("elementName".equals(localName))
                    attr = new Attribute("elementName", doctype.getElementName());
            }
            // With 2.1 semantics it  makes more sense to just return a null and let the core
            // throw an InvalidReferenceException and the template writer can use ?exists etcetera. (JR)
            else {
                return null;
View Full Code Here


                Element element = (Element)node;
                return Collections12.singletonList(element.getNamespace().getURI() + element.getName());
            }
            else if (node instanceof Attribute)
            {
                Attribute attribute = (Attribute)node;
                return Collections12.singletonList(attribute.getNamespace().getURI() + attribute.getName());
            }
            // With 2.1 semantics it  makes more sense to just return a null and let the core
            // throw an InvalidReferenceException and the template writer can use ?exists etcetera. (JR)
            return null;
//            throw new TemplateModelException("_cname can not be applied on " + node.getClass());
View Full Code Here

   
    private void escape(Element e) {
      List listOfAtrributes = e.getAttributes();
      for(int i = 0; i< listOfAtrributes.size(); i++) {
        //System.out.println(listOfAtrributes.get(i));
        Attribute attr = (Attribute)listOfAtrributes.get(i);
        //System.out.println("name  : " + attr.getName());
        //System.out.println("value : " + attr.getValue());       
        //Utils.setAttribute(attr.getName(), Utils.escape(attr.getValue()), e);
       
        //ok e.setAttribute(attr.getName(), Utils.escape(attr.getValue()));
        Attribute a = new Attribute(attr.getName(), Utils.escape(attr.getValue()), attr.getAttributeType(), attr.getNamespace());
        e.setAttribute(a);
        //e.setAttribute(attr.getName(), Utils.escape(attr.getValue()));
        //System.out.println("neue value  : " + e.getAttributeValue(attr.getName()));
       
        //System.out.println("*************************************");
 
View Full Code Here

   
    private void deEscape(Element e) {
      List listOfAtrributes = e.getAttributes();
      for(int i = 0; i< listOfAtrributes.size(); i++) {
        //System.out.println(listOfAtrributes.get(i));
        Attribute attr = (Attribute)listOfAtrributes.get(i);
        //System.out.println("name  : " + attr.getName());
        //System.out.println("value : " + attr.getValue());
        /*String newValue = attr.getValue();
        newValue = newValue.replaceAll("&quot;", "\"");
        newValue = newValue.replaceAll("&lt;", "<");
        newValue = newValue.replaceAll("&gt;", ">");
        newValue = newValue.replaceAll("&amp;", "&");
        */
        //Utils.setAttribute(attr.getName(), Utils.deEscape(attr.getValue()), e);
       
        //ok e.setAttribute(attr.getName(), Utils.deEscape(attr.getValue()));
       
        Attribute a = new Attribute(attr.getName(), Utils.deEscape(attr.getValue()), attr.getAttributeType(), attr.getNamespace());
        e.setAttribute(a);
       
        //System.out.println("neue value  : " + newValue);
       
        //System.out.println("*************************************");
 
View Full Code Here

     */
    @Override
    public void writeSchema(Element root) {
        BeanTypeInfo inf = getTypeInfo();
        Element complex = new Element("complexType", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
        complex.setAttribute(new Attribute("name", getSchemaType().getLocalPart()));
        root.addContent(complex);

        Type sooperType = getSuperType();

        /*
         * See Java Virtual Machine specification:
         * http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75734
         */
        if (((inf.getTypeClass().getModifiers() & Modifier.ABSTRACT) != 0)
            && !inf.getTypeClass().isInterface()) {
            complex.setAttribute(new Attribute("abstract", "true"));
        }

        if (inf.isExtension() && sooperType != null) {
            Element complexContent = new Element("complexContent",
                                                 SOAPConstants.XSD_PREFIX,
                                                 SOAPConstants.XSD);
            complex.addContent(complexContent);
            complex = complexContent;
        }

        /*
         * Decide if we're going to extend another type. If we are going to
         * defer, then make sure that we extend the type for our superclass.
         */
        boolean isExtension = inf.isExtension();

        Element dummy = complex;

        if (isExtension && sooperType != null) {

            Element extension = new Element("extension", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
            complex.addContent(extension);
            QName baseType = sooperType.getSchemaType();
            extension.setAttribute(new Attribute("base", getNameWithPrefix2(root, baseType
                .getNamespaceURI(), baseType.getLocalPart())));

            dummy = extension;
        }

        Element seq = null;
        boolean needXmime = false;
        boolean needUtilityTypes = false;
       
        // Write out schema for elements
        for (Iterator itr = inf.getElements(); itr.hasNext();) {

            QName name = (QName)itr.next();

            if (isExtension) {
                PropertyDescriptor pd = inf.getPropertyDescriptorFromMappedName(name);

                assert pd.getReadMethod() != null && pd.getWriteMethod() != null;
                if (pd.getReadMethod().getDeclaringClass() != inf.getTypeClass()) {
                    continue;
                }
            }

            if (seq == null) {
                seq = new Element("sequence", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
                dummy.addContent(seq);
            }

            Element element = new Element("element", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
            seq.addContent(element);

            Type type = getType(inf, name);

            String nameNS = name.getNamespaceURI();
            String nameWithPrefix = getNameWithPrefix(root, nameNS, name.getLocalPart());

            String prefix = NamespaceHelper.getUniquePrefix(root, type.getSchemaType().getNamespaceURI());

            writeTypeReference(name, nameWithPrefix, element, type, prefix, root);
            needXmime |= type.usesXmime();
            needUtilityTypes |= type.usesUtilityTypes();
        }
       
        if (needXmime) {
            addXmimeToSchema(root);
        }
       
        if (needUtilityTypes) {
            AegisContext.addUtilityTypesToSchema(root);
        }

        /**
         * if future proof then add <xsd:any/> element
         */
        if (inf.isExtensibleElements()) {
            if (seq == null) {
                seq = new Element("sequence", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
                dummy.addContent(seq);
            }
            seq.addContent(createAnyElement());
        }

        // Write out schema for attributes
        for (Iterator itr = inf.getAttributes(); itr.hasNext();) {
            QName name = (QName)itr.next();

            Element element = new Element("attribute", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
            dummy.addContent(element);

            Type type = getType(inf, name);

            String nameNS = name.getNamespaceURI();
            String nameWithPrefix = getNameWithPrefix(root, nameNS, name.getLocalPart());

            String prefix = NamespaceHelper.getUniquePrefix(root, type.getSchemaType().getNamespaceURI());
            element.setAttribute(new Attribute("name", nameWithPrefix));
            element.setAttribute(TypeUtil.createTypeAttribute(prefix, type, root));
        }

        /**
         * If extensible attributes then add <xsd:anyAttribute/>
View Full Code Here

    private void writeTypeReference(QName name, String nameWithPrefix,
                                    Element element, Type type, String prefix,
                                    Element root) {
        if (type.isAbstract()) {
            element.setAttribute(new Attribute("name", nameWithPrefix));
            element.setAttribute(TypeUtil.createTypeAttribute(prefix, type, root));

            int minOccurs = getTypeInfo().getMinOccurs(name);
            if (minOccurs == 0) {
                element.setAttribute(new Attribute("minOccurs", Integer.valueOf(minOccurs).toString()));
            }

            if (getTypeInfo().isNillable(name)) {
                element.setAttribute(new Attribute("nillable", "true"));
            }
        } else {
            element.setAttribute(new Attribute("ref", prefix + ':' + type.getSchemaType().getLocalPart()));
        }
    }
View Full Code Here

     *
     * @return
     */
    private Element createAnyElement() {
        Element result = new Element("any", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
        result.setAttribute(new Attribute("minOccurs", "0"));
        result.setAttribute(new Attribute("maxOccurs", "unbounded"));
        return result;
    }
View Full Code Here

            String lname = name.getName();
            if (!lname.equals("*")) {
                attributes = new ArrayList();
                if (ns != null) {
                    Attribute attr = element.getAttribute(lname, ns);
//  System.err.println("LNAME=" + lname + "  NS: " + ns + " ATTR: " + attr);
                    if (attr != null) {
                        attributes.add(attr);
                    }
                }
            }
            else {
                attributes = new ArrayList();
                List allAttributes = element.getAttributes();
                for (int i = 0; i < allAttributes.size(); i++) {
                    Attribute attr = (Attribute) allAttributes.get(i);
                    if (attr.getNamespace().equals(ns)) {
                        attributes.add(attr);
                    }
                }
            }
        }
View Full Code Here

            Namespace ns = element.getNamespace(prefix);
            if (ns == null) {
                throw new JXPathException(
                    "Unknown namespace prefix: " + prefix);
            }
            Attribute attr = element.getAttribute(name.getName(), ns);
            if (attr == null) {
                element.setAttribute(name.getName(), "", ns);
            }
        }
        else {
            Attribute attr = element.getAttribute(name.getName());
            if (attr == null) {
                element.setAttribute(name.getName(), "");
            }
        }
        NodeIterator it = attributeIterator(name);
View Full Code Here

  private Attribute nodeToAttribute(IConstructor n) {
    IConstructor ns = (IConstructor) n.get(0);
    IString name = (IString) n.get(1);
    IString data = (IString) n.get(2);
    return new Attribute(name.getValue(), data.getValue(), namespaceToNamespace(ns));
  }
View Full Code Here

TOP

Related Classes of org.jdom.Attribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.