XML Processor to validate AUD_JMS Blob file

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package com.massiveGaze.DOMSource;

import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.StringReader;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import oracle.iam.platform.OIMClient;

import org.w3c.dom.Document;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import com.massiveGaze.connection.DataSource;
import com.thortech.xl.audit.engine.AuditMessage;

public class XMLProcessorToValidateAUD_JMSBlobFile {

 protected static OIMClient platform = null;

 // Transformer transformer = factory.newTransformer();
 // transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");

 public static String getStringValue(Document document)
   throws TransformerException {

  CharArrayWriter writer = new CharArrayWriter();
  StreamResult result = new StreamResult(writer);
  TransformerFactory factory = TransformerFactory.newInstance();
  Transformer transformer = factory.newTransformer();
  transformer.setOutputProperty("encoding", "UTF-8");

   DOMImplementationLS lsImpl = (DOMImplementationLS)document.getDocumentElement().getOwnerDocument().getImplementation().getFeature("LS", "3.0");
  LSSerializer serializer = lsImpl.createLSSerializer();
  serializer.getDomConfig().setParameter("xml-declaration", Boolean.valueOf(true));
      System.out.println(" Will Exception Occurs During  new DOMSource Object  ? ");
      new DOMSource(document.getDocumentElement());
       System.out.println(" No Exception Occurs During  new DOMSource Object  ? ");
       String str = serializer.writeToString(document.getDocumentElement());
       System.out.println(" After Setting reason getDocumentElement STRIGN XML IS *****->" + str);
      System.out.println(" Will Exception Occurs During Transform Object  ?");
      transformer.transform(new DOMSource(document.getDocumentElement()), result);
       System.out.println(" No Exception Occurs After Transform Object..");
      System.out.println("Writer Object -> \n \n" + new String(writer.toCharArray()).toString());
      System.out.println(" Returning From getStringValue() method, Class: XMLProcessor");
       return new String(writer.toCharArray());  

 }

 public static void main(String args[]) throws TransformerException,
   SQLException, IOException, ClassNotFoundException {

  // getBlob();

  DocumentBuilderFactory builderFactory = DocumentBuilderFactory
    .newInstance();
  builderFactory.setNamespaceAware(true); // Set namespace aware
  builderFactory.setValidating(false); // and validating parser feaures
  builderFactory.setIgnoringElementContentWhitespace(false);
 
  DocumentBuilder builder = null;
  try {
   builder = builderFactory.newDocumentBuilder(); // Create the parser
  } catch (ParserConfigurationException e) {
   e.printStackTrace();
  }
  Document xmlDoc = null;
  try {
   
   xmlDoc = builder.parse(new InputSource(new StringReader(xmlString)));
   /*NodeList list = xmlDoc.getChildNodes();
   Node node = list.item(0);
       System.out.println(" Node Object from List array   ? ");
       if ((node != null) && (node.getAttributes() != null)) {
         System.out.println(" Node is not null and checking for Attributes  ? ");
        NamedNodeMap attr = node.getAttributes();
        System.out.println(" Retrived attributes. checking for null and namespace ? ");
        if (attr != null) {
        System.out.println(" Retrived attributes. Not Null ? ");
         if (attr.getNamedItem("reason") != null) {
            System.out.println(" Exist attributes. with reason namespace ");
            if (((Attr)attr.getNamedItem("reason")).getValue().equals("")) {
              System.out.println(" reason is having Empty string ");
              System.out.println("Before Setting Reason value :" + ((Attr)attr.getNamedItem("reason")).getValue());
              ((Attr)attr.getNamedItem("reason")).setValue("ADMIN");
              System.out.println("attribute Reason Set To Value : " + ((Attr)attr.getNamedItem("reason")).getValue());
            }
           }
         }
      }*/
    // platform = OIMConnection.connection();
   //  XMLProcessor unauth = platform.getService(XMLProcessor.class);
   
    com.thortech.xl.audit.genericauditor.utils.XMLProcessor unauth = new com.thortech.xl.audit.genericauditor.utils.XMLProcessor(null);
    System.out.println("**************************");
   //System.out.println( unauth.getStringValue(xmlDoc));
    getStringValue(xmlDoc);

  } catch (SAXException e) {
   e.printStackTrace();

  } catch (IOException e) {
   e.printStackTrace();
  }

 }

 public static void getBlob() throws SQLException, IOException,
   ClassNotFoundException {

  Connection connectionObject = DataSource.getConnection();
  String sql = "select JMS_VALUE from aud_jms where aud_jms_key=?";
  PreparedStatement query = connectionObject.prepareStatement(sql);
  query.setInt(1, 141);
  ResultSet rs = query.executeQuery();
  rs.next();
  Blob jmsValue = rs.getBlob("JMS_VALUE");
  InputStream is = jmsValue.getBinaryStream();
  ObjectInputStream ois = new ObjectInputStream(is);
  AuditMessage auditMsg = (AuditMessage) ois.readObject();
  System.out.println(" ->>>>>>>>>>>>>>> "+ auditMsg.getAuditDeltas());
 
  Object o = ois.readObject();
  //XMLStream xStream = new XStream(new DomDriver());
  //String xmldata = xStream.toXML(o);
 }

 static String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Changes><Change action=\"update\" where=\"/UserProfileSnapshot/UserInfo\" order=\"0\" reason=\"admin\" reasonKey=\"0\">"
   + "<Attribute name=\"Users.Update Date\">"
   + " <OldValue>2014-01-11 12:32:59 -0500</OldValue>"
   + " <NewValue>2014-01-11 12:33:58 -0500</NewValue>"
   + "</Attribute>"
   + "<Attribute name=\"Users.Password\">"
   + " <OldValue>*******</OldValue>"
   + " <NewValue>********</NewValue>"
   + "</Attribute>"
   + "<Attribute name=\"Users.Updated By Login\">"
   + " <OldValue key=\"252145\">BXT1</OldValue>"
   + " <NewValue key=\"4\">OIMINTERNAL</NewValue>"
   + "</Attribute>"
   + "</Change></Changes>";

}

3 comments:

About OIM

Oracle Identity Management enables organizations to effectively manage the end - to - end life - cycle of user ide...

Popular Posts