Package br.net.woodstock.rockframework.core.xml.dom

Examples of br.net.woodstock.rockframework.core.xml.dom.XmlElement


  @Override
  public void read(final InputStream inputStream, final String password) throws IOException {
    try {
      XmlDocument document = XmlDocument.read(inputStream);
      XmlElement root = document.getRoot();

      String encoding = root.getAttribute(XMLStore.ENCODING_ATTRIBUTE);

      XmlElement certificates = root.getElement(XMLStore.CERTIFICATES_ELEMENT);
      XmlElement privateKeys = root.getElement(XMLStore.PRIVATE_KEYS_ELEMENT);
      XmlElement publicKeys = root.getElement(XMLStore.PUBLIC_KEYS_ELEMENT);
      XmlElement secretKeys = root.getElement(XMLStore.SECRET_KEYS_ELEMENT);

      for (XmlElement certificateElement : certificates.getElements()) {
        String alias = certificateElement.getAttribute(XMLStore.ALIAS_ATTRIBUTE);
        Certificate certificate = this.getCertificate(certificateElement, encoding);
        this.getCertificateMap().put(alias, certificate);
      }

      for (XmlElement privateKeyElement : privateKeys.getElements()) {
        String alias = privateKeyElement.getAttribute(XMLStore.ALIAS_ATTRIBUTE);
        Identity holder = this.getPrivateKey(privateKeyElement, encoding);
        this.getPrivateKeyMap().put(alias, holder);
      }

      for (XmlElement publicKeyElement : publicKeys.getElements()) {
        String alias = publicKeyElement.getAttribute(XMLStore.ALIAS_ATTRIBUTE);
        PublicKey publicKey = this.getPublicKey(publicKeyElement, encoding);
        this.getPublicKeyMap().put(alias, publicKey);
      }

      for (XmlElement secretKeyElement : secretKeys.getElements()) {
        String alias = secretKeyElement.getAttribute(XMLStore.ALIAS_ATTRIBUTE);
        SecretKey secretKey = this.getSecretKey(secretKeyElement, encoding);
        this.getSecretKeyMap().put(alias, secretKey);
      }
    } catch (GeneralSecurityException e) {
View Full Code Here


  @Override
  public void write(final OutputStream outputStream, final String password) throws IOException {
    try {
      XmlDocument document = new XmlDocument(XMLStore.STORE_ELEMENT);

      XmlElement root = document.getRoot();
      root.setAttribute(XMLStore.ENCODING_ATTRIBUTE, XMLStore.ENCODING);

      XmlElement certificates = root.addElement(XMLStore.CERTIFICATES_ELEMENT);
      XmlElement privateKeys = root.addElement(XMLStore.PRIVATE_KEYS_ELEMENT);
      XmlElement publicKeys = root.addElement(XMLStore.PUBLIC_KEYS_ELEMENT);
      XmlElement secretKeys = root.addElement(XMLStore.SECRET_KEYS_ELEMENT);
      for (Entry<String, Certificate> entry : this.getCertificateMap().entrySet()) {
        String alias = entry.getKey();
        Certificate certificate = entry.getValue();
        this.addCertificateElement(certificates, alias, certificate);
      }
View Full Code Here

    PrivateKey privateKey = Keys.getPrivateKeyFromPKCS8File(data, KeyPairType.getKeyPairType(algorithm));

    List<Certificate> chainList = new ArrayList<Certificate>();
    Certificate[] chain = null;
    XmlElement chainElement = e.getElement(XMLStore.CHAIN_ELEMENT);
    for (XmlElement certificateElement : chainElement.getElements()) {
      Certificate certificate = this.getCertificate(certificateElement, encoding);
      chainList.add(certificate);
    }

    if (chainList.size() > 0) {
View Full Code Here

    SecretKey secretKey = Keys.getSecretKeyFromFile(data, KeyType.getKeyType(algorithm));
    return secretKey;
  }

  private void addCertificateElement(final XmlElement parent, final String alias, final Certificate certificate) throws CertificateEncodingException, UnsupportedEncodingException {
    XmlElement certificateElement = parent.addElement(XMLStore.CERTIFICATE_ELEMENT);
    certificateElement.setAttribute(XMLStore.ALIAS_ATTRIBUTE, alias);
    certificateElement.setAttribute(XMLStore.ALGORITHM_ATTRIBUTE, certificate.getType());

    this.setBase64Data(certificateElement, certificate.getEncoded());
  }
View Full Code Here

  }

  private void addPrivateKeyElement(final XmlElement parent, final String alias, final Identity identity) throws CertificateEncodingException, UnsupportedEncodingException {
    PrivateKey privateKey = identity.getPrivateKey();
    Certificate[] chain = identity.getChain();
    XmlElement privateKeyElement = parent.addElement(XMLStore.PRIVATE_KEY_ELEMENT);
    XmlElement chainElement = privateKeyElement.addElement(XMLStore.CHAIN_ELEMENT);
    privateKeyElement.setAttribute(XMLStore.ALIAS_ATTRIBUTE, alias);
    privateKeyElement.setAttribute(XMLStore.ALGORITHM_ATTRIBUTE, privateKey.getAlgorithm());

    this.setBase64Data(privateKeyElement, privateKey.getEncoded());
View Full Code Here

      }
    }
  }

  private void addPublicKeyElement(final XmlElement parent, final String alias, final PublicKey publicKey) throws UnsupportedEncodingException {
    XmlElement publicKeyElement = parent.addElement(XMLStore.PUBLIC_KEY_ELEMENT);
    publicKeyElement.setAttribute(XMLStore.ALIAS_ATTRIBUTE, alias);
    publicKeyElement.setAttribute(XMLStore.ALGORITHM_ATTRIBUTE, publicKey.getAlgorithm());

    this.setBase64Data(publicKeyElement, publicKey.getEncoded());
  }
View Full Code Here

    this.setBase64Data(publicKeyElement, publicKey.getEncoded());
  }

  private void addSecretKeyElement(final XmlElement parent, final String alias, final SecretKey secretKey) throws UnsupportedEncodingException {
    XmlElement publicKeyElement = parent.addElement(XMLStore.SECRET_KEY_ELEMENT);
    publicKeyElement.setAttribute(XMLStore.ALIAS_ATTRIBUTE, alias);
    publicKeyElement.setAttribute(XMLStore.ALGORITHM_ATTRIBUTE, secretKey.getAlgorithm());

    this.setBase64Data(publicKeyElement, secretKey.getEncoded());
  }
