Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* Copyright 1999 Vince Via vvia@viaoa.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/package com.viaoa.util;
import java.util.*;
import java.io.*;
import java.net.*;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import com.viaoa.ds.OASelect;
import com.viaoa.hub.Hub;
import com.viaoa.object.*;
// 20150906 created to be correct xml, removing OA specific format and tags. old version renamed to OAXMLReader1/**
OAXMLReader using a SAXParser to parse and automatically create OAObjects from an XML file.
This will do the following to find the existing object:
1: if OAProperty.importMatch, then it will search to find a matching object
2: if objectId props, then it will search to find a matching object
3: use guid
if not found, then a new object will be created.
@see OAXMLWriter
*/publicclassOAXMLReader{
private String fileName;
protected String value;
protectedint indent;
protectedint total;
protectedboolean bWithinTag;
protected Object[] stack = new Object[10];
private String decodeMessage;
privatestaticfinal String XML_ID = "XML_ID";
privatestaticfinal String XML_IDREF = "XML_IDREF";
privatestaticfinal String XML_VALUE = "XML_VALUE";
privatestaticfinal String XML_CLASS = "XML_CLASS";
privatestaticfinal String XML_OBJECT = "XML_OBJECT";
privatestaticfinal String XML_HUB = "XML_HUB";
protected Class conversionClass; // type of class that value needs to be converted toprotected HashMap hashGuid;
private OAXMLReader1 xmlReader1;
privateboolean bImportMatching = true;
private MyDefaultHandler myDefaultHandler;
// flag to know if OAXMLWriter wrote the object, which adds an additonal tag for the start of each object.privateint versionOAXML;
publicOAXMLReader(){
}
/**
* Read the xml data from a file and load into objects.
*/public Object[] readFile(String fileName) throws Exception {
parseFile(fileName);
ArrayList al = process();
Object[] objs = new Object[al.size()];
al.toArray(objs);
return objs;
}
public Object[] read(File file) throws Exception {
return readFile(file.getPath());
}
/**
* Read the xml data and load into objects.
*/public Object[] readXML(String xmlText) throws Exception {
parseString(xmlText);
ArrayList al = process();
Object[] objs = new Object[al.size()];
al.toArray(objs);
return objs;
}
publicvoidsetImportMatching(boolean b){
this.bImportMatching = b;
if (xmlReader1 != null) xmlReader1.setImportMatching(b);
}
publicbooleangetImportMatching(){
returnthis.bImportMatching;
}
/**
Used to unencrypt an XML file created by OAXMLWriter that used an encryption code.
@see OAXMLWriter#setEncodeMessage(String)
*/publicvoidsetDecodeMessage(String msg){
if (msg != null && msg.length() == 0) thrownew IllegalArgumentException("DecodeMessage cant be an empty string");
decodeMessage = msg;
if (xmlReader1 != null) xmlReader1.setDecodeMessage(msg);
}
public String getDecodeMessage(){
return decodeMessage;
}
protectedvoidreset(){
indent = 0;
total = 0;
bWithinTag = false;
hashGuid = new HashMap();
versionOAXML = 0;
xmlReader1 = null;
}
// Used to parse and create OAObjects from an XML file.protectedvoidparseFile(String fileName)throws Exception {
if (fileName == null) thrownew IllegalArgumentException("fileName is required");
reset();
URI uri = null;
File f = new File(OAString.convertFileName(fileName));
if (f.exists()) uri = f.toURI();
else uri = new URI(fileName);
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
saxParser.parse( uri.toString(), this.getDefaultHandler());
Object[] objs = new Object[indent + 1];
System.arraycopy(stack, 0, objs, 0, indent+1);
stack = objs;
}
// Used to parse and create OAObjects from an XML string.protectedvoidparseString(String xmlData)throws Exception {
if (xmlData == null) thrownew IllegalArgumentException("xmlData is required");
reset();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(new StringBufferInputStream(xmlData), this.getDefaultHandler());
}
protected ArrayList process()throws Exception {
if (xmlReader1 != null) {
ArrayList al = new ArrayList();
for (Object objx : xmlReader1.getRootObjects()) {
if (objx instanceof Hub) {
for (Object obj : ((Hub)objx)) {
al.add((OAObject) obj);
}
break;
}
al.add((OAObject) objx);
}
return al;
}
ArrayList