View Full Code Here

    }

    Tag tag = clazz.getAnnotation(Tag.class);

    XmlDocument document = new XmlDocument("tag");
    XmlElement root = document.getRoot();

    if (Conditions.isNotEmpty(tag.description())) {
      root.addElement("description").setData(tag.description());
    }

    root.addElement("name").setData(tag.name());
    root.addElement("tag-class").setData(clazz.getCanonicalName());
    root.addElement("body-content").setData(tag.content());

    if (tag.dynamicAttributes()) {
      root.addElement("dynamic-attributes").setData(Boolean.valueOf(tag.dynamicAttributes()));
    }

    BeanDescriptor beanDescriptor = new BeanDescriptorBuilder(clazz).getBeanDescriptor();

    for (PropertyDescriptor propertyDescriptor : beanDescriptor.getProperties()) {
      if (!propertyDescriptor.isAnnotationPresent(Attribute.class)) {
        continue;
      }

      Attribute tldAttribute = propertyDescriptor.getAnnotation(Attribute.class);
      XmlElement e = root.addElement("attribute");

      if (Conditions.isNotEmpty(tldAttribute.description())) {
        e.addElement("description").setData(tldAttribute.description());
      }

      e.addElement("name").setData(propertyDescriptor.getName());
      e.addElement("required").setData(Boolean.valueOf(tldAttribute.required()));
      e.addElement("rtexprvalue").setData(Boolean.valueOf(tldAttribute.rtexprvalue()));
      if ((!tldAttribute.rtexprvalue()) && (tldAttribute.type() != String.class)) {
        e.addElement("type").setData(tldAttribute.type().getCanonicalName());
      }
    }

    return document.toString();
  }
View Full Code Here

  public XmlDocument toXML(final String baseName) {
    Assert.notEmpty(baseName, "baseName");
    ClassFinder classFinder = new ClassFinderImpl(baseName, new AnnotationClassFilter(Entity.class));
    XmlDocument document = new XmlDocument(AnnotationToXML.XML_NAMESPACE, AnnotationToXML.XML_LOCATION, AnnotationToXML.XML_ROOT);
    XmlElement entityMappings = document.getRoot();

    for (Class<?> clazz : classFinder.getClasses()) {
      XmlElement entity = entityMappings.addElement("entity");
      entity.setAttribute("class", clazz.getCanonicalName());
      entity.setAttribute("access", "PROPERTY");
      entity.setAttribute("metadata-complete", "true");

      BeanDescriptor beanDescriptor = new BeanDescriptorBuilder(clazz).getBeanDescriptor();
      Entity e = beanDescriptor.getAnnotation(Entity.class);
      if (Conditions.isNotEmpty(e.name())) {
        entity.setAttribute("name", e.name());
      }

      Table t = beanDescriptor.getAnnotation(Table.class);
      if (t != null) {
        XmlElement table = entity.addElement("table");
        table.setAttribute("name", t.name());
        if (Conditions.isNotEmpty(t.schema())) {
          table.setAttribute("schema", t.schema());
        }
      }

      XmlElement attributes = entity.addElement("attributes");

      for (PropertyDescriptor propertyDescriptor : beanDescriptor.getProperties()) {
        if (propertyDescriptor.isAnnotationPresent(ManyToMany.class)) {
          ManyToMany mm = propertyDescriptor.getAnnotation(ManyToMany.class);
          this.addManyToMany(attributes, propertyDescriptor, mm);
        } else if (propertyDescriptor.isAnnotationPresent(ManyToOne.class)) {
          ManyToOne mo = propertyDescriptor.getAnnotation(ManyToOne.class);
          this.addManyToOne(attributes, propertyDescriptor, mo);
        } else if (propertyDescriptor.isAnnotationPresent(OneToMany.class)) {
          OneToMany om = propertyDescriptor.getAnnotation(OneToMany.class);
          this.addOneToMany(attributes, propertyDescriptor, om);
        } else if (propertyDescriptor.isAnnotationPresent(OneToOne.class)) {
          OneToOne oo = propertyDescriptor.getAnnotation(OneToOne.class);
          this.addOneToOne(attributes, propertyDescriptor, oo);
        } else if (propertyDescriptor.isAnnotationPresent(Basic.class)) {
          Basic b = propertyDescriptor.getAnnotation(Basic.class);
          this.addBasic(attributes, propertyDescriptor, b);
        } else if (propertyDescriptor.isAnnotationPresent(Id.class)) {
          this.addId(attributes, propertyDescriptor);
        } else if (propertyDescriptor.isAnnotationPresent(Column.class)) {
          Column c = propertyDescriptor.getAnnotation(Column.class);
          this.addBasic(attributes, propertyDescriptor, c);
        } else if (propertyDescriptor.isAnnotationPresent(Transient.class)) {
          this.addTransient(attributes, propertyDescriptor);
        } else {
          attributes.addComment("Field " + propertyDescriptor.getName() + " not correctly mapped");
        }
      }
    }

    return document;
View Full Code Here

    return document;
  }

  private XmlElement addManyToMany(final XmlElement parent, final PropertyDescriptor propertyDescriptor, final ManyToMany manyToMany) {
    XmlElement element = parent.addElement("many-to-many");
    element.setAttribute("name", propertyDescriptor.getName());
    element.setAttribute("fetch", manyToMany.fetch().name());
    element.setAttribute("mappedBy", manyToMany.mappedBy());

    this.addCascades(element, manyToMany.cascade());

    if (propertyDescriptor.isAnnotationPresent(JoinTable.class)) {
      JoinTable jt = propertyDescriptor.getAnnotation(JoinTable.class);
View Full Code Here

TOP

Related Classes of br.net.woodstock.rockframework.core.xml.dom.XmlElement

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.