first commit

This commit is contained in:
2025-07-28 13:56:49 +05:30
commit e9eb805edb
3438 changed files with 520990 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Created-By: Oracle9i JDeveloper 9.0.4

1797
hrmsEjb/META-INF/ejb-jar.xml Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,181 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- ** This file was automatically generated by
** EJBGen WebLogic Server 10.3 SP0 Mon Jul 7 22:45:36 EDT 2008 1132476 -->
<!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN" "http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd">
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>HrmSecondFacade</ejb-name>
<jndi-name>HrmSecondFacade</jndi-name>
<local-jndi-name>HrmSecondFacadeHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ejb/HrmAttendanceFacadeLocal</ejb-name>
<jndi-name>ejb/HrmAttendanceFacadeLocal</jndi-name>
<local-jndi-name>HrmAttendanceFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ejb/HrmEligibilityFacadeLocal</ejb-name>
<jndi-name>ejb/HrmEligibilityFacadeLocal</jndi-name>
<local-jndi-name>HrmEligibilityFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ejb/HrmLeaveFacadeLocal</ejb-name>
<jndi-name>ejb/HrmLeaveFacadeLocal</jndi-name>
<local-jndi-name>HrmLeaveFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ejb/HrmManPlFacadeLocal</ejb-name>
<jndi-name>ejb/HrmManPlFacadeLocal</jndi-name>
<local-jndi-name>HrmManPlFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ejb/HrmPromotionFacadeLocal</ejb-name>
<jndi-name>ejb/HrmPromotionFacadeLocal</jndi-name>
<local-jndi-name>HrmPromotionFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ejb/HrmRecruitmentFacadeLocal</ejb-name>
<jndi-name>ejb/HrmRecruitmentFacadeLocal</jndi-name>
<local-jndi-name>HrmRecruitmentFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ejb/HrmTrainingFacadeLocal</ejb-name>
<jndi-name>ejb/HrmTrainingFacadeLocal</jndi-name>
<local-jndi-name>HrmTrainingFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmPerformanceAppraisalFacade</ejb-name>
<jndi-name>HrmPerformanceAppraisalFacade</jndi-name>
<local-jndi-name>HrmPerformanceAppraisalFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmTrainingFacade</ejb-name>
<jndi-name>HrmTrainingFacade</jndi-name>
<local-jndi-name>HrmTrainingFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmAttendanceFacade</ejb-name>
<jndi-name>HrmAttendanceFacade</jndi-name>
<local-jndi-name>HrmAttendanceFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmHelpFacade</ejb-name>
<jndi-name>HrmHelpFacade</jndi-name>
<local-jndi-name>HelpFacadeHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmAllocationTransferDeputationFacade</ejb-name>
<jndi-name>HrmAllocationTransferDeputationFacade</jndi-name>
<local-jndi-name>HrmAllocationTransferDeputationFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmRecruitmentFacade</ejb-name>
<jndi-name>HrmRecruitmentFacade</jndi-name>
<local-jndi-name>HrmRecruitmentFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmLeaveFacade</ejb-name>
<jndi-name>HrmLeaveFacade</jndi-name>
<local-jndi-name>HrmLeaveFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmThirdFacade</ejb-name>
<jndi-name>HrmThirdFacade</jndi-name>
<local-jndi-name>HrmThirdFacadeHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ejb/HrmAllocationTransferDeputationFacadeLocal</ejb-name>
<jndi-name>ejb/HrmAllocationTransferDeputationFacadeLocal</jndi-name>
<local-jndi-name>HrmAllocationTransferDeputationFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ejb/HrmPerformanceAppraisalFacadeLocal</ejb-name>
<jndi-name>ejb/HrmPerformanceAppraisalFacadeLocal</jndi-name>
<local-jndi-name>HrmPerformanceAppraisalFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmEligibilityFacade</ejb-name>
<jndi-name>HrmEligibilityFacade</jndi-name>
<local-jndi-name>HrmEligibilityFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmLoanFacade</ejb-name>
<jndi-name>HrmLoanFacade</jndi-name>
<local-jndi-name>HrmLoanFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmUserSession</ejb-name>
<jndi-name>HrmUserSession</jndi-name>
<local-jndi-name>UserSessionHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmOrganisationSetUpFacade</ejb-name>
<jndi-name>HrmOrganisationSetUpFacade</jndi-name>
<local-jndi-name>HrmOrganisationSetUpFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmEmployeeMaintenanceFacade</ejb-name>
<jndi-name>HrmEmployeeMaintenanceFacade</jndi-name>
<local-jndi-name>HrmEmployeeMaintenanceFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmSecurityFacade</ejb-name>
<jndi-name>HrmSecurityFacade</jndi-name>
<local-jndi-name>SecurityFacadeHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmFacade</ejb-name>
<jndi-name>HrmFacade</jndi-name>
<local-jndi-name>HrmFacadeHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ejb/HrmAdvanceClaimFacadeLocal</ejb-name>
<jndi-name>ejb/HrmAdvanceClaimFacadeLocal</jndi-name>
<local-jndi-name>HrmAdvanceClaimFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ejb/HrmEmployeeMaintenanceFacadeLocal</ejb-name>
<jndi-name>ejb/HrmEmployeeMaintenanceFacadeLocal</jndi-name>
<local-jndi-name>HrmEmployeeMaintenanceFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ejb/HrmLeaveFacadeLocal</ejb-name>
<jndi-name>ejb/HrmLeaveFacadeLocal</jndi-name>
<local-jndi-name>HrmLeaveFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ejb/HrmLoanFacadeLocal</ejb-name>
<jndi-name>ejb/HrmLoanFacadeLocal</jndi-name>
<local-jndi-name>HrmLoanFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ejb/HrmOrganisationSetUpFacadeLocal</ejb-name>
<jndi-name>ejb/HrmOrganisationSetUpFacadeLocal</jndi-name>
<local-jndi-name>HrmOrganisationSetUpFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>ejb/HrmSeparationFacadeLocal</ejb-name>
<jndi-name>ejb/HrmSeparationFacadeLocal</jndi-name>
<local-jndi-name>HrmSeparationFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmSeparationFacade</ejb-name>
<jndi-name>HrmSeparationFacade</jndi-name>
<local-jndi-name>HrmSeparationFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmAdvanceClaimFacade</ejb-name>
<jndi-name>HrmAdvanceClaimFacade</jndi-name>
<local-jndi-name>HrmAdvanceClaimFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmManPlFacade</ejb-name>
<jndi-name>HrmManPlFacade</jndi-name>
<local-jndi-name>HrmManPlFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>HrmPromotionFacade</ejb-name>
<jndi-name>HrmPromotionFacade</jndi-name>
<local-jndi-name>HrmPromotionFacadeLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>

View File

@@ -0,0 +1,185 @@
package com.tcs.wenrgise.util.common;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Stack;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
public class FWSAXParser extends DefaultHandler {
private String lastName;
private Stack aStack = new Stack();
private Object objFinal;
private String sPackage = "";
void setPackage(String sPackage_) {
this.sPackage = sPackage_;
}
void setObject(Object obj) {
this.objFinal = obj;
}
Object getFinalObject() {
return this.objFinal;
}
public void startElement(String uri, String name, String qName, Attributes atts) {
this.lastName = new String(name);
this.sCharStringBuffer = new StringBuffer();
try {
this.aStack.push(name);
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
public void endElement(String uri, String name, String qName) {
try {
this.sPathMap = getPathMap();
String sChar = this.sCharStringBuffer.toString();
String sTempChar = new String(sChar);
sTempChar = sTempChar.replace('\r', ' ');
sTempChar = sTempChar.replace('\n', ' ');
sTempChar = sTempChar.trim();
if (sChar != null && sChar.length() > 0 && sTempChar.length() > 0)
populateValue(sChar, this.sPathMap);
this.sCharStringBuffer = new StringBuffer();
String sTopElement = this.aStack.pop();
if (sTopElement.equals(name)) {
addToHashMap(getPathMap(this.sPathMap));
} else {
this.aStack.push(sTopElement);
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
ArrayList sPathMap = null;
StringBuffer sCharStringBuffer = new StringBuffer();
public void characters(char[] ch, int start, int length) {
try {
this.sCharStringBuffer.append(new String(ch, start, length));
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
private ArrayList getPathMap() {
ArrayList aList = new ArrayList(this.aStack.size());
for (int i = 0; i < this.aStack.size(); i++)
aList.add(this.aStack.get(i));
return aList;
}
private void populateValue(Object value, ArrayList aPathMap) throws Exception {
StringBuffer sbfGetMethodName = new StringBuffer(20);
StringBuffer sbfSetMethodName = new StringBuffer(20);
try {
if (null == aPathMap)
return;
Object objOriginal = this.objFinal;
Object objTempCurrent = this.objFinal;
ArrayList aTempPathMap = new ArrayList();
aTempPathMap.add(aPathMap.get(0));
for (int i = 1; i < aPathMap.size(); i++) {
String sElement = aPathMap.get(i);
aTempPathMap.add(sElement);
sbfGetMethodName = (new StringBuffer("get_")).append(sElement);
Method mGet = objTempCurrent.getClass().getMethod(sbfGetMethodName.toString(), null);
Object objChild = mGet.invoke(objTempCurrent, null);
if (objChild == null) {
Class retClass = mGet.getReturnType();
objChild = retClass.newInstance();
}
if (objChild instanceof ArrayList) {
sbfSetMethodName = (new StringBuffer("set_")).append(sElement);
if (i == aPathMap.size() - 1) {
((ArrayList)objChild).add(value);
Method mSet = objTempCurrent.getClass().getMethod(sbfSetMethodName.toString(), new Class[] { objChild.getClass() });
mSet.invoke(objTempCurrent, new Object[] { objChild });
} else {
ArrayList aList = (ArrayList)objChild;
Object objTemp = null;
String sTempPathMap = getPathMap(aTempPathMap);
int iCounter = getCounter(sTempPathMap);
if (aList.size() > iCounter) {
objTemp = aList.get(iCounter);
} else {
Class cTemp = Class.forName(this.sPackage + sElement);
objTemp = cTemp.newInstance();
aList.add(objTemp);
}
Method mSet = objTempCurrent.getClass().getMethod(sbfSetMethodName.toString(), new Class[] { objChild.getClass() });
mSet.invoke(objTempCurrent, new Object[] { objChild });
objChild = objTemp;
}
} else {
if (i == aPathMap.size() - 1)
objChild = value;
sbfSetMethodName = (new StringBuffer("set_")).append(sElement);
Method mSet = objTempCurrent.getClass().getMethod(sbfSetMethodName.toString(), new Class[] { objChild.getClass() });
mSet.invoke(objTempCurrent, new Object[] { objChild });
}
objTempCurrent = objChild;
}
this.objFinal = objOriginal;
} catch (Exception e) {
throw new Exception(String.valueOf(String.valueOf(e.getMessage()).concat(String.valueOf(" TAGMETHODNAME: "))).concat(String.valueOf(sbfGetMethodName.toString())));
}
}
private void addToHashMap(String sPathMap) {
if (sPathMap == null || sPathMap.trim().length() <= 0)
return;
Object objCounter = this.aCounterMap.get(sPathMap);
Integer iCounter = null;
if (objCounter != null) {
iCounter = (Integer)objCounter;
} else {
iCounter = new Integer(0);
}
iCounter = new Integer(iCounter.intValue() + 1);
this.aCounterMap.put(sPathMap, iCounter);
Set keySet = this.aCounterMap.keySet();
Iterator itrKey = keySet.iterator();
while (itrKey.hasNext()) {
String sKey = itrKey.next();
if (sKey.startsWith(sPathMap) && sKey.length() > sPathMap.length())
this.aCounterMap.put(sKey, new Integer(0));
}
}
private int getCounter(String sPathMap) {
if (sPathMap == null || sPathMap.trim().length() <= 0)
return 0;
Object objCounter = this.aCounterMap.get(sPathMap);
Integer iCounter = null;
if (objCounter != null) {
iCounter = (Integer)objCounter;
} else {
iCounter = new Integer(0);
}
return iCounter.intValue();
}
private String getPathMap(ArrayList aPathMap) {
if (aPathMap == null || aPathMap.size() <= 0)
return null;
StringBuffer sTotStringBuffer = new StringBuffer();
for (int i = 0; i < aPathMap.size(); i++)
sTotStringBuffer.append(aPathMap.get(i)).append("/");
return sTotStringBuffer.toString();
}
private HashMap aCounterMap = new HashMap(20);
}

View File

@@ -0,0 +1,472 @@
package com.tcs.wenrgise.util.common;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.xerces.parsers.SAXParser;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class FWXMLUtility {
private static boolean bReverseOrderAttr;
private static String timerClassName;
private static final String LINESEPARATOR = "\n";
static {
try {
Class cTempClass = Class.forName("com.tcs.wenrgise.util.common.FWXMLUtilitySequence");
Field[] fFieldArray = cTempClass.getDeclaredFields();
if (fFieldArray[0].getName().equals("ATTRIBUTE1")) {
bReverseOrderAttr = false;
} else {
bReverseOrderAttr = true;
}
} catch (Exception exception) {}
}
public static void setTimerClassName(String timerClassName_) {
timerClassName = timerClassName_;
}
public static Object xmlToObject(String className, String sFileName) throws Exception {
String methodName = "xmlToObject";
FWSAXParser handler = null;
InputSource aSource = null;
SAXParser parser = null;
FileReader aFileReader = null;
try {
Class c = Class.forName(className);
Object objFinal = c.newInstance();
String sPackage = getPackage(className);
parser = null;
try {
parser = new SAXParser();
} catch (Exception e) {
e.printStackTrace();
parser = null;
System.err.println(String.valueOf(String.valueOf("error: Unable to instantiate parser(").concat(String.valueOf(parser))).concat(String.valueOf(")")));
return null;
}
handler = new FWSAXParser();
handler.setObject(objFinal);
handler.setPackage(sPackage);
parser.setContentHandler(handler);
aFileReader = new FileReader(sFileName);
aSource = new InputSource(aFileReader);
parser.parse(aSource);
aSource = null;
parser = null;
return handler.getFinalObject();
} catch (Throwable e) {
aSource = null;
parser = null;
throw new Exception(e.getMessage());
} finally {
if (null != aFileReader) {
aFileReader.close();
aFileReader = null;
}
aSource = null;
parser = null;
}
}
public static void display(Object obj) throws Exception {
if (obj == null)
return;
Method[] mList = obj.getClass().getMethods();
if (mList != null)
for (int i = 0; i < mList.length; i++) {
String methodName = mList[i].getName();
if (methodName.startsWith("get_")) {
Object objRet = null;
try {
objRet = mList[i].invoke(obj, null);
} catch (Exception e) {}
Class retClass = mList[i].getReturnType();
if (retClass.getName().equals("java.lang.String")) {
System.out.println(String.valueOf(String.valueOf(String.valueOf(String.valueOf(obj.getClass().getName()).concat(String.valueOf(":"))).concat(String.valueOf(methodName))).concat(String.valueOf("="))).concat(String.valueOf(objRet)));
} else if (retClass.getName().equals("java.util.ArrayList")) {
if (objRet != null) {
ArrayList aList = (ArrayList)objRet;
for (int j = 0; j < aList.size(); j++) {
if (aList.get(j) instanceof String) {
System.out.println(String.valueOf(String.valueOf(String.valueOf(String.valueOf(String.valueOf(String.valueOf(obj.getClass().getName()).concat(String.valueOf(":"))).concat(String.valueOf(methodName))).concat(String.valueOf("["))).concat(String.valueOf(j))).concat(String.valueOf("]="))).concat(String.valueOf(aList.get(j))));
} else {
display(aList.get(j));
}
}
}
} else {
display(objRet);
}
}
}
}
private static String getPackage(String classWithPackage) {
if (classWithPackage == null)
return "";
int intLastIndexOfDot = classWithPackage.lastIndexOf(".");
if (intLastIndexOfDot == -1)
return "";
return classWithPackage.substring(0, intLastIndexOfDot + 1);
}
private static String getClassNameWithoutPackage(String sClassNameWithPackage) {
if (null == sClassNameWithPackage)
return "";
int indexOfDot = sClassNameWithPackage.lastIndexOf(".");
if (indexOfDot != -1 && indexOfDot < sClassNameWithPackage.length())
return sClassNameWithPackage.substring(indexOfDot + 1, sClassNameWithPackage.length());
return sClassNameWithPackage;
}
public static String objectToXSD(String sClassName) throws Exception {
Class cClass = Class.forName(sClassName);
Object objIn = cClass.newInstance();
String sClassNameWithoutPackage = getClassNameWithoutPackage(sClassName);
String sPackageName = getPackage(sClassName);
String sXSD = "";
int level = 0;
sXSD = String.valueOf(sXSD).concat(String.valueOf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
sXSD = String.valueOf(sXSD).concat(String.valueOf("\n"));
sXSD = String.valueOf(sXSD).concat(String.valueOf("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\">"));
sXSD = String.valueOf(sXSD).concat(String.valueOf("\n"));
sXSD = String.valueOf(sXSD).concat(String.valueOf(String.valueOf(String.valueOf(String.valueOf(getSpaces(level + 1)).concat(String.valueOf("<xs:element name=\""))).concat(String.valueOf(sClassNameWithoutPackage))).concat(String.valueOf("\">"))));
sXSD = String.valueOf(sXSD).concat(String.valueOf("\n"));
sXSD = String.valueOf(sXSD).concat(String.valueOf(String.valueOf(getSpaces(level + 2)).concat(String.valueOf("<xs:complexType>"))));
sXSD = String.valueOf(sXSD).concat(String.valueOf("\n"));
sXSD = String.valueOf(sXSD).concat(String.valueOf(String.valueOf(getSpaces(level + 3)).concat(String.valueOf("<xs:sequence>"))));
sXSD = String.valueOf(sXSD).concat(String.valueOf("\n"));
sXSD = String.valueOf(sXSD).concat(String.valueOf(objectToXSDInternal(objIn, sPackageName, level + 3)));
sXSD = String.valueOf(sXSD).concat(String.valueOf(String.valueOf(getSpaces(level + 3)).concat(String.valueOf("</xs:sequence>"))));
sXSD = String.valueOf(sXSD).concat(String.valueOf("\n"));
sXSD = String.valueOf(sXSD).concat(String.valueOf(String.valueOf(getSpaces(level + 2)).concat(String.valueOf("</xs:complexType>"))));
sXSD = String.valueOf(sXSD).concat(String.valueOf("\n"));
sXSD = String.valueOf(sXSD).concat(String.valueOf(String.valueOf(getSpaces(level + 1)).concat(String.valueOf("</xs:element>"))));
sXSD = String.valueOf(sXSD).concat(String.valueOf("\n"));
sXSD = String.valueOf(sXSD).concat(String.valueOf("</xs:schema>"));
return sXSD;
}
private static String objectToXSDInternal(Object objIn, String sPackageName, int level) throws Exception {
if (null == objIn)
return "";
String sXML = "";
Class cIn = objIn.getClass();
String sClassName = cIn.getName();
if (sClassName.equals("java.util.ArrayList")) {
ArrayList aList = (ArrayList)objIn;
for (int i = 0; i < aList.size(); i++) {
Object obj = aList.get(i);
sXML = String.valueOf(sXML).concat(String.valueOf(objectToXSDInternal(obj, sPackageName, level)));
}
} else {
if (sClassName.equals("java.lang.String"))
return objIn.toString();
Field[] fFieldArray = cIn.getDeclaredFields();
for (int i = 0; i < fFieldArray.length; i++) {
Field aField = fFieldArray[i];
String sFieldName = aField.getName();
Class cType = aField.getType();
String sTagName = getTagName(sFieldName);
String sMethodName = String.valueOf("get").concat(String.valueOf(sFieldName));
Method m = cIn.getMethod(sMethodName, null);
Class cReturnType = m.getReturnType();
if (cReturnType.getName().equals("java.util.ArrayList")) {
sXML = String.valueOf(sXML).concat(String.valueOf(String.valueOf(String.valueOf(String.valueOf(getSpaces(level + 1)).concat(String.valueOf("<xs:element name=\""))).concat(String.valueOf(sTagName))).concat(String.valueOf("\" maxOccurs=\"unbounded\">"))));
sXML = String.valueOf(sXML).concat(String.valueOf("\n"));
sXML = String.valueOf(sXML).concat(String.valueOf(String.valueOf(getSpaces(level + 2)).concat(String.valueOf("<xs:complexType>"))));
sXML = String.valueOf(sXML).concat(String.valueOf("\n"));
sXML = String.valueOf(sXML).concat(String.valueOf(String.valueOf(getSpaces(level + 3)).concat(String.valueOf("<xs:sequence>"))));
sXML = String.valueOf(sXML).concat(String.valueOf("\n"));
Class cRetType = Class.forName(getClassNameWithPackage(sTagName, sPackageName));
Object objRet = cRetType.newInstance();
sXML = String.valueOf(sXML).concat(String.valueOf(objectToXSDInternal(objRet, sPackageName, level + 3)));
sXML = String.valueOf(sXML).concat(String.valueOf(String.valueOf(getSpaces(level + 3)).concat(String.valueOf("</xs:sequence>"))));
sXML = String.valueOf(sXML).concat(String.valueOf("\n"));
sXML = String.valueOf(sXML).concat(String.valueOf(String.valueOf(getSpaces(level + 2)).concat(String.valueOf("</xs:complexType>"))));
sXML = String.valueOf(sXML).concat(String.valueOf("\n"));
sXML = String.valueOf(sXML).concat(String.valueOf(String.valueOf(getSpaces(level + 1)).concat(String.valueOf("</xs:element>"))));
sXML = String.valueOf(sXML).concat(String.valueOf("\n"));
} else if (cReturnType.getName().equals("java.lang.String")) {
sXML = String.valueOf(sXML).concat(String.valueOf(String.valueOf(String.valueOf(String.valueOf(getSpaces(level + 1)).concat(String.valueOf("<xs:element name=\""))).concat(String.valueOf(sTagName))).concat(String.valueOf("\" type=\"xs:string\" minOccurs=\"0\">"))));
sXML = String.valueOf(sXML).concat(String.valueOf("\n"));
sXML = String.valueOf(sXML).concat(String.valueOf(String.valueOf(getSpaces(level + 1)).concat(String.valueOf("</xs:element>"))));
sXML = String.valueOf(sXML).concat(String.valueOf("\n"));
} else {
sXML = String.valueOf(sXML).concat(String.valueOf(String.valueOf(String.valueOf(String.valueOf(getSpaces(level + 1)).concat(String.valueOf("<xs:element name=\""))).concat(String.valueOf(sTagName))).concat(String.valueOf("\" minOccurs=\"0\">"))));
sXML = String.valueOf(sXML).concat(String.valueOf("\n"));
sXML = String.valueOf(sXML).concat(String.valueOf(String.valueOf(getSpaces(level + 2)).concat(String.valueOf("<xs:complexType>"))));
sXML = String.valueOf(sXML).concat(String.valueOf("\n"));
sXML = String.valueOf(sXML).concat(String.valueOf(String.valueOf(getSpaces(level + 3)).concat(String.valueOf("<xs:sequence>"))));
sXML = String.valueOf(sXML).concat(String.valueOf("\n"));
Object objRet = cReturnType.newInstance();
sXML = String.valueOf(sXML).concat(String.valueOf(objectToXSDInternal(objRet, sPackageName, level + 3)));
sXML = String.valueOf(sXML).concat(String.valueOf(String.valueOf(getSpaces(level + 3)).concat(String.valueOf("</xs:sequence>"))));
sXML = String.valueOf(sXML).concat(String.valueOf("\n"));
sXML = String.valueOf(sXML).concat(String.valueOf(String.valueOf(getSpaces(level + 2)).concat(String.valueOf("</xs:complexType>"))));
sXML = String.valueOf(sXML).concat(String.valueOf("\n"));
sXML = String.valueOf(sXML).concat(String.valueOf(String.valueOf(getSpaces(level + 1)).concat(String.valueOf("</xs:element>"))));
sXML = String.valueOf(sXML).concat(String.valueOf("\n"));
}
}
}
return sXML;
}
public static String objectToXML(Object objIn) throws Exception {
String methodName = "objectToXML";
try {
StringBuffer sXMLBuffer = new StringBuffer();
sXMLBuffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
if (objIn == null)
return sXMLBuffer.toString();
sXMLBuffer.append("\n");
String sClassName = objIn.getClass().getName();
String sClassNameWithoutPackage = getClassNameWithoutPackage(sClassName);
sXMLBuffer.append("<").append(sClassNameWithoutPackage).append(">");
sXMLBuffer.append("\n");
sXMLBuffer.append(objectToXMLInternal(objIn, 0));
sXMLBuffer.append("</").append(sClassNameWithoutPackage).append(">");
return sXMLBuffer.toString();
} catch (Exception e) {
e.printStackTrace();
} finally {}
return null;
}
private static StringBuffer objectToXMLInternal(Object objIn, int level) throws Exception {
if (null == objIn)
return new StringBuffer();
StringBuffer sXMLBuffer = new StringBuffer();
Class cIn = objIn.getClass();
String sClassName = cIn.getName();
if (sClassName.equals("java.util.ArrayList")) {
ArrayList aList = (ArrayList)objIn;
if (aList.size() > 0)
if (bReverseOrderAttr) {
for (int i = aList.size() - 1; i >= 0; i--) {
Object obj = aList.get(i);
if (obj != null) {
String sTempClassName = obj.getClass().getName();
if (sTempClassName.equals("java.lang.String")) {
sXMLBuffer.append(objectToXMLInternal(obj, level + 1));
} else {
String sClassNameWithoutPackage = getClassNameWithoutPackage(sTempClassName);
sXMLBuffer.append(getSpaces(level + 1)).append("<").append(sClassNameWithoutPackage).append(">");
sXMLBuffer.append("\n");
sXMLBuffer.append(objectToXMLInternal(obj, level + 1));
sXMLBuffer.append(getSpaces(level + 1)).append("</").append(sClassNameWithoutPackage).append(">");
sXMLBuffer.append("\n");
}
}
}
} else {
for (int i = 0; i < aList.size(); i++) {
Object obj = aList.get(i);
if (obj != null) {
String sTempClassName = obj.getClass().getName();
if (sTempClassName.equals("java.lang.String")) {
sXMLBuffer.append(objectToXMLInternal(obj, level + 1));
} else {
String sClassNameWithoutPackage = getClassNameWithoutPackage(sTempClassName);
sXMLBuffer.append(getSpaces(level + 1)).append("<").append(sClassNameWithoutPackage).append(">");
sXMLBuffer.append("\n");
sXMLBuffer.append(objectToXMLInternal(obj, level + 1));
sXMLBuffer.append(getSpaces(level + 1)).append("</").append(sClassNameWithoutPackage).append(">");
sXMLBuffer.append("\n");
}
}
}
}
} else {
if (sClassName.equals("java.lang.String")) {
String sTempStr = objIn.toString();
if (sTempStr.startsWith("<![CDATA"))
return new StringBuffer(sTempStr);
return new StringBuffer(encodeXML(sTempStr));
}
Field[] fFieldArray = cIn.getDeclaredFields();
if (bReverseOrderAttr) {
for (int i = fFieldArray.length - 1; i >= 0; i--) {
Field aField = fFieldArray[i];
String sFieldName = aField.getName();
Class cType = aField.getType();
String sTagName = getTagName(sFieldName);
String sMethodName = String.valueOf("get").concat(String.valueOf(sFieldName));
Method m = null;
try {
m = cIn.getMethod(sMethodName, null);
} catch (Exception e) {}
Object objRet = m.invoke(objIn, null);
String sReturnClassName = "";
if (objRet != null) {
sReturnClassName = objRet.getClass().getName();
if (sReturnClassName.equals("java.util.ArrayList")) {
ArrayList aList = (ArrayList)objRet;
if (aList.size() > 0) {
Object objTemp = aList.get(0);
if (objTemp instanceof String) {
sXMLBuffer.append(getSpaces(level + 1)).append("<").append(sTagName).append(">");
sXMLBuffer.append(objectToXMLInternal(objRet, level + 1));
sXMLBuffer.append("</").append(sTagName).append(">");
sXMLBuffer.append("\n");
} else {
sXMLBuffer.append(objectToXMLInternal(objRet, level));
}
}
} else if (sReturnClassName.equals("java.lang.String")) {
sXMLBuffer.append(getSpaces(level + 1)).append("<").append(sTagName).append(">");
sXMLBuffer.append(objectToXMLInternal(objRet, level + 1));
sXMLBuffer.append(String.valueOf(String.valueOf("</").concat(String.valueOf(sTagName))).concat(String.valueOf(">")));
sXMLBuffer.append("\n");
} else {
sXMLBuffer.append(getSpaces(level + 1)).append("<").append(sTagName).append(">");
sXMLBuffer.append("\n");
sXMLBuffer.append(objectToXMLInternal(objRet, level + 1));
sXMLBuffer.append(getSpaces(level + 1)).append(String.valueOf("</").concat(String.valueOf(sTagName))).append(">");
sXMLBuffer.append("\n");
}
}
}
} else {
for (int i = 0; i < fFieldArray.length; i++) {
Field aField = fFieldArray[i];
String sFieldName = aField.getName();
Class cType = aField.getType();
String sTagName = getTagName(sFieldName);
String sMethodName = String.valueOf("get").concat(String.valueOf(sFieldName));
Method m = null;
try {
m = cIn.getMethod(sMethodName, null);
} catch (Exception e) {}
Object objRet = m.invoke(objIn, null);
String sReturnClassName = "";
if (objRet != null) {
sReturnClassName = objRet.getClass().getName();
if (sReturnClassName.equals("java.util.ArrayList")) {
ArrayList aList = (ArrayList)objRet;
if (aList.size() > 0) {
Object objTemp = aList.get(0);
if (objTemp instanceof String) {
sXMLBuffer.append(getSpaces(level + 1)).append("<").append(sTagName).append(">");
sXMLBuffer.append(objectToXMLInternal(objRet, level + 1));
sXMLBuffer.append("</").append(sTagName).append(">");
sXMLBuffer.append("\n");
} else {
sXMLBuffer.append(objectToXMLInternal(objRet, level));
}
}
} else if (sReturnClassName.equals("java.lang.String")) {
sXMLBuffer.append(getSpaces(level + 1)).append("<").append(sTagName).append(">");
sXMLBuffer.append(objectToXMLInternal(objRet, level + 1));
sXMLBuffer.append("</").append(sTagName).append(">");
sXMLBuffer.append("\n");
} else {
sXMLBuffer.append(getSpaces(level + 1)).append("<").append(sTagName).append(">");
sXMLBuffer.append("\n");
sXMLBuffer.append(objectToXMLInternal(objRet, level + 1));
sXMLBuffer.append(getSpaces(level + 1)).append("</").append(sTagName).append(">");
sXMLBuffer.append("\n");
}
}
}
}
}
return sXMLBuffer;
}
private static String getTagName(String sFieldName) {
if (sFieldName == null)
return "";
int indexOfUnderScore = sFieldName.indexOf("_");
if (indexOfUnderScore == 0 && sFieldName.length() >= 2)
return sFieldName.substring(1, sFieldName.length());
return sFieldName;
}
private static String getClassNameWithPackage(String sTagName, String sPackageName) {
if (sPackageName == null || sPackageName.trim().length() <= 0)
return sTagName;
return String.valueOf(sPackageName).concat(String.valueOf(sTagName));
}
private static String getSpaces(int iCount) {
String sRet = "";
for (int i = 0; i < iCount; i++)
sRet = String.valueOf(sRet).concat(String.valueOf(" "));
return sRet;
}
public static String encodeXML(String strIn) {
String[] xmlEncFrom = { "&", "\"", "<", ">" };
String[] xmlEncTo = { "&amp;", "&quot;", "&lt;", "&gt;" };
int idx = 0;
if (strIn == null)
return null;
StringBuffer strOut = new StringBuffer(strIn);
StringBuffer strTemp = null;
for (int i = 0; i < xmlEncFrom.length; i++) {
idx = strOut.toString().indexOf(xmlEncFrom[i]);
while (idx != -1) {
strTemp = new StringBuffer();
strTemp.append(strOut.substring(0, idx)).append(xmlEncTo[i]).append(strOut.substring(idx + xmlEncFrom[i].length()));
strOut = strTemp;
idx = strOut.toString().indexOf(xmlEncFrom[i], idx + xmlEncTo[i].length());
}
}
return strOut.toString();
}
public static ArrayList validateXMLWithXSD(String xml, String schema) throws IOException, ParserConfigurationException, SAXException {
try {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
parserFactory.setValidating(true);
parserFactory.setFeature("http://apache.org/xml/features/validation/schema", true);
parserFactory.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
SAXParser saxParser = parserFactory.newSAXParser();
saxParser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", schema);
InputSource is = new InputSource(new StringReader(xml));
XMLValidationHandler handler = new XMLValidationHandler();
saxParser.parse(is, handler);
ArrayList aList = handler.getResults();
return aList;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static ArrayList validateXMLWithXSD(File file, String schema) throws IOException, ParserConfigurationException, SAXException {
try {
String sFileName = file.getAbsolutePath();
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
parserFactory.setValidating(true);
parserFactory.setFeature("http://apache.org/xml/features/validation/schema", true);
parserFactory.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
SAXParser saxParser = parserFactory.newSAXParser();
saxParser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", schema);
InputSource is = new InputSource(sFileName);
XMLValidationHandler handler = new XMLValidationHandler();
saxParser.parse(is, handler);
ArrayList aList = handler.getResults();
return aList;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

View File

@@ -0,0 +1,26 @@
package com.tcs.wenrgise.util.common;
import java.util.ArrayList;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
public class XMLValidationHandler extends DefaultHandler {
private ArrayList results = new ArrayList();
public ArrayList getResults() {
return this.results;
}
public void warning(SAXParseException e) throws SAXException {
this.results.add(e.toString());
}
public void fatalError(SAXParseException e) throws SAXException {
this.results.add(e.toString());
}
public void error(SAXParseException e) throws SAXException {
this.results.add(e.toString());
}
}

View File

@@ -0,0 +1,13 @@
package common;
public final class Assert {
public static void verify(boolean condition) {
if (!condition)
throw new AssertionFailed();
}
public static void verify(boolean condition, String message) {
if (!condition)
throw new AssertionFailed(message);
}
}

View File

@@ -0,0 +1,11 @@
package common;
public class AssertionFailed extends RuntimeException {
public AssertionFailed() {
printStackTrace();
}
public AssertionFailed(String s) {
super(s);
}
}

View File

@@ -0,0 +1,63 @@
package common;
import common.log.LoggerName;
import common.log.SimpleLogger;
import java.security.AccessControlException;
public abstract class Logger {
private static Logger logger = null;
public static final Logger getLogger(Class cl) {
if (logger == null)
initializeLogger();
return logger.getLoggerImpl(cl);
}
private static synchronized void initializeLogger() {
if (logger != null)
return;
String loggerName = LoggerName.NAME;
try {
loggerName = System.getProperty("logger");
if (loggerName == null)
loggerName = LoggerName.NAME;
logger = (Logger)Class.forName(loggerName).newInstance();
} catch (IllegalAccessException e) {
logger = (Logger)new SimpleLogger();
logger.warn("Could not instantiate logger " + loggerName + " using default");
} catch (InstantiationException e) {
logger = (Logger)new SimpleLogger();
logger.warn("Could not instantiate logger " + loggerName + " using default");
} catch (AccessControlException e) {
logger = (Logger)new SimpleLogger();
logger.warn("Could not instantiate logger " + loggerName + " using default");
} catch (ClassNotFoundException e) {
logger = (Logger)new SimpleLogger();
logger.warn("Could not instantiate logger " + loggerName + " using default");
}
}
public abstract void debug(Object paramObject);
public abstract void debug(Object paramObject, Throwable paramThrowable);
public abstract void error(Object paramObject);
public abstract void error(Object paramObject, Throwable paramThrowable);
public abstract void fatal(Object paramObject);
public abstract void fatal(Object paramObject, Throwable paramThrowable);
public abstract void info(Object paramObject);
public abstract void info(Object paramObject, Throwable paramThrowable);
public abstract void warn(Object paramObject);
public abstract void warn(Object paramObject, Throwable paramThrowable);
protected abstract Logger getLoggerImpl(Class paramClass);
public void setSuppressWarnings(boolean w) {}
}

View File

@@ -0,0 +1,5 @@
package common.log;
public class LoggerName {
public static final String NAME = SimpleLogger.class.getName();
}

View File

@@ -0,0 +1,79 @@
package common.log;
import common.Logger;
public class SimpleLogger extends Logger {
private boolean suppressWarnings = false;
public void debug(Object message) {
if (!this.suppressWarnings) {
System.out.print("Debug: ");
System.out.println(message);
}
}
public void debug(Object message, Throwable t) {
if (!this.suppressWarnings) {
System.out.print("Debug: ");
System.out.println(message);
t.printStackTrace();
}
}
public void error(Object message) {
System.err.print("Error: ");
System.err.println(message);
}
public void error(Object message, Throwable t) {
System.err.print("Error: ");
System.err.println(message);
t.printStackTrace();
}
public void fatal(Object message) {
System.err.print("Fatal: ");
System.err.println(message);
}
public void fatal(Object message, Throwable t) {
System.err.print("Fatal: ");
System.err.println(message);
t.printStackTrace();
}
public void info(Object message) {
if (!this.suppressWarnings)
System.out.println(message);
}
public void info(Object message, Throwable t) {
if (!this.suppressWarnings) {
System.out.println(message);
t.printStackTrace();
}
}
public void warn(Object message) {
if (!this.suppressWarnings) {
System.err.print("Warning: ");
System.err.println(message);
}
}
public void warn(Object message, Throwable t) {
if (!this.suppressWarnings) {
System.err.print("Warning: ");
System.err.println(message);
t.printStackTrace();
}
}
protected Logger getLoggerImpl(Class c) {
return this;
}
public void setSuppressWarnings(boolean w) {
this.suppressWarnings = w;
}
}

View File

@@ -0,0 +1,5 @@
package jxl;
public interface BooleanCell extends Cell {
boolean getValue();
}

View File

@@ -0,0 +1,3 @@
package jxl;
public interface BooleanFormulaCell extends BooleanCell, FormulaCell {}

19
hrmsEjb/jxl/Cell.java Normal file
View File

@@ -0,0 +1,19 @@
package jxl;
import jxl.format.CellFormat;
public interface Cell {
int getRow();
int getColumn();
CellType getType();
boolean isHidden();
String getContents();
CellFormat getCellFormat();
CellFeatures getCellFeatures();
}

View File

@@ -0,0 +1,15 @@
package jxl;
import jxl.biff.BaseCellFeatures;
public class CellFeatures extends BaseCellFeatures {
public CellFeatures() {}
protected CellFeatures(CellFeatures cf) {
super(cf);
}
public String getComment() {
return super.getComment();
}
}

View File

@@ -0,0 +1,5 @@
package jxl;
import jxl.format.CellFormat;
public interface CellFormat extends CellFormat {}

View File

@@ -0,0 +1,63 @@
package jxl;
import jxl.biff.CellReferenceHelper;
import jxl.biff.formula.ExternalSheet;
import jxl.write.WritableWorkbook;
public final class CellReferenceHelper {
public static void getCellReference(int column, int row, StringBuffer buf) {
CellReferenceHelper.getCellReference(column, row, buf);
}
public static void getCellReference(int column, boolean colabs, int row, boolean rowabs, StringBuffer buf) {
CellReferenceHelper.getCellReference(column, colabs, row, rowabs, buf);
}
public static String getCellReference(int column, int row) {
return CellReferenceHelper.getCellReference(column, row);
}
public static int getColumn(String s) {
return CellReferenceHelper.getColumn(s);
}
public static String getColumnReference(int c) {
return CellReferenceHelper.getColumnReference(c);
}
public static int getRow(String s) {
return CellReferenceHelper.getRow(s);
}
public static boolean isColumnRelative(String s) {
return CellReferenceHelper.isColumnRelative(s);
}
public static boolean isRowRelative(String s) {
return CellReferenceHelper.isRowRelative(s);
}
public static void getCellReference(int sheet, int column, int row, Workbook workbook, StringBuffer buf) {
CellReferenceHelper.getCellReference(sheet, column, row, (ExternalSheet)workbook, buf);
}
public static void getCellReference(int sheet, int column, int row, WritableWorkbook workbook, StringBuffer buf) {
CellReferenceHelper.getCellReference(sheet, column, row, (ExternalSheet)workbook, buf);
}
public static void getCellReference(int sheet, int column, boolean colabs, int row, boolean rowabs, Workbook workbook, StringBuffer buf) {
CellReferenceHelper.getCellReference(sheet, column, colabs, row, rowabs, (ExternalSheet)workbook, buf);
}
public static String getCellReference(int sheet, int column, int row, Workbook workbook) {
return CellReferenceHelper.getCellReference(sheet, column, row, (ExternalSheet)workbook);
}
public static String getCellReference(int sheet, int column, int row, WritableWorkbook workbook) {
return CellReferenceHelper.getCellReference(sheet, column, row, (ExternalSheet)workbook);
}
public static String getSheet(String ref) {
return CellReferenceHelper.getSheet(ref);
}
}

35
hrmsEjb/jxl/CellType.java Normal file
View File

@@ -0,0 +1,35 @@
package jxl;
public final class CellType {
private String description;
private CellType(String desc) {
this.description = desc;
}
public String toString() {
return this.description;
}
public static final CellType EMPTY = new CellType("Empty");
public static final CellType LABEL = new CellType("Label");
public static final CellType NUMBER = new CellType("Number");
public static final CellType BOOLEAN = new CellType("Boolean");
public static final CellType ERROR = new CellType("Error");
public static final CellType NUMBER_FORMULA = new CellType("Numerical Formula");
public static final CellType DATE_FORMULA = new CellType("Date Formula");
public static final CellType STRING_FORMULA = new CellType("String Formula");
public static final CellType BOOLEAN_FORMULA = new CellType("Boolean Formula");
public static final CellType FORMULA_ERROR = new CellType("Formula Error");
public static final CellType DATE = new CellType("Date");
}

53
hrmsEjb/jxl/CellView.java Normal file
View File

@@ -0,0 +1,53 @@
package jxl;
import jxl.format.CellFormat;
public final class CellView {
private boolean hidden = false;
private boolean depUsed = false;
private int dimension = 1;
private int size = 1;
private CellFormat format;
public void setHidden(boolean h) {
this.hidden = h;
}
public boolean isHidden() {
return this.hidden;
}
public void setDimension(int d) {
this.dimension = d;
this.depUsed = true;
}
public void setSize(int d) {
this.size = d;
this.depUsed = false;
}
public int getDimension() {
return this.dimension;
}
public int getSize() {
return this.size;
}
public void setFormat(CellFormat cf) {
this.format = cf;
}
public CellFormat getFormat() {
return this.format;
}
public boolean depUsed() {
return this.depUsed;
}
}

12
hrmsEjb/jxl/DateCell.java Normal file
View File

@@ -0,0 +1,12 @@
package jxl;
import java.text.DateFormat;
import java.util.Date;
public interface DateCell extends Cell {
Date getDate();
boolean isTime();
DateFormat getDateFormat();
}

View File

@@ -0,0 +1,3 @@
package jxl;
public interface DateFormulaCell extends DateCell, FormulaCell {}

View File

@@ -0,0 +1,5 @@
package jxl;
public interface ErrorCell extends Cell {
int getErrorCode();
}

View File

@@ -0,0 +1,3 @@
package jxl;
public interface ErrorFormulaCell extends ErrorCell, FormulaCell {}

View File

@@ -0,0 +1,7 @@
package jxl;
import jxl.biff.formula.FormulaException;
public interface FormulaCell extends Cell {
String getFormula() throws FormulaException;
}

View File

@@ -0,0 +1,139 @@
package jxl;
import jxl.biff.HeaderFooter;
public final class HeaderFooter extends HeaderFooter {
public static class Contents extends HeaderFooter.Contents {
Contents() {}
Contents(String s) {
super(s);
}
Contents(Contents copy) {
super(copy);
}
public void append(String txt) {
super.append(txt);
}
public void toggleBold() {
super.toggleBold();
}
public void toggleUnderline() {
super.toggleUnderline();
}
public void toggleItalics() {
super.toggleItalics();
}
public void toggleStrikethrough() {
super.toggleStrikethrough();
}
public void toggleDoubleUnderline() {
super.toggleDoubleUnderline();
}
public void toggleSuperScript() {
super.toggleSuperScript();
}
public void toggleSubScript() {
super.toggleSubScript();
}
public void toggleOutline() {
super.toggleOutline();
}
public void toggleShadow() {
super.toggleShadow();
}
public void setFontName(String fontName) {
super.setFontName(fontName);
}
public boolean setFontSize(int size) {
return super.setFontSize(size);
}
public void appendPageNumber() {
super.appendPageNumber();
}
public void appendTotalPages() {
super.appendTotalPages();
}
public void appendDate() {
super.appendDate();
}
public void appendTime() {
super.appendTime();
}
public void appendWorkbookName() {
super.appendWorkbookName();
}
public void appendWorkSheetName() {
super.appendWorkSheetName();
}
public void clear() {
super.clear();
}
public boolean empty() {
return super.empty();
}
}
public HeaderFooter() {}
public HeaderFooter(HeaderFooter hf) {
super(hf);
}
public HeaderFooter(String s) {
super(s);
}
public String toString() {
return super.toString();
}
public Contents getRight() {
return (Contents)getRightText();
}
public Contents getCentre() {
return (Contents)getCentreText();
}
public Contents getLeft() {
return (Contents)getLeftText();
}
public void clear() {
super.clear();
}
protected HeaderFooter.Contents createContents() {
return new Contents();
}
protected HeaderFooter.Contents createContents(String s) {
return new Contents(s);
}
protected HeaderFooter.Contents createContents(HeaderFooter.Contents c) {
return new Contents((Contents)c);
}
}

View File

@@ -0,0 +1,26 @@
package jxl;
import java.io.File;
import java.net.URL;
public interface Hyperlink {
int getRow();
int getColumn();
Range getRange();
boolean isFile();
boolean isURL();
boolean isLocation();
int getLastRow();
int getLastColumn();
URL getURL();
File getFile();
}

17
hrmsEjb/jxl/Image.java Normal file
View File

@@ -0,0 +1,17 @@
package jxl;
import java.io.File;
public interface Image {
double getColumn();
double getRow();
double getWidth();
double getHeight();
File getImageFile();
byte[] getImageData();
}

View File

@@ -0,0 +1,7 @@
package jxl;
public class JXLException extends Exception {
protected JXLException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,5 @@
package jxl;
public interface LabelCell extends Cell {
String getString();
}

View File

@@ -0,0 +1,9 @@
package jxl;
import java.text.NumberFormat;
public interface NumberCell extends Cell {
double getValue();
NumberFormat getNumberFormat();
}

View File

@@ -0,0 +1,3 @@
package jxl;
public interface NumberFormulaCell extends NumberCell, FormulaCell {}

11
hrmsEjb/jxl/Range.java Normal file
View File

@@ -0,0 +1,11 @@
package jxl;
public interface Range {
Cell getTopLeft();
Cell getBottomRight();
int getFirstSheetIndex();
int getLastSheetIndex();
}

49
hrmsEjb/jxl/Sheet.java Normal file
View File

@@ -0,0 +1,49 @@
package jxl;
import jxl.format.CellFormat;
public interface Sheet {
Cell getCell(int paramInt1, int paramInt2);
Cell getCell(String paramString);
int getRows();
int getColumns();
Cell[] getRow(int paramInt);
Cell[] getColumn(int paramInt);
String getName();
boolean isHidden();
boolean isProtected();
Cell findCell(String paramString);
LabelCell findLabelCell(String paramString);
Hyperlink[] getHyperlinks();
Range[] getMergedCells();
SheetSettings getSettings();
CellFormat getColumnFormat(int paramInt);
int getColumnWidth(int paramInt);
CellView getColumnView(int paramInt);
int getRowHeight(int paramInt);
CellView getRowView(int paramInt);
int getNumberOfImages();
Image getDrawing(int paramInt);
int[] getRowPageBreaks();
}

View File

@@ -0,0 +1,471 @@
package jxl;
import common.Assert;
import jxl.format.PageOrientation;
import jxl.format.PaperSize;
public final class SheetSettings {
private PageOrientation orientation;
private PaperSize paperSize;
private boolean sheetProtected;
private boolean hidden;
private boolean selected;
private HeaderFooter header;
private double headerMargin;
private HeaderFooter footer;
private double footerMargin;
private int scaleFactor;
private int zoomFactor;
private int pageStart;
private int fitWidth;
private int fitHeight;
private int horizontalPrintResolution;
private int verticalPrintResolution;
private double leftMargin;
private double rightMargin;
private double topMargin;
private double bottomMargin;
private boolean fitToPages;
private boolean showGridLines;
private boolean printGridLines;
private boolean printHeaders;
private boolean displayZeroValues;
private String password;
private int passwordHash;
private int defaultColumnWidth;
private int defaultRowHeight;
private int horizontalFreeze;
private int verticalFreeze;
private boolean verticalCentre;
private boolean horizontalCentre;
private int copies;
private boolean automaticFormulaCalculation;
private boolean recalculateFormulasBeforeSave;
private static final PageOrientation defaultOrientation = PageOrientation.PORTRAIT;
private static final PaperSize defaultPaperSize = PaperSize.A4;
private static final double defaultHeaderMargin = 0.5D;
private static final double defaultFooterMargin = 0.5D;
private static final int defaultPrintResolution = 300;
private static final double defaultWidthMargin = 0.75D;
private static final double defaultHeightMargin = 1.0D;
private static final int defaultDefaultColumnWidth = 8;
private static final int defaultZoomFactor = 100;
public static final int DEFAULT_DEFAULT_ROW_HEIGHT = 255;
public SheetSettings() {
this.orientation = defaultOrientation;
this.paperSize = defaultPaperSize;
this.sheetProtected = false;
this.hidden = false;
this.selected = false;
this.headerMargin = 0.5D;
this.footerMargin = 0.5D;
this.horizontalPrintResolution = 300;
this.verticalPrintResolution = 300;
this.leftMargin = 0.75D;
this.rightMargin = 0.75D;
this.topMargin = 1.0D;
this.bottomMargin = 1.0D;
this.fitToPages = false;
this.showGridLines = true;
this.printGridLines = false;
this.printHeaders = false;
this.displayZeroValues = true;
this.defaultColumnWidth = 8;
this.defaultRowHeight = 255;
this.zoomFactor = 100;
this.horizontalFreeze = 0;
this.verticalFreeze = 0;
this.copies = 1;
this.header = new HeaderFooter();
this.footer = new HeaderFooter();
this.automaticFormulaCalculation = true;
this.recalculateFormulasBeforeSave = true;
}
public SheetSettings(SheetSettings copy) {
Assert.verify((copy != null));
this.orientation = copy.orientation;
this.paperSize = copy.paperSize;
this.sheetProtected = copy.sheetProtected;
this.hidden = copy.hidden;
this.selected = false;
this.headerMargin = copy.headerMargin;
this.footerMargin = copy.footerMargin;
this.scaleFactor = copy.scaleFactor;
this.pageStart = copy.pageStart;
this.fitWidth = copy.fitWidth;
this.fitHeight = copy.fitHeight;
this.horizontalPrintResolution = copy.horizontalPrintResolution;
this.verticalPrintResolution = copy.verticalPrintResolution;
this.leftMargin = copy.leftMargin;
this.rightMargin = copy.rightMargin;
this.topMargin = copy.topMargin;
this.bottomMargin = copy.bottomMargin;
this.fitToPages = copy.fitToPages;
this.password = copy.password;
this.passwordHash = copy.passwordHash;
this.defaultColumnWidth = copy.defaultColumnWidth;
this.defaultRowHeight = copy.defaultRowHeight;
this.zoomFactor = copy.zoomFactor;
this.showGridLines = copy.showGridLines;
this.displayZeroValues = copy.displayZeroValues;
this.horizontalFreeze = copy.horizontalFreeze;
this.verticalFreeze = copy.verticalFreeze;
this.horizontalCentre = copy.horizontalCentre;
this.verticalCentre = copy.verticalCentre;
this.copies = copy.copies;
this.header = new HeaderFooter(copy.header);
this.footer = new HeaderFooter(copy.footer);
this.automaticFormulaCalculation = copy.automaticFormulaCalculation;
this.recalculateFormulasBeforeSave = copy.recalculateFormulasBeforeSave;
}
public void setOrientation(PageOrientation po) {
this.orientation = po;
}
public PageOrientation getOrientation() {
return this.orientation;
}
public void setPaperSize(PaperSize ps) {
this.paperSize = ps;
}
public PaperSize getPaperSize() {
return this.paperSize;
}
public boolean isProtected() {
return this.sheetProtected;
}
public void setProtected(boolean p) {
this.sheetProtected = p;
}
public void setHeaderMargin(double d) {
this.headerMargin = d;
}
public double getHeaderMargin() {
return this.headerMargin;
}
public void setFooterMargin(double d) {
this.footerMargin = d;
}
public double getFooterMargin() {
return this.footerMargin;
}
public void setHidden(boolean h) {
this.hidden = h;
}
public boolean isHidden() {
return this.hidden;
}
public void setSelected() {
setSelected(true);
}
public void setSelected(boolean s) {
this.selected = s;
}
public boolean isSelected() {
return this.selected;
}
public void setScaleFactor(int sf) {
this.scaleFactor = sf;
this.fitToPages = false;
}
public int getScaleFactor() {
return this.scaleFactor;
}
public void setPageStart(int ps) {
this.pageStart = ps;
}
public int getPageStart() {
return this.pageStart;
}
public void setFitWidth(int fw) {
this.fitWidth = fw;
this.fitToPages = true;
}
public int getFitWidth() {
return this.fitWidth;
}
public void setFitHeight(int fh) {
this.fitHeight = fh;
this.fitToPages = true;
}
public int getFitHeight() {
return this.fitHeight;
}
public void setHorizontalPrintResolution(int hpw) {
this.horizontalPrintResolution = hpw;
}
public int getHorizontalPrintResolution() {
return this.horizontalPrintResolution;
}
public void setVerticalPrintResolution(int vpw) {
this.verticalPrintResolution = vpw;
}
public int getVerticalPrintResolution() {
return this.verticalPrintResolution;
}
public void setRightMargin(double m) {
this.rightMargin = m;
}
public double getRightMargin() {
return this.rightMargin;
}
public void setLeftMargin(double m) {
this.leftMargin = m;
}
public double getLeftMargin() {
return this.leftMargin;
}
public void setTopMargin(double m) {
this.topMargin = m;
}
public double getTopMargin() {
return this.topMargin;
}
public void setBottomMargin(double m) {
this.bottomMargin = m;
}
public double getBottomMargin() {
return this.bottomMargin;
}
public double getDefaultWidthMargin() {
return 0.75D;
}
public double getDefaultHeightMargin() {
return 1.0D;
}
public boolean getFitToPages() {
return this.fitToPages;
}
public void setFitToPages(boolean b) {
this.fitToPages = b;
}
public String getPassword() {
return this.password;
}
public void setPassword(String s) {
this.password = s;
}
public int getPasswordHash() {
return this.passwordHash;
}
public void setPasswordHash(int ph) {
this.passwordHash = ph;
}
public int getDefaultColumnWidth() {
return this.defaultColumnWidth;
}
public void setDefaultColumnWidth(int w) {
this.defaultColumnWidth = w;
}
public int getDefaultRowHeight() {
return this.defaultRowHeight;
}
public void setDefaultRowHeight(int h) {
this.defaultRowHeight = h;
}
public int getZoomFactor() {
return this.zoomFactor;
}
public void setZoomFactor(int zf) {
this.zoomFactor = zf;
}
public boolean getDisplayZeroValues() {
return this.displayZeroValues;
}
public void setDisplayZeroValues(boolean b) {
this.displayZeroValues = b;
}
public boolean getShowGridLines() {
return this.showGridLines;
}
public void setShowGridLines(boolean b) {
this.showGridLines = b;
}
public boolean getPrintGridLines() {
return this.printGridLines;
}
public void setPrintGridLines(boolean b) {
this.printGridLines = b;
}
public boolean getPrintHeaders() {
return this.printHeaders;
}
public void setPrintHeaders(boolean b) {
this.printHeaders = b;
}
public int getHorizontalFreeze() {
return this.horizontalFreeze;
}
public void setHorizontalFreeze(int row) {
this.horizontalFreeze = Math.max(row, 0);
}
public int getVerticalFreeze() {
return this.verticalFreeze;
}
public void setVerticalFreeze(int col) {
this.verticalFreeze = Math.max(col, 0);
}
public void setCopies(int c) {
this.copies = c;
}
public int getCopies() {
return this.copies;
}
public HeaderFooter getHeader() {
return this.header;
}
public void setHeader(HeaderFooter h) {
this.header = h;
}
public void setFooter(HeaderFooter f) {
this.footer = f;
}
public HeaderFooter getFooter() {
return this.footer;
}
public boolean isHorizontalCentre() {
return this.horizontalCentre;
}
public void setHorizontalCentre(boolean horizontalCentre) {
this.horizontalCentre = horizontalCentre;
}
public boolean isVerticalCentre() {
return this.verticalCentre;
}
public void setVerticalCentre(boolean verticalCentre) {
this.verticalCentre = verticalCentre;
}
public void setAutomaticFormulaCalculation(boolean auto) {
this.automaticFormulaCalculation = auto;
}
public boolean getAutomaticFormulaCalculation() {
return this.automaticFormulaCalculation;
}
public void setRecalculateFormulasBeforeSave(boolean recalc) {
this.recalculateFormulasBeforeSave = recalc;
}
public boolean getRecalculateFormulasBeforeSave() {
return this.recalculateFormulasBeforeSave;
}
}

View File

@@ -0,0 +1,3 @@
package jxl;
public interface StringFormulaCell extends LabelCell, FormulaCell {}

113
hrmsEjb/jxl/Workbook.java Normal file
View File

@@ -0,0 +1,113 @@
package jxl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import jxl.read.biff.BiffException;
import jxl.read.biff.File;
import jxl.read.biff.PasswordException;
import jxl.read.biff.WorkbookParser;
import jxl.write.WritableWorkbook;
import jxl.write.biff.WritableWorkbookImpl;
public abstract class Workbook {
private static final String version = "2.5.9";
public abstract Sheet[] getSheets();
public abstract String[] getSheetNames();
public abstract Sheet getSheet(int paramInt) throws IndexOutOfBoundsException;
public abstract Sheet getSheet(String paramString);
public static String getVersion() {
return "2.5.9";
}
public abstract int getNumberOfSheets();
public abstract Cell findCellByName(String paramString);
public abstract Cell getCell(String paramString);
public abstract Range[] findByName(String paramString);
public abstract String[] getRangeNames();
public abstract boolean isProtected();
protected abstract void parse() throws BiffException, PasswordException;
public abstract void close();
public static Workbook getWorkbook(File file) throws IOException, BiffException {
return getWorkbook(file, new WorkbookSettings());
}
public static Workbook getWorkbook(File file, WorkbookSettings ws) throws IOException, BiffException {
FileInputStream fis = new FileInputStream(file);
File dataFile = null;
try {
dataFile = new File(fis, ws);
} catch (IOException e) {
fis.close();
throw e;
} catch (BiffException e) {
fis.close();
throw e;
}
fis.close();
WorkbookParser workbookParser = new WorkbookParser(dataFile, ws);
workbookParser.parse();
return (Workbook)workbookParser;
}
public static Workbook getWorkbook(InputStream is) throws IOException, BiffException {
return getWorkbook(is, new WorkbookSettings());
}
public static Workbook getWorkbook(InputStream is, WorkbookSettings ws) throws IOException, BiffException {
File dataFile = new File(is, ws);
WorkbookParser workbookParser = new WorkbookParser(dataFile, ws);
workbookParser.parse();
return (Workbook)workbookParser;
}
public static WritableWorkbook createWorkbook(File file) throws IOException {
return createWorkbook(file, new WorkbookSettings());
}
public static WritableWorkbook createWorkbook(File file, WorkbookSettings ws) throws IOException {
FileOutputStream fos = new FileOutputStream(file);
return (WritableWorkbook)new WritableWorkbookImpl(fos, true, ws);
}
public static WritableWorkbook createWorkbook(File file, Workbook in) throws IOException {
return createWorkbook(file, in, new WorkbookSettings());
}
public static WritableWorkbook createWorkbook(File file, Workbook in, WorkbookSettings ws) throws IOException {
FileOutputStream fos = new FileOutputStream(file);
return (WritableWorkbook)new WritableWorkbookImpl(fos, in, true, ws);
}
public static WritableWorkbook createWorkbook(OutputStream os, Workbook in) throws IOException {
return createWorkbook(os, in, ((WorkbookParser)in).getSettings());
}
public static WritableWorkbook createWorkbook(OutputStream os, Workbook in, WorkbookSettings ws) throws IOException {
return (WritableWorkbook)new WritableWorkbookImpl(os, in, false, ws);
}
public static WritableWorkbook createWorkbook(OutputStream os) throws IOException {
return createWorkbook(os, new WorkbookSettings());
}
public static WritableWorkbook createWorkbook(OutputStream os, WorkbookSettings ws) throws IOException {
return (WritableWorkbook)new WritableWorkbookImpl(os, false, ws);
}
}

View File

@@ -0,0 +1,214 @@
package jxl;
import common.Logger;
import java.util.HashMap;
import java.util.Locale;
import jxl.biff.CountryCode;
import jxl.biff.formula.FunctionNames;
public final class WorkbookSettings {
private static Logger logger = Logger.getLogger(WorkbookSettings.class);
private int initialFileSize = 5242880;
private int arrayGrowSize = 1048576;
private HashMap localeFunctionNames = new HashMap();
private String excelDisplayLanguage = CountryCode.USA.getCode();
private String excelRegionalSettings = CountryCode.UK.getCode();
private boolean drawingsDisabled;
private boolean namesDisabled;
private boolean formulaReferenceAdjustDisabled;
private boolean gcDisabled;
private boolean rationalizationDisabled;
private boolean mergedCellCheckingDisabled;
private boolean propertySetsDisabled;
private boolean ignoreBlankCells;
private Locale locale;
private FunctionNames functionNames;
private String encoding;
private int characterSet;
private static final int defaultInitialFileSize = 5242880;
private static final int defaultArrayGrowSize = 1048576;
public WorkbookSettings() {
try {
boolean suppressWarnings = Boolean.getBoolean("jxl.nowarnings");
setSuppressWarnings(suppressWarnings);
this.drawingsDisabled = Boolean.getBoolean("jxl.nodrawings");
this.namesDisabled = Boolean.getBoolean("jxl.nonames");
this.gcDisabled = Boolean.getBoolean("jxl.nogc");
this.rationalizationDisabled = Boolean.getBoolean("jxl.norat");
this.mergedCellCheckingDisabled = Boolean.getBoolean("jxl.nomergedcellchecks");
this.formulaReferenceAdjustDisabled = Boolean.getBoolean("jxl.noformulaadjust");
this.propertySetsDisabled = Boolean.getBoolean("jxl.nopropertysets");
this.ignoreBlankCells = Boolean.getBoolean("jxl.ignoreblanks");
this.encoding = System.getProperty("file.encoding");
} catch (SecurityException e) {
logger.warn("Error accessing system properties.", e);
}
try {
if (System.getProperty("jxl.lang") == null || System.getProperty("jxl.country") == null) {
this.locale = Locale.getDefault();
} else {
this.locale = new Locale(System.getProperty("jxl.lang"), System.getProperty("jxl.country"));
}
if (System.getProperty("jxl.encoding") != null)
this.encoding = System.getProperty("jxl.encoding");
} catch (SecurityException e) {
logger.warn("Error accessing system properties.", e);
this.locale = Locale.getDefault();
}
}
public void setArrayGrowSize(int sz) {
this.arrayGrowSize = sz;
}
public int getArrayGrowSize() {
return this.arrayGrowSize;
}
public void setInitialFileSize(int sz) {
this.initialFileSize = sz;
}
public int getInitialFileSize() {
return this.initialFileSize;
}
public boolean getDrawingsDisabled() {
return this.drawingsDisabled;
}
public boolean getGCDisabled() {
return this.gcDisabled;
}
public boolean getNamesDisabled() {
return this.namesDisabled;
}
public void setNamesDisabled(boolean b) {
this.namesDisabled = b;
}
public void setDrawingsDisabled(boolean b) {
this.drawingsDisabled = b;
}
public void setRationalization(boolean r) {
this.rationalizationDisabled = !r;
}
public boolean getRationalizationDisabled() {
return this.rationalizationDisabled;
}
public boolean getMergedCellCheckingDisabled() {
return this.mergedCellCheckingDisabled;
}
public void setMergedCellChecking(boolean b) {
this.mergedCellCheckingDisabled = !b;
}
public void setPropertySets(boolean r) {
this.propertySetsDisabled = !r;
}
public boolean getPropertySetsDisabled() {
return this.propertySetsDisabled;
}
public void setSuppressWarnings(boolean w) {
logger.setSuppressWarnings(w);
}
public boolean getFormulaAdjust() {
return !this.formulaReferenceAdjustDisabled;
}
public void setFormulaAdjust(boolean b) {
this.formulaReferenceAdjustDisabled = !b;
}
public void setLocale(Locale l) {
this.locale = l;
}
public Locale getLocale() {
return this.locale;
}
public String getEncoding() {
return this.encoding;
}
public void setEncoding(String enc) {
this.encoding = enc;
}
public FunctionNames getFunctionNames() {
if (this.functionNames == null) {
this.functionNames = (FunctionNames)this.localeFunctionNames.get(this.locale);
if (this.functionNames == null) {
this.functionNames = new FunctionNames(this.locale);
this.localeFunctionNames.put(this.locale, this.functionNames);
}
}
return this.functionNames;
}
public int getCharacterSet() {
return this.characterSet;
}
public void setCharacterSet(int cs) {
this.characterSet = cs;
}
public void setGCDisabled(boolean disabled) {
this.gcDisabled = disabled;
}
public void setIgnoreBlanks(boolean ignoreBlanks) {
this.ignoreBlankCells = ignoreBlanks;
}
public boolean getIgnoreBlanks() {
return this.ignoreBlankCells;
}
public String getExcelDisplayLanguage() {
return this.excelDisplayLanguage;
}
public String getExcelRegionalSettings() {
return this.excelRegionalSettings;
}
public void setExcelDisplayLanguage(String code) {
this.excelDisplayLanguage = code;
}
public void setExcelRegionalSettings(String code) {
this.excelRegionalSettings = code;
}
}

View File

@@ -0,0 +1,84 @@
package jxl.biff;
import common.Logger;
import jxl.biff.drawing.Comment;
import jxl.write.biff.CellValue;
public class BaseCellFeatures {
public static Logger logger = Logger.getLogger(BaseCellFeatures.class);
private String comment;
private double commentWidth;
private double commentHeight;
private Comment commentDrawing;
private CellValue writableCell;
private static final double defaultCommentWidth = 3.0D;
private static final double defaultCommentHeight = 4.0D;
protected BaseCellFeatures() {}
public BaseCellFeatures(BaseCellFeatures cf) {
this.comment = cf.comment;
this.commentWidth = cf.commentWidth;
this.commentHeight = cf.commentHeight;
}
protected String getComment() {
return this.comment;
}
public double getCommentWidth() {
return this.commentWidth;
}
public double getCommentHeight() {
return this.commentHeight;
}
public final void setWritableCell(CellValue wc) {
this.writableCell = wc;
}
public void setReadComment(String s, double w, double h) {
this.comment = s;
this.commentWidth = w;
this.commentHeight = h;
}
public void setComment(String s) {
setComment(s, 3.0D, 4.0D);
}
public void setComment(String s, double width, double height) {
this.comment = s;
this.commentWidth = width;
this.commentHeight = height;
if (this.commentDrawing != null) {
this.commentDrawing.setCommentText(s);
this.commentDrawing.setWidth(width);
this.commentDrawing.setWidth(height);
}
}
public void removeComment() {
this.comment = null;
if (this.commentDrawing != null) {
this.writableCell.removeComment(this.commentDrawing);
this.commentDrawing = null;
}
}
public final void setCommentDrawing(Comment c) {
this.commentDrawing = c;
}
public final Comment getCommentDrawing() {
return this.commentDrawing;
}
}

View File

@@ -0,0 +1,158 @@
package jxl.biff;
import common.Assert;
import common.Logger;
public abstract class BaseCompoundFile {
private static Logger logger = Logger.getLogger(BaseCompoundFile.class);
protected static final byte[] IDENTIFIER = new byte[] { -48, -49, 17, -32, -95, -79, 26, -31 };
protected static final int NUM_BIG_BLOCK_DEPOT_BLOCKS_POS = 44;
protected static final int SMALL_BLOCK_DEPOT_BLOCK_POS = 60;
protected static final int NUM_SMALL_BLOCK_DEPOT_BLOCKS_POS = 64;
protected static final int ROOT_START_BLOCK_POS = 48;
protected static final int BIG_BLOCK_SIZE = 512;
protected static final int SMALL_BLOCK_SIZE = 64;
protected static final int EXTENSION_BLOCK_POS = 68;
protected static final int NUM_EXTENSION_BLOCK_POS = 72;
protected static final int PROPERTY_STORAGE_BLOCK_SIZE = 128;
protected static final int BIG_BLOCK_DEPOT_BLOCKS_POS = 76;
protected static final int SMALL_BLOCK_THRESHOLD = 4096;
private static final int SIZE_OF_NAME_POS = 64;
private static final int TYPE_POS = 66;
private static final int COLOUR_POS = 67;
private static final int PREVIOUS_POS = 68;
private static final int NEXT_POS = 72;
private static final int CHILD_POS = 76;
private static final int START_BLOCK_POS = 116;
private static final int SIZE_POS = 120;
public static final String ROOT_ENTRY_NAME = "Root Entry";
public static final String WORKBOOK_NAME = "Workbook";
public static final String SUMMARY_INFORMATION_NAME = "\005SummaryInformation";
public static final String DOCUMENT_SUMMARY_INFORMATION_NAME = "\005DocumentSummaryInformation";
public static final String COMP_OBJ_NAME = "\001CompObj";
public static final String[] STANDARD_PROPERTY_SETS = new String[] { "Root Entry", "Workbook", "\005SummaryInformation", "\005DocumentSummaryInformation" };
public static final int NONE_PS_TYPE = 0;
public static final int DIRECTORY_PS_TYPE = 1;
public static final int FILE_PS_TYPE = 2;
public static final int ROOT_ENTRY_PS_TYPE = 5;
public class PropertyStorage {
public String name;
public int type;
public int colour;
public int startBlock;
public int size;
public int previous;
public int next;
public int child;
public byte[] data;
private final BaseCompoundFile this$0;
public PropertyStorage(BaseCompoundFile this$0, byte[] d) {
this.this$0 = this$0;
this.data = d;
int nameSize = IntegerHelper.getInt(this.data[64], this.data[65]);
if (nameSize > 64) {
BaseCompoundFile.logger.warn("property set name exceeds max length - truncating");
nameSize = 64;
}
this.type = this.data[66];
this.colour = this.data[67];
this.startBlock = IntegerHelper.getInt(this.data[116], this.data[117], this.data[118], this.data[119]);
this.size = IntegerHelper.getInt(this.data[120], this.data[121], this.data[122], this.data[123]);
this.previous = IntegerHelper.getInt(this.data[68], this.data[69], this.data[70], this.data[71]);
this.next = IntegerHelper.getInt(this.data[72], this.data[73], this.data[74], this.data[75]);
this.child = IntegerHelper.getInt(this.data[76], this.data[77], this.data[78], this.data[79]);
int chars = 0;
if (nameSize > 2)
chars = (nameSize - 1) / 2;
StringBuffer n = new StringBuffer("");
for (int i = 0; i < chars; i++)
n.append((char)this.data[i * 2]);
this.name = n.toString();
}
public PropertyStorage(BaseCompoundFile this$0, String name) {
this.this$0 = this$0;
this.data = new byte[128];
Assert.verify((name.length() < 32));
IntegerHelper.getTwoBytes((name.length() + 1) * 2, this.data, 64);
for (int i = 0; i < name.length(); i++)
this.data[i * 2] = (byte)name.charAt(i);
}
public void setType(int t) {
this.type = t;
this.data[66] = (byte)t;
}
public void setStartBlock(int sb) {
this.startBlock = sb;
IntegerHelper.getFourBytes(sb, this.data, 116);
}
public void setSize(int s) {
this.size = s;
IntegerHelper.getFourBytes(s, this.data, 120);
}
public void setPrevious(int prev) {
this.previous = prev;
IntegerHelper.getFourBytes(prev, this.data, 68);
}
public void setNext(int nxt) {
this.next = nxt;
IntegerHelper.getFourBytes(this.next, this.data, 72);
}
public void setChild(int dir) {
this.child = dir;
IntegerHelper.getFourBytes(this.child, this.data, 76);
}
public void setColour(int col) {
this.colour = (col == 0) ? 0 : 1;
this.data[67] = (byte)this.colour;
}
}
}

View File

@@ -0,0 +1,82 @@
package jxl.biff;
import jxl.format.Format;
final class BuiltInFormat implements Format, DisplayFormat {
private String formatString;
private int formatIndex;
private BuiltInFormat(String s, int i) {
this.formatIndex = i;
this.formatString = s;
}
public String getFormatString() {
return this.formatString;
}
public int getFormatIndex() {
return this.formatIndex;
}
public boolean isInitialized() {
return true;
}
public void initialize(int pos) {}
public boolean isBuiltIn() {
return true;
}
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof BuiltInFormat))
return false;
BuiltInFormat bif = (BuiltInFormat)o;
return (this.formatIndex == bif.formatIndex);
}
public static BuiltInFormat[] builtIns = new BuiltInFormat[50];
static {
builtIns[0] = new BuiltInFormat("", 0);
builtIns[1] = new BuiltInFormat("0", 1);
builtIns[2] = new BuiltInFormat("0.00", 2);
builtIns[3] = new BuiltInFormat("#,##0", 3);
builtIns[4] = new BuiltInFormat("#,##0.00", 4);
builtIns[5] = new BuiltInFormat("($#,##0_);($#,##0)", 5);
builtIns[6] = new BuiltInFormat("($#,##0_);[Red]($#,##0)", 6);
builtIns[7] = new BuiltInFormat("($#,##0_);[Red]($#,##0)", 7);
builtIns[8] = new BuiltInFormat("($#,##0.00_);[Red]($#,##0.00)", 8);
builtIns[9] = new BuiltInFormat("0%", 9);
builtIns[10] = new BuiltInFormat("0.00%", 10);
builtIns[11] = new BuiltInFormat("0.00E+00", 11);
builtIns[12] = new BuiltInFormat("# ?/?", 12);
builtIns[13] = new BuiltInFormat("# ??/??", 13);
builtIns[14] = new BuiltInFormat("dd/mm/yyyy", 14);
builtIns[15] = new BuiltInFormat("d-mmm-yy", 15);
builtIns[16] = new BuiltInFormat("d-mmm", 16);
builtIns[17] = new BuiltInFormat("mmm-yy", 17);
builtIns[18] = new BuiltInFormat("h:mm AM/PM", 18);
builtIns[19] = new BuiltInFormat("h:mm:ss AM/PM", 19);
builtIns[20] = new BuiltInFormat("h:mm", 20);
builtIns[21] = new BuiltInFormat("h:mm:ss", 21);
builtIns[22] = new BuiltInFormat("m/d/yy h:mm", 22);
builtIns[37] = new BuiltInFormat("(#,##0_);(#,##0)", 37);
builtIns[38] = new BuiltInFormat("(#,##0_);[Red](#,##0)", 38);
builtIns[39] = new BuiltInFormat("(#,##0.00_);(#,##0.00)", 39);
builtIns[40] = new BuiltInFormat("(#,##0.00_);[Red](#,##0.00)", 40);
builtIns[41] = new BuiltInFormat("_(*#,##0_);_(*(#,##0);_(*\"-\"_);(@_)", 41);
builtIns[42] = new BuiltInFormat("_($*#,##0_);_($*(#,##0);_($*\"-\"_);(@_)", 42);
builtIns[43] = new BuiltInFormat("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);(@_)", 43);
builtIns[44] = new BuiltInFormat("_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);(@_)", 44);
builtIns[45] = new BuiltInFormat("mm:ss", 45);
builtIns[46] = new BuiltInFormat("[h]mm:ss", 46);
builtIns[47] = new BuiltInFormat("mm:ss.0", 47);
builtIns[48] = new BuiltInFormat("##0.0E+0", 48);
builtIns[49] = new BuiltInFormat("@", 49);
}
}

View File

@@ -0,0 +1,22 @@
package jxl.biff;
class BuiltInStyle extends WritableRecordData {
private int xfIndex;
private int styleNumber;
public BuiltInStyle(int xfind, int sn) {
super(Type.STYLE);
this.xfIndex = xfind;
this.styleNumber = sn;
}
public byte[] getData() {
byte[] data = new byte[4];
IntegerHelper.getTwoBytes(this.xfIndex, data, 0);
data[1] = (byte)(data[1] | 0x80);
data[2] = (byte)this.styleNumber;
data[3] = -1;
return data;
}
}

View File

@@ -0,0 +1,47 @@
package jxl.biff;
public class ByteArray {
private int growSize;
private byte[] bytes;
private int pos;
private static final int defaultGrowSize = 1024;
public ByteArray() {
this(1024);
}
public ByteArray(int gs) {
this.growSize = gs;
this.bytes = new byte[1024];
this.pos = 0;
}
public void add(byte b) {
checkSize(1);
this.bytes[this.pos] = b;
this.pos++;
}
public void add(byte[] b) {
checkSize(b.length);
System.arraycopy(b, 0, this.bytes, this.pos, b.length);
this.pos += b.length;
}
public byte[] getBytes() {
byte[] returnArray = new byte[this.pos];
System.arraycopy(this.bytes, 0, returnArray, 0, this.pos);
return returnArray;
}
private void checkSize(int sz) {
while (this.pos + sz >= this.bytes.length) {
byte[] newArray = new byte[this.bytes.length + this.growSize];
System.arraycopy(this.bytes, 0, newArray, 0, this.pos);
this.bytes = newArray;
}
}
}

View File

@@ -0,0 +1,5 @@
package jxl.biff;
public interface ByteData {
byte[] getBytes();
}

View File

@@ -0,0 +1,137 @@
package jxl.biff;
import common.Logger;
import jxl.biff.formula.ExternalSheet;
public final class CellReferenceHelper {
private static Logger logger = Logger.getLogger(CellReferenceHelper.class);
private static final char fixedInd = '$';
private static final char sheetInd = '!';
public static void getCellReference(int column, int row, StringBuffer buf) {
getColumnReference(column, buf);
buf.append(Integer.toString(row + 1));
}
public static void getCellReference(int column, boolean colabs, int row, boolean rowabs, StringBuffer buf) {
if (colabs)
buf.append('$');
getColumnReference(column, buf);
if (rowabs)
buf.append('$');
buf.append(Integer.toString(row + 1));
}
public static String getColumnReference(int column) {
StringBuffer buf = new StringBuffer();
getColumnReference(column, buf);
return buf.toString();
}
public static void getColumnReference(int column, StringBuffer buf) {
int v = column / 26;
int r = column % 26;
StringBuffer tmp = new StringBuffer();
while (v != 0) {
char c = (char)(65 + r);
tmp.append(c);
r = v % 26 - 1;
v /= 26;
}
char col = (char)(65 + r);
tmp.append(col);
for (int i = tmp.length() - 1; i >= 0; i--)
buf.append(tmp.charAt(i));
}
public static void getCellReference(int sheet, int column, int row, ExternalSheet workbook, StringBuffer buf) {
buf.append('\'');
String name = workbook.getExternalSheetName(sheet);
buf.append(StringHelper.replace(name, "'", "''"));
buf.append(name);
buf.append('\'');
buf.append('!');
getCellReference(column, row, buf);
}
public static void getCellReference(int sheet, int column, boolean colabs, int row, boolean rowabs, ExternalSheet workbook, StringBuffer buf) {
buf.append('\'');
String name = workbook.getExternalSheetName(sheet);
buf.append(StringHelper.replace(name, "'", "''"));
buf.append(name);
buf.append('\'');
buf.append('!');
getCellReference(column, colabs, row, rowabs, buf);
}
public static String getCellReference(int sheet, int column, int row, ExternalSheet workbook) {
StringBuffer sb = new StringBuffer();
getCellReference(sheet, column, row, workbook, sb);
return sb.toString();
}
public static String getCellReference(int column, int row) {
StringBuffer buf = new StringBuffer();
getCellReference(column, row, buf);
return buf.toString();
}
public static int getColumn(String s) {
int colnum = 0;
int numindex = getNumberIndex(s);
String s2 = s.toUpperCase();
int startPos = s.lastIndexOf('!') + 1;
if (s.charAt(startPos) == '$')
startPos++;
int endPos = numindex;
if (s.charAt(numindex - 1) == '$')
endPos--;
for (int i = startPos; i < endPos; i++) {
if (i != startPos)
colnum = (colnum + 1) * 26;
colnum += s2.charAt(i) - 65;
}
return colnum;
}
public static int getRow(String s) {
try {
return Integer.parseInt(s.substring(getNumberIndex(s))) - 1;
} catch (NumberFormatException e) {
logger.warn(e, e);
return 65535;
}
}
private static int getNumberIndex(String s) {
boolean numberFound = false;
int pos = s.lastIndexOf('!') + 1;
char c = Character.MIN_VALUE;
while (!numberFound && pos < s.length()) {
c = s.charAt(pos);
if (c >= '0' && c <= '9') {
numberFound = true;
continue;
}
pos++;
}
return pos;
}
public static boolean isColumnRelative(String s) {
return (s.charAt(0) != '$');
}
public static boolean isRowRelative(String s) {
return (s.charAt(getNumberIndex(s) - 1) != '$');
}
public static String getSheet(String ref) {
int sheetPos = ref.lastIndexOf('!');
if (sheetPos == -1)
return "";
return ref.substring(0, sheetPos);
}
}

View File

@@ -0,0 +1,21 @@
package jxl.biff;
import jxl.read.biff.Record;
public class ContinueRecord extends WritableRecordData {
private byte[] data;
public ContinueRecord(Record t) {
super(t);
this.data = t.getData();
}
public ContinueRecord(byte[] d) {
super(Type.CONTINUE);
this.data = d;
}
public byte[] getData() {
return this.data;
}
}

View File

@@ -0,0 +1,92 @@
package jxl.biff;
import common.Logger;
public class CountryCode {
private static Logger logger = Logger.getLogger(CountryCode.class);
private int value;
private String code;
private String description;
private static CountryCode[] codes = new CountryCode[0];
private CountryCode(int v, String c, String d) {
this.value = v;
this.code = c;
this.description = d;
CountryCode[] newcodes = new CountryCode[codes.length + 1];
System.arraycopy(codes, 0, newcodes, 0, codes.length);
newcodes[codes.length] = this;
codes = newcodes;
}
private CountryCode(int v) {
this.value = v;
this.description = "Arbitrary";
this.code = "??";
}
public int getValue() {
return this.value;
}
public String getCode() {
return this.code;
}
public static CountryCode getCountryCode(String s) {
if (s == null || s.length() != 2) {
logger.warn("Please specify two character ISO 3166 country code");
return USA;
}
CountryCode code = UNKNOWN;
for (int i = 0; i < codes.length && code == UNKNOWN; i++) {
if ((codes[i]).code.equals(s))
code = codes[i];
}
return code;
}
public static CountryCode createArbitraryCode(int i) {
return new CountryCode(i);
}
public static final CountryCode USA = new CountryCode(1, "US", "USA");
public static final CountryCode CANADA = new CountryCode(2, "CA", "Canada");
public static final CountryCode GREECE = new CountryCode(30, "GR", "Greece");
public static final CountryCode NETHERLANDS = new CountryCode(31, "NE", "Netherlands");
public static final CountryCode BELGIUM = new CountryCode(32, "BE", "Belgium");
public static final CountryCode FRANCE = new CountryCode(33, "FR", "France");
public static final CountryCode SPAIN = new CountryCode(34, "ES", "Spain");
public static final CountryCode ITALY = new CountryCode(39, "IT", "Italy");
public static final CountryCode SWITZERLAND = new CountryCode(41, "CH", "Switzerland");
public static final CountryCode UK = new CountryCode(44, "UK", "United Kingdowm");
public static final CountryCode DENMARK = new CountryCode(45, "DK", "Denmark");
public static final CountryCode SWEDEN = new CountryCode(46, "SE", "Sweden");
public static final CountryCode NORWAY = new CountryCode(47, "NO", "Norway");
public static final CountryCode GERMANY = new CountryCode(49, "DE", "Germany");
public static final CountryCode PHILIPPINES = new CountryCode(63, "PH", "Philippines");
public static final CountryCode CHINA = new CountryCode(86, "CN", "China");
public static final CountryCode INDIA = new CountryCode(91, "IN", "India");
public static final CountryCode UNKNOWN = new CountryCode(65535, "??", "Unknown");
}

View File

@@ -0,0 +1,351 @@
package jxl.biff;
import common.Logger;
import jxl.WorkbookSettings;
import jxl.biff.formula.ExternalSheet;
import jxl.biff.formula.FormulaException;
import jxl.biff.formula.FormulaParser;
public class DVParser {
private static Logger logger = Logger.getLogger(DVParser.class);
public static class DVType {
private int value;
private static DVType[] types = new DVType[0];
DVType(int v) {
this.value = v;
DVType[] oldtypes = types;
types = new DVType[oldtypes.length + 1];
System.arraycopy(oldtypes, 0, types, 0, oldtypes.length);
types[oldtypes.length] = this;
}
static DVType getType(int v) {
DVType found = null;
for (int i = 0; i < types.length && found == null; i++) {
if ((types[i]).value == v)
found = types[i];
}
return found;
}
public int getValue() {
return this.value;
}
}
public static class ErrorStyle {
private int value;
private static ErrorStyle[] types = new ErrorStyle[0];
ErrorStyle(int v) {
this.value = v;
ErrorStyle[] oldtypes = types;
types = new ErrorStyle[oldtypes.length + 1];
System.arraycopy(oldtypes, 0, types, 0, oldtypes.length);
types[oldtypes.length] = this;
}
static ErrorStyle getErrorStyle(int v) {
ErrorStyle found = null;
for (int i = 0; i < types.length && found == null; i++) {
if ((types[i]).value == v)
found = types[i];
}
return found;
}
public int getValue() {
return this.value;
}
}
public static class Condition {
private int value;
private static Condition[] types = new Condition[0];
Condition(int v) {
this.value = v;
Condition[] oldtypes = types;
types = new Condition[oldtypes.length + 1];
System.arraycopy(oldtypes, 0, types, 0, oldtypes.length);
types[oldtypes.length] = this;
}
static Condition getCondition(int v) {
Condition found = null;
for (int i = 0; i < types.length && found == null; i++) {
if ((types[i]).value == v)
found = types[i];
}
return found;
}
public int getValue() {
return this.value;
}
}
public static final DVType ANY = new DVType(0);
public static final DVType INTEGER = new DVType(1);
public static final DVType DECIMAL = new DVType(2);
public static final DVType LIST = new DVType(3);
public static final DVType DATE = new DVType(4);
public static final DVType TIME = new DVType(5);
public static final DVType TEXT_LENGTH = new DVType(6);
public static final DVType FORMULA = new DVType(7);
public static final ErrorStyle STOP = new ErrorStyle(0);
public static final ErrorStyle WARNING = new ErrorStyle(1);
public static final ErrorStyle INFO = new ErrorStyle(2);
public static final Condition BETWEEN = new Condition(0);
public static final Condition NOT_BETWEEN = new Condition(1);
public static final Condition EQUAL = new Condition(2);
public static final Condition NOT_EQUAL = new Condition(3);
public static final Condition GREATER_THAN = new Condition(4);
public static final Condition LESS_THAN = new Condition(5);
public static final Condition GREATER_EQUAL = new Condition(6);
public static final Condition LESS_EQUAL = new Condition(7);
private static int STRING_LIST_GIVEN_MASK = 128;
private static int EMPTY_CELLS_ALLOWED_MASK = 256;
private static int SUPPRESS_ARROW_MASK = 512;
private static int SHOW_PROMPT_MASK = 262144;
private static int SHOW_ERROR_MASK = 524288;
private DVType type;
private ErrorStyle errorStyle;
private Condition condition;
private boolean stringListGiven;
private boolean emptyCellsAllowed;
private boolean suppressArrow;
private boolean showPrompt;
private boolean showError;
private String promptTitle;
private String errorTitle;
private String promptText;
private String errorText;
private FormulaParser formula1;
private FormulaParser formula2;
private int column1;
private int row1;
private int column2;
private int row2;
public DVParser(byte[] data, ExternalSheet es, WorkbookMethods nt, WorkbookSettings ws) throws FormulaException {
int options = IntegerHelper.getInt(data[0], data[1], data[2], data[3]);
int typeVal = options & 0xF;
this.type = DVType.getType(typeVal);
int errorStyleVal = (options & 0x70) >> 4;
this.errorStyle = ErrorStyle.getErrorStyle(errorStyleVal);
int conditionVal = (options & 0xF00000) >> 20;
this.condition = Condition.getCondition(conditionVal);
this.stringListGiven = ((options & STRING_LIST_GIVEN_MASK) != 0);
this.emptyCellsAllowed = ((options & EMPTY_CELLS_ALLOWED_MASK) != 0);
this.suppressArrow = ((options & SUPPRESS_ARROW_MASK) != 0);
this.showPrompt = ((options & SHOW_PROMPT_MASK) != 0);
this.showError = ((options & SHOW_ERROR_MASK) != 0);
int pos = 4;
int length = IntegerHelper.getInt(data[pos], data[pos + 1]);
this.promptTitle = StringHelper.getUnicodeString(data, length, pos + 2);
pos += length * 2 + 2;
length = IntegerHelper.getInt(data[pos], data[pos + 1]);
this.errorTitle = StringHelper.getUnicodeString(data, length, pos + 2);
pos += length * 2 + 2;
length = IntegerHelper.getInt(data[pos], data[pos + 1]);
this.promptText = StringHelper.getUnicodeString(data, length, pos + 2);
pos += length * 2 + 2;
length = IntegerHelper.getInt(data[pos], data[pos + 1]);
this.errorText = StringHelper.getUnicodeString(data, length, pos + 2);
pos += length * 2 + 2;
int formulaLength = IntegerHelper.getInt(data[pos], data[pos + 1]);
pos += 4;
if (formulaLength != 0) {
byte[] tokens = new byte[formulaLength];
System.arraycopy(data, pos, tokens, 0, formulaLength);
this.formula1 = new FormulaParser(tokens, null, es, nt, ws);
this.formula1.parse();
pos += formulaLength;
}
formulaLength = IntegerHelper.getInt(data[pos], data[pos + 1]);
pos += 4;
if (formulaLength != 0) {
byte[] tokens = new byte[formulaLength];
System.arraycopy(data, pos, tokens, 0, formulaLength);
this.formula2 = new FormulaParser(tokens, null, es, nt, ws);
this.formula2.parse();
pos += formulaLength;
}
pos += 2;
this.row1 = IntegerHelper.getInt(data[pos], data[pos + 1]);
pos += 2;
this.row2 = IntegerHelper.getInt(data[pos], data[pos + 1]);
pos += 2;
this.column1 = IntegerHelper.getInt(data[pos], data[pos + 1]);
pos += 2;
this.column2 = IntegerHelper.getInt(data[pos], data[pos + 1]);
pos += 2;
}
public byte[] getData() {
byte[] f1Bytes = (this.formula1 != null) ? this.formula1.getBytes() : new byte[0];
byte[] f2Bytes = (this.formula2 != null) ? this.formula2.getBytes() : new byte[0];
int dataLength = 4 + this.promptTitle.length() * 2 + 2 + this.errorTitle.length() * 2 + 2 + this.promptText.length() * 2 + 2 + this.errorText.length() * 2 + 2 + f1Bytes.length + 2 + f2Bytes.length + 2 + 4 + 10;
byte[] data = new byte[dataLength];
int pos = 0;
int options = 0;
options |= this.type.getValue();
options |= this.errorStyle.getValue() << 4;
options |= this.condition.getValue() << 20;
if (this.stringListGiven)
options |= STRING_LIST_GIVEN_MASK;
if (this.emptyCellsAllowed)
options |= EMPTY_CELLS_ALLOWED_MASK;
if (this.suppressArrow)
options |= SUPPRESS_ARROW_MASK;
if (this.showPrompt)
options |= SHOW_PROMPT_MASK;
if (this.showError)
options |= SHOW_ERROR_MASK;
IntegerHelper.getFourBytes(options, data, pos);
pos += 4;
IntegerHelper.getTwoBytes(this.promptTitle.length(), data, pos);
pos += 2;
StringHelper.getUnicodeBytes(this.promptTitle, data, pos);
pos += this.promptTitle.length() * 2;
IntegerHelper.getTwoBytes(this.errorTitle.length(), data, pos);
pos += 2;
StringHelper.getUnicodeBytes(this.errorTitle, data, pos);
pos += this.errorTitle.length() * 2;
IntegerHelper.getTwoBytes(this.promptText.length(), data, pos);
pos += 2;
StringHelper.getUnicodeBytes(this.promptText, data, pos);
pos += this.promptText.length() * 2;
IntegerHelper.getTwoBytes(this.errorText.length(), data, pos);
pos += 2;
StringHelper.getUnicodeBytes(this.errorText, data, pos);
pos += this.errorText.length() * 2;
IntegerHelper.getTwoBytes(f1Bytes.length, data, pos);
pos += 4;
System.arraycopy(f1Bytes, 0, data, pos, f1Bytes.length);
pos += f1Bytes.length;
IntegerHelper.getTwoBytes(f2Bytes.length, data, pos);
pos += 2;
System.arraycopy(f2Bytes, 0, data, pos, f2Bytes.length);
pos += f2Bytes.length;
pos += 2;
IntegerHelper.getTwoBytes(1, data, pos);
pos += 2;
IntegerHelper.getTwoBytes(this.row1, data, pos);
pos += 2;
IntegerHelper.getTwoBytes(this.row2, data, pos);
pos += 2;
IntegerHelper.getTwoBytes(this.column1, data, pos);
pos += 2;
IntegerHelper.getTwoBytes(this.column2, data, pos);
pos += 2;
return data;
}
public void insertRow(int row) {
if (this.formula1 != null)
this.formula1.rowInserted(0, row, true);
if (this.formula2 != null)
this.formula2.rowInserted(0, row, true);
if (this.row1 >= row)
this.row1++;
if (this.row2 >= row)
this.row2++;
}
public void insertColumn(int col) {
if (this.formula1 != null)
this.formula1.columnInserted(0, col, true);
if (this.formula2 != null)
this.formula2.columnInserted(0, col, true);
if (this.column1 >= col)
this.column1++;
if (this.column2 >= col)
this.column2++;
}
public void removeRow(int row) {
if (this.formula1 != null)
this.formula1.rowRemoved(0, row, true);
if (this.formula2 != null)
this.formula2.rowRemoved(0, row, true);
if (this.row1 > row)
this.row1--;
if (this.row2 >= row)
this.row2--;
}
public void removeColumn(int col) {
if (this.formula1 != null)
this.formula1.columnRemoved(0, col, true);
if (this.formula2 != null)
this.formula2.columnRemoved(0, col, true);
if (this.column1 > col)
this.column1--;
if (this.column2 >= col)
this.column2--;
}
public int getFirstColumn() {
return this.column1;
}
public int getLastColumn() {
return this.column2;
}
public int getFirstRow() {
return this.row1;
}
public int getLastRow() {
return this.row2;
}
}

View File

@@ -0,0 +1,51 @@
package jxl.biff;
import common.Logger;
public class DValParser {
private static Logger logger = Logger.getLogger(DValParser.class);
private static int PROMPT_BOX_VISIBLE_MASK = 1;
private static int PROMPT_BOX_AT_CELL_MASK = 2;
private static int VALIDITY_DATA_CACHED_MASK = 4;
private boolean promptBoxVisible;
private boolean promptBoxAtCell;
private boolean validityDataCached;
private int numDVRecords;
public DValParser(byte[] data) {
int options = IntegerHelper.getInt(data[0], data[1]);
this.promptBoxVisible = ((options & PROMPT_BOX_VISIBLE_MASK) != 0);
this.promptBoxAtCell = ((options & PROMPT_BOX_AT_CELL_MASK) != 0);
this.validityDataCached = ((options & VALIDITY_DATA_CACHED_MASK) != 0);
this.numDVRecords = IntegerHelper.getInt(data[14], data[15], data[16], data[17]);
}
public byte[] getData() {
byte[] data = new byte[18];
int options = 0;
if (this.promptBoxVisible)
options |= PROMPT_BOX_VISIBLE_MASK;
if (this.promptBoxAtCell)
options |= PROMPT_BOX_AT_CELL_MASK;
if (this.validityDataCached)
options |= VALIDITY_DATA_CACHED_MASK;
IntegerHelper.getFourBytes(-1, data, 10);
IntegerHelper.getFourBytes(this.numDVRecords, data, 14);
return data;
}
public void dvRemoved() {
this.numDVRecords--;
}
public int getNumberOfDVRecords() {
return this.numDVRecords;
}
}

View File

@@ -0,0 +1,11 @@
package jxl.biff;
public interface DisplayFormat {
int getFormatIndex();
boolean isInitialized();
void initialize(int paramInt);
boolean isBuiltIn();
}

View File

@@ -0,0 +1,26 @@
package jxl.biff;
public class DoubleHelper {
public static double getIEEEDouble(byte[] data, int pos) {
int num1 = IntegerHelper.getInt(data[pos], data[pos + 1], data[pos + 2], data[pos + 3]);
int num2 = IntegerHelper.getInt(data[pos + 4], data[pos + 5], data[pos + 6], data[pos + 7]);
boolean negative = ((num2 & Integer.MIN_VALUE) != 0);
long val = (num2 & Integer.MAX_VALUE) * 4294967296L + ((num1 < 0) ? (4294967296L + num1) : num1);
double value = Double.longBitsToDouble(val);
if (negative)
value = -value;
return value;
}
public static void getIEEEBytes(double d, byte[] target, int pos) {
long val = Double.doubleToLongBits(d);
target[pos] = (byte)(int)(val & 0xFFL);
target[pos + 1] = (byte)(int)((val & 0xFF00L) >> 8L);
target[pos + 2] = (byte)(int)((val & 0xFF0000L) >> 16L);
target[pos + 3] = (byte)(int)((val & 0xFFFFFFFFFF000000L) >> 24L);
target[pos + 4] = (byte)(int)((val & 0xFF00000000L) >> 32L);
target[pos + 5] = (byte)(int)((val & 0xFF0000000000L) >> 40L);
target[pos + 6] = (byte)(int)((val & 0xFF000000000000L) >> 48L);
target[pos + 7] = (byte)(int)((val & 0xFF00000000000000L) >> 56L);
}
}

View File

@@ -0,0 +1,75 @@
package jxl.biff;
import jxl.CellFeatures;
import jxl.CellFormat;
import jxl.CellType;
import jxl.format.Alignment;
import jxl.format.CellFormat;
import jxl.write.Border;
import jxl.write.BorderLineStyle;
import jxl.write.VerticalAlignment;
import jxl.write.WritableCell;
import jxl.write.WritableCellFeatures;
public class EmptyCell implements WritableCell {
private int row;
private int col;
public EmptyCell(int c, int r) {
this.row = r;
this.col = c;
}
public int getRow() {
return this.row;
}
public int getColumn() {
return this.col;
}
public CellType getType() {
return CellType.EMPTY;
}
public String getContents() {
return "";
}
public CellFormat getCellFormat() {
return null;
}
public void setHidden(boolean flag) {}
public void setLocked(boolean flag) {}
public void setAlignment(Alignment align) {}
public void setVerticalAlignment(VerticalAlignment valign) {}
public void setBorder(Border border, BorderLineStyle line) {}
public void setCellFormat(CellFormat cf) {}
public void setCellFormat(CellFormat cf) {}
public boolean isHidden() {
return false;
}
public WritableCell copyTo(int c, int r) {
return new EmptyCell(c, r);
}
public CellFeatures getCellFeatures() {
return null;
}
public WritableCellFeatures getWritableCellFeatures() {
return null;
}
public void setCellFeatures(WritableCellFeatures wcf) {}
}

View File

@@ -0,0 +1,73 @@
package jxl.biff;
import common.Logger;
import jxl.WorkbookSettings;
public class EncodedURLHelper {
private static Logger logger = Logger.getLogger(EncodedURLHelper.class);
private static byte msDosDriveLetter = 1;
private static byte sameDrive = 2;
private static byte endOfSubdirectory = 3;
private static byte parentDirectory = 4;
private static byte unencodedUrl = 5;
public static byte[] getEncodedURL(String s, WorkbookSettings ws) {
if (s.startsWith("http:"))
return getURL(s, ws);
return getFile(s, ws);
}
private static byte[] getFile(String s, WorkbookSettings ws) {
ByteArray byteArray = new ByteArray();
int pos = 0;
if (s.charAt(1) == ':') {
byteArray.add(msDosDriveLetter);
byteArray.add((byte)s.charAt(0));
pos = 2;
} else if (s.charAt(pos) == '\\' || s.charAt(pos) == '/') {
byteArray.add(sameDrive);
}
while (s.charAt(pos) == '\\' || s.charAt(pos) == '/')
pos++;
while (pos < s.length()) {
int nextSepIndex1 = s.indexOf('/', pos);
int nextSepIndex2 = s.indexOf('\\', pos);
int nextSepIndex = 0;
String nextFileNameComponent = null;
if (nextSepIndex1 != -1 && nextSepIndex2 != -1) {
nextSepIndex = Math.min(nextSepIndex1, nextSepIndex2);
} else if (nextSepIndex1 == -1 || nextSepIndex2 == -1) {
nextSepIndex = Math.max(nextSepIndex1, nextSepIndex2);
}
if (nextSepIndex == -1) {
nextFileNameComponent = s.substring(pos);
pos = s.length();
} else {
nextFileNameComponent = s.substring(pos, nextSepIndex);
pos = nextSepIndex + 1;
}
if (!nextFileNameComponent.equals("."))
if (nextFileNameComponent.equals("..")) {
byteArray.add(parentDirectory);
} else {
byteArray.add(StringHelper.getBytes(nextFileNameComponent, ws));
}
if (pos < s.length())
byteArray.add(endOfSubdirectory);
}
return byteArray.getBytes();
}
private static byte[] getURL(String s, WorkbookSettings ws) {
ByteArray byteArray = new ByteArray();
byteArray.add(unencodedUrl);
byteArray.add((byte)s.length());
byteArray.add(StringHelper.getBytes(s, ws));
return byteArray.getBytes();
}
}

View File

@@ -0,0 +1,234 @@
package jxl.biff;
import common.Assert;
import common.Logger;
import jxl.WorkbookSettings;
import jxl.format.Colour;
import jxl.format.Font;
import jxl.format.ScriptStyle;
import jxl.format.UnderlineStyle;
import jxl.read.biff.Record;
public class FontRecord extends WritableRecordData implements Font {
private static Logger logger = Logger.getLogger(FontRecord.class);
private int pointHeight;
private int colourIndex;
private int boldWeight;
private int scriptStyle;
private int underlineStyle;
private byte fontFamily;
private byte characterSet;
private boolean italic;
private boolean struckout;
private String name;
private boolean initialized;
private int fontIndex;
private static class Biff7 {
private Biff7() {}
}
public static final Biff7 biff7 = new Biff7();
private static final int EXCEL_UNITS_PER_POINT = 20;
protected FontRecord(String fn, int ps, int bold, boolean it, int us, int ci, int ss) {
super(Type.FONT);
this.boldWeight = bold;
this.underlineStyle = us;
this.name = fn;
this.pointHeight = ps;
this.italic = it;
this.scriptStyle = ss;
this.colourIndex = ci;
this.initialized = false;
this.struckout = false;
}
public FontRecord(Record t, WorkbookSettings ws) {
super(t);
byte[] data = getRecord().getData();
this.pointHeight = IntegerHelper.getInt(data[0], data[1]) / 20;
this.colourIndex = IntegerHelper.getInt(data[4], data[5]);
this.boldWeight = IntegerHelper.getInt(data[6], data[7]);
this.scriptStyle = IntegerHelper.getInt(data[8], data[9]);
this.underlineStyle = data[10];
this.fontFamily = data[11];
this.characterSet = data[12];
this.initialized = false;
if ((data[2] & 0x2) != 0)
this.italic = true;
if ((data[2] & 0x8) != 0)
this.struckout = true;
int numChars = data[14];
if (data[15] == 0) {
this.name = StringHelper.getString(data, numChars, 16, ws);
} else if (data[15] == 1) {
this.name = StringHelper.getUnicodeString(data, numChars, 16);
} else {
this.name = StringHelper.getString(data, numChars, 15, ws);
}
}
public FontRecord(Record t, WorkbookSettings ws, Biff7 dummy) {
super(t);
byte[] data = getRecord().getData();
this.pointHeight = IntegerHelper.getInt(data[0], data[1]) / 20;
this.colourIndex = IntegerHelper.getInt(data[4], data[5]);
this.boldWeight = IntegerHelper.getInt(data[6], data[7]);
this.scriptStyle = IntegerHelper.getInt(data[8], data[9]);
this.underlineStyle = data[10];
this.fontFamily = data[11];
this.initialized = false;
if ((data[2] & 0x2) != 0)
this.italic = true;
if ((data[2] & 0x8) != 0)
this.struckout = true;
int numChars = data[14];
this.name = StringHelper.getString(data, numChars, 15, ws);
}
protected FontRecord(Font f) {
super(Type.FONT);
Assert.verify((f != null));
this.pointHeight = f.getPointSize();
this.colourIndex = f.getColour().getValue();
this.boldWeight = f.getBoldWeight();
this.scriptStyle = f.getScriptStyle().getValue();
this.underlineStyle = f.getUnderlineStyle().getValue();
this.italic = f.isItalic();
this.name = f.getName();
this.struckout = false;
this.initialized = false;
}
public byte[] getData() {
byte[] data = new byte[16 + this.name.length() * 2];
IntegerHelper.getTwoBytes(this.pointHeight * 20, data, 0);
if (this.italic)
data[2] = (byte)(data[2] | 0x2);
if (this.struckout)
data[2] = (byte)(data[2] | 0x8);
IntegerHelper.getTwoBytes(this.colourIndex, data, 4);
IntegerHelper.getTwoBytes(this.boldWeight, data, 6);
IntegerHelper.getTwoBytes(this.scriptStyle, data, 8);
data[10] = (byte)this.underlineStyle;
data[11] = this.fontFamily;
data[12] = this.characterSet;
data[13] = 0;
data[14] = (byte)this.name.length();
data[15] = 1;
StringHelper.getUnicodeBytes(this.name, data, 16);
return data;
}
public final boolean isInitialized() {
return this.initialized;
}
public final void initialize(int pos) {
this.fontIndex = pos;
this.initialized = true;
}
public final void uninitialize() {
this.initialized = false;
}
public final int getFontIndex() {
return this.fontIndex;
}
protected void setFontPointSize(int ps) {
Assert.verify(!this.initialized);
this.pointHeight = ps;
}
public int getPointSize() {
return this.pointHeight;
}
protected void setFontBoldStyle(int bs) {
Assert.verify(!this.initialized);
this.boldWeight = bs;
}
public int getBoldWeight() {
return this.boldWeight;
}
protected void setFontItalic(boolean i) {
Assert.verify(!this.initialized);
this.italic = i;
}
public boolean isItalic() {
return this.italic;
}
protected void setFontUnderlineStyle(int us) {
Assert.verify(!this.initialized);
this.underlineStyle = us;
}
public UnderlineStyle getUnderlineStyle() {
return UnderlineStyle.getStyle(this.underlineStyle);
}
protected void setFontColour(int c) {
Assert.verify(!this.initialized);
this.colourIndex = c;
}
public Colour getColour() {
return Colour.getInternalColour(this.colourIndex);
}
protected void setFontScriptStyle(int ss) {
Assert.verify(!this.initialized);
this.scriptStyle = ss;
}
public ScriptStyle getScriptStyle() {
return ScriptStyle.getStyle(this.scriptStyle);
}
public String getName() {
return this.name;
}
public int hashCode() {
return this.name.hashCode();
}
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof FontRecord))
return false;
FontRecord font = (FontRecord)o;
if (this.pointHeight == font.pointHeight && this.colourIndex == font.colourIndex && this.boldWeight == font.boldWeight && this.scriptStyle == font.scriptStyle && this.underlineStyle == font.underlineStyle && this.italic == font.italic && this.struckout == font.struckout && this.fontFamily == font.fontFamily && this.characterSet == font.characterSet && this.name.equals(font.name))
return true;
return false;
}
public boolean isStruckout() {
return this.struckout;
}
protected void setFontStruckout(boolean os) {
this.struckout = os;
}
}

View File

@@ -0,0 +1,79 @@
package jxl.biff;
import common.Assert;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import jxl.write.biff.File;
public class Fonts {
private ArrayList fonts = new ArrayList();
private static final int numDefaultFonts = 4;
public void addFont(FontRecord f) {
if (!f.isInitialized()) {
int pos = this.fonts.size();
if (pos >= 4)
pos++;
f.initialize(pos);
this.fonts.add(f);
}
}
public FontRecord getFont(int index) {
if (index > 4)
index--;
return this.fonts.get(index);
}
public void write(File outputFile) throws IOException {
Iterator i = this.fonts.iterator();
FontRecord font = null;
while (i.hasNext()) {
font = i.next();
outputFile.write(font);
}
}
IndexMapping rationalize() {
IndexMapping mapping = new IndexMapping(this.fonts.size() + 1);
ArrayList newfonts = new ArrayList();
FontRecord fr = null;
int numremoved = 0;
for (int i = 0; i < 4; i++) {
fr = this.fonts.get(i);
newfonts.add(fr);
mapping.setMapping(fr.getFontIndex(), fr.getFontIndex());
}
Iterator it = null;
FontRecord fr2 = null;
boolean duplicate = false;
for (int j = 4; j < this.fonts.size(); j++) {
fr = this.fonts.get(j);
duplicate = false;
it = newfonts.iterator();
while (it.hasNext() && !duplicate) {
fr2 = it.next();
if (fr.equals(fr2)) {
duplicate = true;
mapping.setMapping(fr.getFontIndex(), mapping.getNewIndex(fr2.getFontIndex()));
numremoved++;
}
}
if (!duplicate) {
newfonts.add(fr);
int newindex = fr.getFontIndex() - numremoved;
Assert.verify((newindex > 4));
mapping.setMapping(fr.getFontIndex(), newindex);
}
}
it = newfonts.iterator();
while (it.hasNext()) {
fr = it.next();
fr.initialize(mapping.getNewIndex(fr.getFontIndex()));
}
this.fonts = newfonts;
return mapping;
}
}

View File

@@ -0,0 +1,309 @@
package jxl.biff;
import common.Logger;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.Format;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import jxl.WorkbookSettings;
import jxl.format.Format;
import jxl.read.biff.Record;
public class FormatRecord extends WritableRecordData implements DisplayFormat, Format {
public static Logger logger = Logger.getLogger(FormatRecord.class);
private boolean initialized;
private byte[] data;
private int indexCode;
private String formatString;
private boolean date;
private boolean number;
private Format format;
private WorkbookSettings settings;
private static String[] dateStrings = new String[] { "dd", "mm", "yy", "hh", "ss", "m/", "/d" };
private static class BiffType {
private BiffType() {}
}
public static final BiffType biff8 = new BiffType();
public static final BiffType biff7 = new BiffType();
FormatRecord(String fmt, int refno) {
super(Type.FORMAT);
this.formatString = fmt;
this.indexCode = refno;
this.initialized = true;
}
protected FormatRecord() {
super(Type.FORMAT);
this.initialized = false;
}
protected FormatRecord(FormatRecord fr) {
super(Type.FORMAT);
this.initialized = false;
this.formatString = fr.formatString;
this.date = fr.date;
this.number = fr.number;
}
public FormatRecord(Record t, WorkbookSettings ws, BiffType biffType) {
super(t);
byte[] data = getRecord().getData();
this.indexCode = IntegerHelper.getInt(data[0], data[1]);
this.initialized = true;
if (biffType == biff8) {
int numchars = IntegerHelper.getInt(data[2], data[3]);
if (data[4] == 0) {
this.formatString = StringHelper.getString(data, numchars, 5, ws);
} else {
this.formatString = StringHelper.getUnicodeString(data, numchars, 5);
}
} else {
int numchars = data[2];
byte[] chars = new byte[numchars];
System.arraycopy(data, 3, chars, 0, chars.length);
this.formatString = new String(chars);
}
this.date = false;
this.number = false;
for (int i = 0; i < dateStrings.length; i++) {
String dateString = dateStrings[i];
if (this.formatString.indexOf(dateString) != -1 || this.formatString.indexOf(dateString.toUpperCase()) != -1) {
this.date = true;
break;
}
}
if (!this.date)
if (this.formatString.indexOf('#') != -1 || this.formatString.indexOf('0') != -1)
this.number = true;
}
public byte[] getData() {
this.data = new byte[this.formatString.length() * 2 + 3 + 2];
IntegerHelper.getTwoBytes(this.indexCode, this.data, 0);
IntegerHelper.getTwoBytes(this.formatString.length(), this.data, 2);
this.data[4] = 1;
StringHelper.getUnicodeBytes(this.formatString, this.data, 5);
return this.data;
}
public int getFormatIndex() {
return this.indexCode;
}
public boolean isInitialized() {
return this.initialized;
}
public void initialize(int pos) {
this.indexCode = pos;
this.initialized = true;
}
protected final String replace(String input, String search, String replace) {
String fmtstr = input;
int pos = fmtstr.indexOf(search);
while (pos != -1) {
StringBuffer tmp = new StringBuffer(fmtstr.substring(0, pos));
tmp.append(replace);
tmp.append(fmtstr.substring(pos + search.length()));
fmtstr = tmp.toString();
pos = fmtstr.indexOf(search);
}
return fmtstr;
}
protected final void setFormatString(String s) {
this.formatString = s;
}
public final boolean isDate() {
return this.date;
}
public final boolean isNumber() {
return this.number;
}
public final NumberFormat getNumberFormat() {
if (this.format != null && this.format instanceof NumberFormat)
return (NumberFormat)this.format;
try {
String fs = this.formatString;
fs = replace(fs, "E+", "E");
fs = replace(fs, "_)", "");
fs = replace(fs, "_", "");
fs = replace(fs, "[Red]", "");
fs = replace(fs, "\\", "");
this.format = new DecimalFormat(fs);
} catch (IllegalArgumentException e) {
this.format = new DecimalFormat("#.###");
}
return (NumberFormat)this.format;
}
public final DateFormat getDateFormat() {
if (this.format != null && this.format instanceof DateFormat)
return (DateFormat)this.format;
String fmt = this.formatString;
int pos = fmt.indexOf("AM/PM");
while (pos != -1) {
StringBuffer stringBuffer = new StringBuffer(fmt.substring(0, pos));
stringBuffer.append('a');
stringBuffer.append(fmt.substring(pos + 5));
fmt = stringBuffer.toString();
pos = fmt.indexOf("AM/PM");
}
pos = fmt.indexOf("ss.0");
while (pos != -1) {
StringBuffer stringBuffer = new StringBuffer(fmt.substring(0, pos));
stringBuffer.append("ss.SSS");
pos += 4;
while (pos < fmt.length() && fmt.charAt(pos) == '0')
pos++;
stringBuffer.append(fmt.substring(pos));
fmt = stringBuffer.toString();
pos = fmt.indexOf("ss.0");
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < fmt.length(); i++) {
if (fmt.charAt(i) != '\\')
sb.append(fmt.charAt(i));
}
fmt = sb.toString();
if (fmt.charAt(0) == '[') {
int end = fmt.indexOf(']');
if (end != -1)
fmt = fmt.substring(end + 1);
}
fmt = replace(fmt, ";@", "");
char[] formatBytes = fmt.toCharArray();
for (int j = 0; j < formatBytes.length; j++) {
if (formatBytes[j] == 'm')
if (j > 0 && (formatBytes[j - 1] == 'm' || formatBytes[j - 1] == 'M')) {
formatBytes[j] = formatBytes[j - 1];
} else {
int minuteDist = Integer.MAX_VALUE;
int k;
for (k = j - 1; k > 0; k--) {
if (formatBytes[k] == 'h') {
minuteDist = j - k;
break;
}
}
for (k = j + 1; k < formatBytes.length; k++) {
if (formatBytes[k] == 'h') {
minuteDist = Math.min(minuteDist, k - j);
break;
}
}
for (k = j - 1; k > 0; k--) {
if (formatBytes[k] == 'H') {
minuteDist = j - k;
break;
}
}
for (k = j + 1; k < formatBytes.length; k++) {
if (formatBytes[k] == 'H') {
minuteDist = Math.min(minuteDist, k - j);
break;
}
}
for (k = j - 1; k > 0; k--) {
if (formatBytes[k] == 's') {
minuteDist = Math.min(minuteDist, j - k);
break;
}
}
for (k = j + 1; k < formatBytes.length; k++) {
if (formatBytes[k] == 's') {
minuteDist = Math.min(minuteDist, k - j);
break;
}
}
int monthDist = Integer.MAX_VALUE;
int m;
for (m = j - 1; m > 0; m--) {
if (formatBytes[m] == 'd') {
monthDist = j - m;
break;
}
}
for (m = j + 1; m < formatBytes.length; m++) {
if (formatBytes[m] == 'd') {
monthDist = Math.min(monthDist, m - j);
break;
}
}
for (m = j - 1; m > 0; m--) {
if (formatBytes[m] == 'y') {
monthDist = Math.min(monthDist, j - m);
break;
}
}
for (m = j + 1; m < formatBytes.length; m++) {
if (formatBytes[m] == 'y') {
monthDist = Math.min(monthDist, m - j);
break;
}
}
if (monthDist < minuteDist) {
formatBytes[j] = Character.toUpperCase(formatBytes[j]);
} else if (monthDist == minuteDist && monthDist != Integer.MAX_VALUE) {
char ind = formatBytes[j - monthDist];
if (ind == 'y' || ind == 'd')
formatBytes[j] = Character.toUpperCase(formatBytes[j]);
}
}
}
try {
this.format = new SimpleDateFormat(new String(formatBytes));
} catch (IllegalArgumentException e) {
this.format = new SimpleDateFormat("dd MM yyyy hh:mm:ss");
}
return (DateFormat)this.format;
}
public int getIndexCode() {
return this.indexCode;
}
public String getFormatString() {
return this.formatString;
}
public boolean isBuiltIn() {
return false;
}
public int hashCode() {
return this.formatString.hashCode();
}
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof FormatRecord))
return false;
FormatRecord fr = (FormatRecord)o;
if (this.initialized && fr.initialized) {
if (this.date != fr.date || this.number != fr.number)
return false;
return this.formatString.equals(fr.formatString);
}
return this.formatString.equals(fr.formatString);
}
}

View File

@@ -0,0 +1,256 @@
package jxl.biff;
import common.Assert;
import common.Logger;
import java.io.IOException;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import jxl.format.Colour;
import jxl.format.RGB;
import jxl.write.biff.File;
public class FormattingRecords {
private static Logger logger = Logger.getLogger(FormattingRecords.class);
private HashMap formats;
private ArrayList formatsList;
private ArrayList xfRecords;
private int nextCustomIndexNumber;
private Fonts fonts;
private PaletteRecord palette;
private static final int customFormatStartIndex = 164;
private static final int maxFormatRecordsIndex = 441;
private static final int minXFRecords = 21;
public FormattingRecords(Fonts f) {
this.xfRecords = new ArrayList(10);
this.formats = new HashMap(10);
this.formatsList = new ArrayList(10);
this.fonts = f;
this.nextCustomIndexNumber = 164;
}
public final void addStyle(XFRecord xf) throws NumFormatRecordsException {
if (!xf.isInitialized()) {
int pos = this.xfRecords.size();
xf.initialize(pos, this, this.fonts);
this.xfRecords.add(xf);
} else if (xf.getXFIndex() >= this.xfRecords.size()) {
this.xfRecords.add(xf);
}
}
public final void addFormat(DisplayFormat fr) throws NumFormatRecordsException {
if (fr.isInitialized() && fr.getFormatIndex() >= 441) {
logger.warn("Format index exceeds Excel maximum - assigning custom number");
fr.initialize(this.nextCustomIndexNumber);
this.nextCustomIndexNumber++;
}
if (!fr.isInitialized()) {
fr.initialize(this.nextCustomIndexNumber);
this.nextCustomIndexNumber++;
}
if (this.nextCustomIndexNumber > 441) {
this.nextCustomIndexNumber = 441;
throw new NumFormatRecordsException();
}
if (fr.getFormatIndex() >= this.nextCustomIndexNumber)
this.nextCustomIndexNumber = fr.getFormatIndex() + 1;
if (!fr.isBuiltIn()) {
this.formatsList.add(fr);
this.formats.put(new Integer(fr.getFormatIndex()), fr);
}
}
public final boolean isDate(int pos) {
XFRecord xfr = this.xfRecords.get(pos);
if (xfr.isDate())
return true;
FormatRecord fr = (FormatRecord)this.formats.get(new Integer(xfr.getFormatRecord()));
return (fr == null) ? false : fr.isDate();
}
public final DateFormat getDateFormat(int pos) {
XFRecord xfr = this.xfRecords.get(pos);
if (xfr.isDate())
return xfr.getDateFormat();
FormatRecord fr = (FormatRecord)this.formats.get(new Integer(xfr.getFormatRecord()));
if (fr == null)
return null;
return fr.isDate() ? fr.getDateFormat() : null;
}
public final NumberFormat getNumberFormat(int pos) {
XFRecord xfr = this.xfRecords.get(pos);
if (xfr.isNumber())
return xfr.getNumberFormat();
FormatRecord fr = (FormatRecord)this.formats.get(new Integer(xfr.getFormatRecord()));
if (fr == null)
return null;
return fr.isNumber() ? fr.getNumberFormat() : null;
}
FormatRecord getFormatRecord(int index) {
return (FormatRecord)this.formats.get(new Integer(index));
}
public void write(File outputFile) throws IOException {
Iterator i = this.formatsList.iterator();
FormatRecord fr = null;
while (i.hasNext()) {
fr = i.next();
outputFile.write(fr);
}
i = this.xfRecords.iterator();
XFRecord xfr = null;
while (i.hasNext()) {
xfr = (XFRecord)i.next();
outputFile.write(xfr);
}
BuiltInStyle style = new BuiltInStyle(16, 3);
outputFile.write(style);
style = new BuiltInStyle(17, 6);
outputFile.write(style);
style = new BuiltInStyle(18, 4);
outputFile.write(style);
style = new BuiltInStyle(19, 7);
outputFile.write(style);
style = new BuiltInStyle(0, 0);
outputFile.write(style);
style = new BuiltInStyle(20, 5);
outputFile.write(style);
}
protected final Fonts getFonts() {
return this.fonts;
}
public final XFRecord getXFRecord(int index) {
return this.xfRecords.get(index);
}
protected final int getNumberOfFormatRecords() {
return this.formatsList.size();
}
public IndexMapping rationalizeFonts() {
return this.fonts.rationalize();
}
public IndexMapping rationalize(IndexMapping fontMapping, IndexMapping formatMapping) {
XFRecord xfr = null;
for (Iterator it = this.xfRecords.iterator(); it.hasNext(); ) {
xfr = it.next();
if (xfr.getFormatRecord() >= 164)
xfr.setFormatIndex(formatMapping.getNewIndex(xfr.getFormatRecord()));
xfr.setFontIndex(fontMapping.getNewIndex(xfr.getFontIndex()));
}
ArrayList newrecords = new ArrayList(21);
IndexMapping mapping = new IndexMapping(this.xfRecords.size());
int numremoved = 0;
int numXFRecords = Math.min(21, this.xfRecords.size());
int j;
for (j = 0; j < numXFRecords; j++) {
newrecords.add(this.xfRecords.get(j));
mapping.setMapping(j, j);
}
if (numXFRecords < 21) {
logger.warn("There are less than the expected minimum number of XF records");
return mapping;
}
for (j = 21; j < this.xfRecords.size(); j++) {
XFRecord xf = this.xfRecords.get(j);
boolean duplicate = false;
Iterator iterator = newrecords.iterator();
while (iterator.hasNext() && !duplicate) {
XFRecord xf2 = iterator.next();
if (xf2.equals(xf)) {
duplicate = true;
mapping.setMapping(j, mapping.getNewIndex(xf2.getXFIndex()));
numremoved++;
}
}
if (!duplicate) {
newrecords.add(xf);
mapping.setMapping(j, j - numremoved);
}
}
for (Iterator i = this.xfRecords.iterator(); i.hasNext(); ) {
XFRecord xf = i.next();
xf.rationalize(mapping);
}
this.xfRecords = newrecords;
return mapping;
}
public IndexMapping rationalizeDisplayFormats() {
ArrayList newformats = new ArrayList();
int numremoved = 0;
IndexMapping mapping = new IndexMapping(this.nextCustomIndexNumber);
Iterator i = this.formatsList.iterator();
DisplayFormat df = null;
DisplayFormat df2 = null;
boolean duplicate = false;
while (i.hasNext()) {
df = i.next();
Assert.verify(!df.isBuiltIn());
Iterator i2 = newformats.iterator();
duplicate = false;
while (i2.hasNext() && !duplicate) {
df2 = i2.next();
if (df2.equals(df)) {
duplicate = true;
mapping.setMapping(df.getFormatIndex(), mapping.getNewIndex(df2.getFormatIndex()));
numremoved++;
}
}
if (!duplicate) {
newformats.add(df);
int indexnum = df.getFormatIndex() - numremoved;
if (indexnum > 441) {
logger.warn("Too many number formats - using default format.");
indexnum = 0;
}
mapping.setMapping(df.getFormatIndex(), df.getFormatIndex() - numremoved);
}
}
this.formatsList = newformats;
i = this.formatsList.iterator();
while (i.hasNext()) {
df = i.next();
df.initialize(mapping.getNewIndex(df.getFormatIndex()));
}
return mapping;
}
public PaletteRecord getPalette() {
return this.palette;
}
public void setPalette(PaletteRecord pr) {
this.palette = pr;
}
public void setColourRGB(Colour c, int r, int g, int b) {
if (this.palette == null)
this.palette = new PaletteRecord();
this.palette.setColourRGB(c, r, g, b);
}
public RGB getColourRGB(Colour c) {
if (this.palette == null)
return c.getDefaultRGB();
return this.palette.getColourRGB(c);
}
}

View File

@@ -0,0 +1,8 @@
package jxl.biff;
import jxl.Cell;
import jxl.biff.formula.FormulaException;
public interface FormulaData extends Cell {
byte[] getFormulaData() throws FormulaException;
}

View File

@@ -0,0 +1,270 @@
package jxl.biff;
import common.Logger;
public abstract class HeaderFooter {
private static Logger logger = Logger.getLogger(HeaderFooter.class);
private static final String BOLD_TOGGLE = "&B";
private static final String UNDERLINE_TOGGLE = "&U";
private static final String ITALICS_TOGGLE = "&I";
private static final String STRIKETHROUGH_TOGGLE = "&S";
private static final String DOUBLE_UNDERLINE_TOGGLE = "&E";
private static final String SUPERSCRIPT_TOGGLE = "&X";
private static final String SUBSCRIPT_TOGGLE = "&Y";
private static final String OUTLINE_TOGGLE = "&O";
private static final String SHADOW_TOGGLE = "&H";
private static final String LEFT_ALIGN = "&L";
private static final String CENTRE = "&C";
private static final String RIGHT_ALIGN = "&R";
private static final String PAGENUM = "&P";
private static final String TOTAL_PAGENUM = "&N";
private static final String DATE = "&D";
private static final String TIME = "&T";
private static final String WORKBOOK_NAME = "&F";
private static final String WORKSHEET_NAME = "&A";
private Contents left;
private Contents right;
private Contents centre;
protected static class Contents {
private StringBuffer contents;
protected Contents() {
this.contents = new StringBuffer();
}
protected Contents(String s) {
this.contents = new StringBuffer(s);
}
protected Contents(Contents copy) {
this.contents = new StringBuffer(copy.getContents());
}
protected String getContents() {
return (this.contents != null) ? this.contents.toString() : "";
}
private void appendInternal(String txt) {
if (this.contents == null)
this.contents = new StringBuffer();
this.contents.append(txt);
}
private void appendInternal(char ch) {
if (this.contents == null)
this.contents = new StringBuffer();
this.contents.append(ch);
}
protected void append(String txt) {
appendInternal(txt);
}
protected void toggleBold() {
appendInternal("&B");
}
protected void toggleUnderline() {
appendInternal("&U");
}
protected void toggleItalics() {
appendInternal("&I");
}
protected void toggleStrikethrough() {
appendInternal("&S");
}
protected void toggleDoubleUnderline() {
appendInternal("&E");
}
protected void toggleSuperScript() {
appendInternal("&X");
}
protected void toggleSubScript() {
appendInternal("&Y");
}
protected void toggleOutline() {
appendInternal("&O");
}
protected void toggleShadow() {
appendInternal("&H");
}
protected void setFontName(String fontName) {
appendInternal("&\"");
appendInternal(fontName);
appendInternal('"');
}
protected boolean setFontSize(int size) {
String fontSize;
if (size < 1 || size > 99)
return false;
if (size < 10) {
fontSize = "0" + size;
} else {
fontSize = Integer.toString(size);
}
appendInternal('&');
appendInternal(fontSize);
return true;
}
protected void appendPageNumber() {
appendInternal("&P");
}
protected void appendTotalPages() {
appendInternal("&N");
}
protected void appendDate() {
appendInternal("&D");
}
protected void appendTime() {
appendInternal("&T");
}
protected void appendWorkbookName() {
appendInternal("&F");
}
protected void appendWorkSheetName() {
appendInternal("&A");
}
protected void clear() {
this.contents = null;
}
protected boolean empty() {
if (this.contents == null || this.contents.length() == 0)
return true;
return false;
}
}
protected HeaderFooter() {
this.left = createContents();
this.right = createContents();
this.centre = createContents();
}
protected HeaderFooter(HeaderFooter hf) {
this.left = createContents(hf.left);
this.right = createContents(hf.right);
this.centre = createContents(hf.centre);
}
protected HeaderFooter(String s) {
if (s == null || s.length() == 0) {
this.left = createContents();
this.right = createContents();
this.centre = createContents();
return;
}
int pos = 0;
int leftPos = s.indexOf("&L");
int rightPos = s.indexOf("&R");
int centrePos = s.indexOf("&C");
if (pos == leftPos)
if (centrePos != -1) {
this.left = createContents(s.substring(pos + 2, centrePos));
pos = centrePos;
} else if (rightPos != -1) {
this.left = createContents(s.substring(pos + 2, rightPos));
pos = rightPos;
} else {
this.left = createContents(s.substring(pos + 2));
pos = s.length();
}
if (pos == centrePos || (leftPos == -1 && rightPos == -1 && centrePos == -1))
if (rightPos != -1) {
this.centre = createContents(s.substring(pos + 2, rightPos));
pos = rightPos;
} else {
this.centre = createContents(s.substring(pos + 2));
pos = s.length();
}
if (pos == rightPos) {
this.right = createContents(s.substring(pos + 2));
pos = s.length();
}
if (this.left == null)
this.left = createContents();
if (this.centre == null)
this.centre = createContents();
if (this.right == null)
this.right = createContents();
}
public String toString() {
StringBuffer hf = new StringBuffer();
if (!this.left.empty()) {
hf.append("&L");
hf.append(this.left.getContents());
}
if (!this.centre.empty()) {
hf.append("&C");
hf.append(this.centre.getContents());
}
if (!this.right.empty()) {
hf.append("&R");
hf.append(this.right.getContents());
}
return hf.toString();
}
protected Contents getRightText() {
return this.right;
}
protected Contents getCentreText() {
return this.centre;
}
protected Contents getLeftText() {
return this.left;
}
protected void clear() {
this.left.clear();
this.right.clear();
this.centre.clear();
}
protected abstract Contents createContents();
protected abstract Contents createContents(String paramString);
protected abstract Contents createContents(Contents paramContents);
}

View File

@@ -0,0 +1,21 @@
package jxl.biff;
import common.Logger;
public final class IndexMapping {
private static Logger logger = Logger.getLogger(IndexMapping.class);
private int[] newIndices;
IndexMapping(int size) {
this.newIndices = new int[size];
}
void setMapping(int oldIndex, int newIndex) {
this.newIndices[oldIndex] = newIndex;
}
public int getNewIndex(int oldIndex) {
return this.newIndices[oldIndex];
}
}

View File

@@ -0,0 +1,53 @@
package jxl.biff;
public final class IntegerHelper {
public static int getInt(byte b1, byte b2) {
int i1 = b1 & 0xFF;
int i2 = b2 & 0xFF;
int val = i2 << 8 | i1;
return val;
}
public static short getShort(byte b1, byte b2) {
short i1 = (short)(b1 & 0xFF);
short i2 = (short)(b2 & 0xFF);
short val = (short)(i2 << 8 | i1);
return val;
}
public static int getInt(byte b1, byte b2, byte b3, byte b4) {
int i1 = getInt(b1, b2);
int i2 = getInt(b3, b4);
int val = i2 << 16 | i1;
return val;
}
public static byte[] getTwoBytes(int i) {
byte[] bytes = new byte[2];
bytes[0] = (byte)(i & 0xFF);
bytes[1] = (byte)((i & 0xFF00) >> 8);
return bytes;
}
public static byte[] getFourBytes(int i) {
byte[] bytes = new byte[4];
int i1 = i & 0xFFFF;
int i2 = (i & 0xFFFF0000) >> 16;
getTwoBytes(i1, bytes, 0);
getTwoBytes(i2, bytes, 2);
return bytes;
}
public static void getTwoBytes(int i, byte[] target, int pos) {
target[pos] = (byte)(i & 0xFF);
target[pos + 1] = (byte)((i & 0xFF00) >> 8);
}
public static void getFourBytes(int i, byte[] target, int pos) {
byte[] bytes = getFourBytes(i);
target[pos] = bytes[0];
target[pos + 1] = bytes[1];
target[pos + 2] = bytes[2];
target[pos + 3] = bytes[3];
}
}

View File

@@ -0,0 +1,7 @@
package jxl.biff;
public class NumFormatRecordsException extends Exception {
public NumFormatRecordsException() {
super("Internal error: max number of FORMAT records exceeded");
}
}

View File

@@ -0,0 +1,96 @@
package jxl.biff;
import jxl.format.Colour;
import jxl.format.RGB;
import jxl.read.biff.Record;
public class PaletteRecord extends WritableRecordData {
private RGB[] rgbColours = new RGB[56];
private boolean dirty;
private boolean read;
private boolean initialized;
private static final int numColours = 56;
public PaletteRecord(Record t) {
super(t);
this.initialized = false;
this.dirty = false;
this.read = true;
}
public PaletteRecord() {
super(Type.PALETTE);
this.initialized = true;
this.dirty = false;
this.read = false;
Colour[] colours = Colour.getAllColours();
for (int i = 0; i < colours.length; i++) {
Colour c = colours[i];
setColourRGB(c, c.getDefaultRGB().getRed(), c.getDefaultRGB().getGreen(), c.getDefaultRGB().getBlue());
}
}
public byte[] getData() {
if (this.read && !this.dirty)
return getRecord().getData();
byte[] data = new byte[226];
int pos = 0;
IntegerHelper.getTwoBytes(56, data, pos);
for (int i = 0; i < 56; i++) {
pos = i * 4 + 2;
data[pos] = (byte)this.rgbColours[i].getRed();
data[pos + 1] = (byte)this.rgbColours[i].getGreen();
data[pos + 2] = (byte)this.rgbColours[i].getBlue();
}
return data;
}
private void initialize() {
byte[] data = getRecord().getData();
int numrecords = IntegerHelper.getInt(data[0], data[1]);
for (int i = 0; i < numrecords; i++) {
int pos = i * 4 + 2;
int red = IntegerHelper.getInt(data[pos], (byte)0);
int green = IntegerHelper.getInt(data[pos + 1], (byte)0);
int blue = IntegerHelper.getInt(data[pos + 2], (byte)0);
this.rgbColours[i] = new RGB(red, green, blue);
}
this.initialized = true;
}
public boolean isDirty() {
return this.dirty;
}
public void setColourRGB(Colour c, int r, int g, int b) {
int pos = c.getValue() - 8;
if (pos < 0 || pos >= 56)
return;
if (!this.initialized)
initialize();
r = setValueRange(r, 0, 255);
g = setValueRange(g, 0, 255);
b = setValueRange(b, 0, 255);
this.rgbColours[pos] = new RGB(r, g, b);
this.dirty = true;
}
public RGB getColourRGB(Colour c) {
int pos = c.getValue() - 8;
if (pos < 0 || pos >= 56)
return c.getDefaultRGB();
if (!this.initialized)
initialize();
return this.rgbColours[pos];
}
private int setValueRange(int val, int min, int max) {
val = Math.max(val, min);
val = Math.min(val, max);
return val;
}
}

View File

@@ -0,0 +1,56 @@
package jxl.biff;
import common.Logger;
import jxl.Cell;
import jxl.Range;
import jxl.Sheet;
public class RangeImpl implements Range {
private static Logger logger = Logger.getLogger(RangeImpl.class);
private WorkbookMethods workbook;
private int sheet1;
private int column1;
private int row1;
private int sheet2;
private int column2;
private int row2;
public RangeImpl(WorkbookMethods w, int s1, int c1, int r1, int s2, int c2, int r2) {
this.workbook = w;
this.sheet1 = s1;
this.sheet2 = s2;
this.row1 = r1;
this.row2 = r2;
this.column1 = c1;
this.column2 = c2;
}
public Cell getTopLeft() {
Sheet s = this.workbook.getReadSheet(this.sheet1);
if (this.column1 < s.getColumns() && this.row1 < s.getRows())
return s.getCell(this.column1, this.row1);
return (Cell)new EmptyCell(this.column1, this.row1);
}
public Cell getBottomRight() {
Sheet s = this.workbook.getReadSheet(this.sheet2);
if (this.column2 < s.getColumns() && this.row2 < s.getRows())
return s.getCell(this.column2, this.row2);
return (Cell)new EmptyCell(this.column2, this.row2);
}
public int getFirstSheetIndex() {
return this.sheet1;
}
public int getLastSheetIndex() {
return this.sheet2;
}
}

View File

@@ -0,0 +1,26 @@
package jxl.biff;
import jxl.read.biff.Record;
public abstract class RecordData {
private Record record;
private int code;
protected RecordData(Record r) {
this.record = r;
this.code = r.getCode();
}
protected RecordData(Type t) {
this.code = t.value;
}
protected Record getRecord() {
return this.record;
}
protected final int getCode() {
return this.code;
}
}

View File

@@ -0,0 +1,114 @@
package jxl.biff;
import jxl.Cell;
import jxl.Range;
import jxl.Sheet;
public class SheetRangeImpl implements Range {
private Sheet sheet;
private int column1;
private int row1;
private int column2;
private int row2;
public SheetRangeImpl(Sheet s, int c1, int r1, int c2, int r2) {
this.sheet = s;
this.row1 = r1;
this.row2 = r2;
this.column1 = c1;
this.column2 = c2;
}
public SheetRangeImpl(SheetRangeImpl c, Sheet s) {
this.sheet = s;
this.row1 = c.row1;
this.row2 = c.row2;
this.column1 = c.column1;
this.column2 = c.column2;
}
public Cell getTopLeft() {
return this.sheet.getCell(this.column1, this.row1);
}
public Cell getBottomRight() {
return this.sheet.getCell(this.column2, this.row2);
}
public int getFirstSheetIndex() {
return -1;
}
public int getLastSheetIndex() {
return -1;
}
public boolean intersects(SheetRangeImpl range) {
if (range == this)
return true;
if (this.row2 < range.row1 || this.row1 > range.row2 || this.column2 < range.column1 || this.column1 > range.column2)
return false;
return true;
}
public String toString() {
StringBuffer sb = new StringBuffer();
CellReferenceHelper.getCellReference(this.column1, this.row1, sb);
sb.append('-');
CellReferenceHelper.getCellReference(this.column2, this.row2, sb);
return sb.toString();
}
public void insertRow(int r) {
if (r > this.row2)
return;
if (r <= this.row1)
this.row1++;
if (r <= this.row2)
this.row2++;
}
public void insertColumn(int c) {
if (c > this.column2)
return;
if (c <= this.column1)
this.column1++;
if (c <= this.column2)
this.column2++;
}
public void removeRow(int r) {
if (r > this.row2)
return;
if (r < this.row1)
this.row1--;
if (r < this.row2)
this.row2--;
}
public void removeColumn(int c) {
if (c > this.column2)
return;
if (c < this.column1)
this.column1--;
if (c < this.column2)
this.column2--;
}
public int hashCode() {
return 0xFFFF ^ this.row1 ^ this.row2 ^ this.column1 ^ this.column2;
}
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof SheetRangeImpl))
return false;
SheetRangeImpl compare = (SheetRangeImpl)o;
return (this.column1 == compare.column1 && this.column2 == compare.column2 && this.row1 == compare.row1 && this.row2 == compare.row2);
}
}

View File

@@ -0,0 +1,79 @@
package jxl.biff;
import common.Logger;
import java.io.UnsupportedEncodingException;
import jxl.WorkbookSettings;
public final class StringHelper {
private static Logger logger = Logger.getLogger(StringHelper.class);
public static byte[] getBytes(String s) {
return s.getBytes();
}
public static byte[] getBytes(String s, WorkbookSettings ws) {
try {
return s.getBytes(ws.getEncoding());
} catch (UnsupportedEncodingException e) {
return null;
}
}
public static byte[] getUnicodeBytes(String s) {
try {
byte[] b = s.getBytes("UnicodeLittle");
if (b.length == s.length() * 2 + 2) {
byte[] b2 = new byte[b.length - 2];
System.arraycopy(b, 2, b2, 0, b2.length);
b = b2;
}
return b;
} catch (UnsupportedEncodingException e) {
return null;
}
}
public static void getBytes(String s, byte[] d, int pos) {
byte[] b = getBytes(s);
System.arraycopy(b, 0, d, pos, b.length);
}
public static void getUnicodeBytes(String s, byte[] d, int pos) {
byte[] b = getUnicodeBytes(s);
System.arraycopy(b, 0, d, pos, b.length);
}
public static String getString(byte[] d, int length, int pos, WorkbookSettings ws) {
try {
byte[] b = new byte[length];
System.arraycopy(d, pos, b, 0, length);
return new String(b, ws.getEncoding());
} catch (UnsupportedEncodingException e) {
logger.warn(e.toString());
return "";
}
}
public static String getUnicodeString(byte[] d, int length, int pos) {
try {
byte[] b = new byte[length * 2];
System.arraycopy(d, pos, b, 0, length * 2);
return new String(b, "UnicodeLittle");
} catch (UnsupportedEncodingException e) {
return "";
}
}
public static final String replace(String input, String search, String replace) {
String fmtstr = input;
int pos = fmtstr.indexOf(search);
while (pos != -1) {
StringBuffer tmp = new StringBuffer(fmtstr.substring(0, pos));
tmp.append(replace);
tmp.append(fmtstr.substring(pos + search.length()));
fmtstr = tmp.toString();
pos = fmtstr.indexOf(search, pos + replace.length());
}
return fmtstr;
}
}

272
hrmsEjb/jxl/biff/Type.java Normal file
View File

@@ -0,0 +1,272 @@
package jxl.biff;
public final class Type {
public final int value;
private static Type[] types = new Type[0];
private Type(int v) {
this.value = v;
Type[] newTypes = new Type[types.length + 1];
System.arraycopy(types, 0, newTypes, 0, types.length);
newTypes[types.length] = this;
types = newTypes;
}
private static class ArbitraryType {
private ArbitraryType() {}
}
private static ArbitraryType arbitrary = new ArbitraryType();
private Type(int v, ArbitraryType arb) {
this.value = v;
}
public int hashCode() {
return this.value;
}
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Type))
return false;
Type t = (Type)o;
return (this.value == t.value);
}
public static Type getType(int v) {
for (int i = 0; i < types.length; i++) {
if ((types[i]).value == v)
return types[i];
}
return UNKNOWN;
}
public static Type createType(int v) {
return new Type(v, arbitrary);
}
public static final Type BOF = new Type(2057);
public static final Type EOF = new Type(10);
public static final Type BOUNDSHEET = new Type(133);
public static final Type SUPBOOK = new Type(430);
public static final Type EXTERNSHEET = new Type(23);
public static final Type DIMENSION = new Type(512);
public static final Type BLANK = new Type(513);
public static final Type MULBLANK = new Type(190);
public static final Type ROW = new Type(520);
public static final Type NOTE = new Type(28);
public static final Type TXO = new Type(438);
public static final Type RK = new Type(126);
public static final Type RK2 = new Type(638);
public static final Type MULRK = new Type(189);
public static final Type INDEX = new Type(523);
public static final Type DBCELL = new Type(215);
public static final Type SST = new Type(252);
public static final Type COLINFO = new Type(125);
public static final Type EXTSST = new Type(255);
public static final Type CONTINUE = new Type(60);
public static final Type LABEL = new Type(516);
public static final Type RSTRING = new Type(214);
public static final Type LABELSST = new Type(253);
public static final Type NUMBER = new Type(515);
public static final Type NAME = new Type(24);
public static final Type TABID = new Type(317);
public static final Type ARRAY = new Type(545);
public static final Type STRING = new Type(519);
public static final Type FORMULA = new Type(1030);
public static final Type FORMULA2 = new Type(6);
public static final Type SHAREDFORMULA = new Type(1212);
public static final Type FORMAT = new Type(1054);
public static final Type XF = new Type(224);
public static final Type BOOLERR = new Type(517);
public static final Type INTERFACEHDR = new Type(225);
public static final Type SAVERECALC = new Type(95);
public static final Type INTERFACEEND = new Type(226);
public static final Type XCT = new Type(89);
public static final Type CRN = new Type(90);
public static final Type DEFCOLWIDTH = new Type(85);
public static final Type DEFAULTROWHEIGHT = new Type(549);
public static final Type WRITEACCESS = new Type(92);
public static final Type WSBOOL = new Type(129);
public static final Type CODEPAGE = new Type(66);
public static final Type DSF = new Type(353);
public static final Type FNGROUPCOUNT = new Type(156);
public static final Type COUNTRY = new Type(140);
public static final Type PROTECT = new Type(18);
public static final Type SCENPROTECT = new Type(221);
public static final Type OBJPROTECT = new Type(99);
public static final Type PRINTHEADERS = new Type(42);
public static final Type HEADER = new Type(20);
public static final Type FOOTER = new Type(21);
public static final Type HCENTER = new Type(131);
public static final Type VCENTER = new Type(132);
public static final Type FILEPASS = new Type(47);
public static final Type SETUP = new Type(161);
public static final Type PRINTGRIDLINES = new Type(43);
public static final Type GRIDSET = new Type(130);
public static final Type GUTS = new Type(128);
public static final Type WINDOWPROTECT = new Type(25);
public static final Type PROT4REV = new Type(431);
public static final Type PROT4REVPASS = new Type(444);
public static final Type PASSWORD = new Type(19);
public static final Type REFRESHALL = new Type(439);
public static final Type WINDOW1 = new Type(61);
public static final Type WINDOW2 = new Type(574);
public static final Type BACKUP = new Type(64);
public static final Type HIDEOBJ = new Type(141);
public static final Type NINETEENFOUR = new Type(34);
public static final Type PRECISION = new Type(14);
public static final Type BOOKBOOL = new Type(218);
public static final Type FONT = new Type(49);
public static final Type MMS = new Type(193);
public static final Type CALCMODE = new Type(13);
public static final Type CALCCOUNT = new Type(12);
public static final Type REFMODE = new Type(15);
public static final Type TEMPLATE = new Type(96);
public static final Type OBJPROJ = new Type(211);
public static final Type DELTA = new Type(16);
public static final Type MERGEDCELLS = new Type(229);
public static final Type ITERATION = new Type(17);
public static final Type STYLE = new Type(659);
public static final Type USESELFS = new Type(352);
public static final Type HORIZONTALPAGEBREAKS = new Type(27);
public static final Type SELECTION = new Type(29);
public static final Type HLINK = new Type(440);
public static final Type OBJ = new Type(93);
public static final Type MSODRAWING = new Type(236);
public static final Type MSODRAWINGGROUP = new Type(235);
public static final Type LEFTMARGIN = new Type(38);
public static final Type RIGHTMARGIN = new Type(39);
public static final Type TOPMARGIN = new Type(40);
public static final Type BOTTOMMARGIN = new Type(41);
public static final Type EXTERNNAME = new Type(35);
public static final Type PALETTE = new Type(146);
public static final Type PLS = new Type(77);
public static final Type SCL = new Type(160);
public static final Type PANE = new Type(65);
public static final Type WEIRD1 = new Type(239);
public static final Type SORT = new Type(144);
public static final Type DV = new Type(446);
public static final Type DVAL = new Type(434);
public static final Type BUTTONPROPERTYSET = new Type(442);
public static final Type FONTX = new Type(4134);
public static final Type IFMT = new Type(4174);
public static final Type FBI = new Type(4192);
public static final Type ALRUNS = new Type(4176);
public static final Type UNKNOWN = new Type(65535);
public static final Type U1C0 = new Type(448);
public static final Type U1C1 = new Type(449);
}

View File

@@ -0,0 +1,11 @@
package jxl.biff;
import jxl.Sheet;
public interface WorkbookMethods {
Sheet getReadSheet(int paramInt);
String getName(int paramInt);
int getNameIndex(String paramString);
}

View File

@@ -0,0 +1,36 @@
package jxl.biff;
import jxl.read.biff.Record;
public class WorkspaceInformationRecord extends WritableRecordData {
private int wsoptions;
private static final int fitToPages = 256;
private static final int defaultOptions = 1217;
public WorkspaceInformationRecord(Record t) {
super(t);
byte[] data = getRecord().getData();
this.wsoptions = IntegerHelper.getInt(data[0], data[1]);
}
public WorkspaceInformationRecord() {
super(Type.WSBOOL);
this.wsoptions = 1217;
}
public boolean getFitToPages() {
return ((this.wsoptions & 0x100) != 0);
}
public void setFitToPages(boolean b) {
this.wsoptions = b ? (this.wsoptions | 0x100) : (this.wsoptions & 0xFFFFFEFF);
}
public byte[] getData() {
byte[] data = new byte[2];
IntegerHelper.getTwoBytes(this.wsoptions, data, 0);
return data;
}
}

View File

@@ -0,0 +1,52 @@
package jxl.biff;
import common.Logger;
import jxl.read.biff.Record;
public abstract class WritableRecordData extends RecordData implements ByteData {
private static Logger logger = Logger.getLogger(WritableRecordData.class);
protected static final int maxRecordLength = 8228;
protected WritableRecordData(Type t) {
super(t);
}
protected WritableRecordData(Record t) {
super(t);
}
public final byte[] getBytes() {
byte[] data = getData();
int dataLength = data.length;
if (data.length > 8224) {
dataLength = 8224;
data = handleContinueRecords(data);
}
byte[] bytes = new byte[data.length + 4];
System.arraycopy(data, 0, bytes, 4, data.length);
IntegerHelper.getTwoBytes(getCode(), bytes, 0);
IntegerHelper.getTwoBytes(dataLength, bytes, 2);
return bytes;
}
private byte[] handleContinueRecords(byte[] data) {
int continuedData = data.length - 8224;
int numContinueRecords = continuedData / 8224 + 1;
byte[] newdata = new byte[data.length + numContinueRecords * 4];
System.arraycopy(data, 0, newdata, 0, 8224);
int oldarraypos = 8224;
int newarraypos = 8224;
for (int i = 0; i < numContinueRecords; i++) {
int length = Math.min(data.length - oldarraypos, 8224);
IntegerHelper.getTwoBytes(Type.CONTINUE.value, newdata, newarraypos);
IntegerHelper.getTwoBytes(length, newdata, newarraypos + 2);
System.arraycopy(data, oldarraypos, newdata, newarraypos + 4, length);
oldarraypos += length;
newarraypos += length + 4;
}
return newdata;
}
protected abstract byte[] getData();
}

View File

@@ -0,0 +1,732 @@
package jxl.biff;
import common.Assert;
import common.Logger;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import jxl.WorkbookSettings;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.CellFormat;
import jxl.format.Colour;
import jxl.format.Font;
import jxl.format.Format;
import jxl.format.Orientation;
import jxl.format.Pattern;
import jxl.format.VerticalAlignment;
import jxl.read.biff.Record;
public class XFRecord extends WritableRecordData implements CellFormat {
private static Logger logger = Logger.getLogger(XFRecord.class);
public int formatIndex;
private int parentFormat;
private XFType xfFormatType;
private boolean date;
private boolean number;
private DateFormat dateFormat;
private NumberFormat numberFormat;
private byte usedAttributes;
private int fontIndex;
private boolean locked;
private boolean hidden;
private Alignment align;
private VerticalAlignment valign;
private Orientation orientation;
private boolean wrap;
private int indentation;
private boolean shrinkToFit;
private BorderLineStyle leftBorder;
private BorderLineStyle rightBorder;
private BorderLineStyle topBorder;
private BorderLineStyle bottomBorder;
private Colour leftBorderColour;
private Colour rightBorderColour;
private Colour topBorderColour;
private Colour bottomBorderColour;
private Colour backgroundColour;
private Pattern pattern;
private int options;
private int xfIndex;
private FontRecord font;
private DisplayFormat format;
private boolean initialized;
private boolean read;
private Format excelFormat;
private boolean formatInfoInitialized;
private boolean copied;
private FormattingRecords formattingRecords;
private static final int[] dateFormats = new int[] {
14, 15, 16, 17, 18, 19, 20, 21, 22, 45,
46, 47 };
private static final DateFormat[] javaDateFormats = new DateFormat[] {
new SimpleDateFormat("dd/MM/yyyy"), new SimpleDateFormat("d-MMM-yy"), new SimpleDateFormat("d-MMM"), new SimpleDateFormat("MMM-yy"), new SimpleDateFormat("h:mm a"), new SimpleDateFormat("h:mm:ss a"), new SimpleDateFormat("H:mm"), new SimpleDateFormat("H:mm:ss"), new SimpleDateFormat("M/d/yy H:mm"), new SimpleDateFormat("mm:ss"),
new SimpleDateFormat("H:mm:ss"), new SimpleDateFormat("mm:ss.S") };
private static int[] numberFormats = new int[] {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 37, 38, 39, 40, 41, 42, 43, 44, 48 };
private static NumberFormat[] javaNumberFormats = new NumberFormat[] {
new DecimalFormat("0"), new DecimalFormat("0.00"), new DecimalFormat("#,##0"), new DecimalFormat("#,##0.00"), new DecimalFormat("$#,##0;($#,##0)"), new DecimalFormat("$#,##0;($#,##0)"), new DecimalFormat("$#,##0.00;($#,##0.00)"), new DecimalFormat("$#,##0.00;($#,##0.00)"), new DecimalFormat("0%"), new DecimalFormat("0.00%"),
new DecimalFormat("0.00E00"), new DecimalFormat("#,##0;(#,##0)"), new DecimalFormat("#,##0;(#,##0)"), new DecimalFormat("#,##0.00;(#,##0.00)"), new DecimalFormat("#,##0.00;(#,##0.00)"), new DecimalFormat("#,##0;(#,##0)"), new DecimalFormat("$#,##0;($#,##0)"), new DecimalFormat("#,##0.00;(#,##0.00)"), new DecimalFormat("$#,##0.00;($#,##0.00)"), new DecimalFormat("##0.0E0") };
private static class BiffType {
private BiffType() {}
}
public static final BiffType biff8 = new BiffType();
public static final BiffType biff7 = new BiffType();
private BiffType biffType;
private static class XFType {
private XFType() {}
}
protected static final XFType cell = new XFType();
protected static final XFType style = new XFType();
public XFRecord(Record t, WorkbookSettings ws, BiffType bt) {
super(t);
this.biffType = bt;
byte[] data = getRecord().getData();
this.fontIndex = IntegerHelper.getInt(data[0], data[1]);
this.formatIndex = IntegerHelper.getInt(data[2], data[3]);
this.date = false;
this.number = false;
int i;
for (i = 0; i < dateFormats.length && !this.date; i++) {
if (this.formatIndex == dateFormats[i]) {
this.date = true;
this.dateFormat = javaDateFormats[i];
}
}
for (i = 0; i < numberFormats.length && !this.number; i++) {
if (this.formatIndex == numberFormats[i]) {
this.number = true;
DecimalFormat df = (DecimalFormat)javaNumberFormats[i].clone();
DecimalFormatSymbols symbols = new DecimalFormatSymbols(ws.getLocale());
df.setDecimalFormatSymbols(symbols);
this.numberFormat = df;
}
}
int cellAttributes = IntegerHelper.getInt(data[4], data[5]);
this.parentFormat = (cellAttributes & 0xFFF0) >> 4;
int formatType = cellAttributes & 0x4;
this.xfFormatType = (formatType == 0) ? cell : style;
this.locked = ((cellAttributes & 0x1) != 0);
this.hidden = ((cellAttributes & 0x2) != 0);
if (this.xfFormatType == cell && (this.parentFormat & 0xFFF) == 4095) {
this.parentFormat = 0;
logger.warn("Invalid parent format found - ignoring");
}
this.initialized = false;
this.read = true;
this.formatInfoInitialized = false;
this.copied = false;
}
public XFRecord(FontRecord fnt, DisplayFormat form) {
super(Type.XF);
this.initialized = false;
this.locked = true;
this.hidden = false;
this.align = Alignment.GENERAL;
this.valign = VerticalAlignment.BOTTOM;
this.orientation = Orientation.HORIZONTAL;
this.wrap = false;
this.leftBorder = BorderLineStyle.NONE;
this.rightBorder = BorderLineStyle.NONE;
this.topBorder = BorderLineStyle.NONE;
this.bottomBorder = BorderLineStyle.NONE;
this.leftBorderColour = Colour.AUTOMATIC;
this.rightBorderColour = Colour.AUTOMATIC;
this.topBorderColour = Colour.AUTOMATIC;
this.bottomBorderColour = Colour.AUTOMATIC;
this.pattern = Pattern.NONE;
this.backgroundColour = Colour.DEFAULT_BACKGROUND;
this.indentation = 0;
this.shrinkToFit = false;
this.parentFormat = 0;
this.xfFormatType = null;
this.font = fnt;
this.format = form;
this.biffType = biff8;
this.read = false;
this.copied = false;
this.formatInfoInitialized = true;
Assert.verify((this.font != null));
Assert.verify((this.format != null));
}
protected XFRecord(XFRecord fmt) {
super(Type.XF);
this.initialized = false;
this.locked = fmt.locked;
this.hidden = fmt.hidden;
this.align = fmt.align;
this.valign = fmt.valign;
this.orientation = fmt.orientation;
this.wrap = fmt.wrap;
this.leftBorder = fmt.leftBorder;
this.rightBorder = fmt.rightBorder;
this.topBorder = fmt.topBorder;
this.bottomBorder = fmt.bottomBorder;
this.leftBorderColour = fmt.leftBorderColour;
this.rightBorderColour = fmt.rightBorderColour;
this.topBorderColour = fmt.topBorderColour;
this.bottomBorderColour = fmt.bottomBorderColour;
this.pattern = fmt.pattern;
this.xfFormatType = fmt.xfFormatType;
this.indentation = fmt.indentation;
this.shrinkToFit = fmt.shrinkToFit;
this.parentFormat = fmt.parentFormat;
this.backgroundColour = fmt.backgroundColour;
this.font = fmt.font;
this.format = fmt.format;
this.fontIndex = fmt.fontIndex;
this.formatIndex = fmt.formatIndex;
this.formatInfoInitialized = fmt.formatInfoInitialized;
this.biffType = biff8;
this.read = false;
this.copied = true;
}
protected XFRecord(CellFormat cellFormat) {
super(Type.XF);
Assert.verify((cellFormat != null));
Assert.verify(cellFormat instanceof XFRecord);
XFRecord fmt = (XFRecord)cellFormat;
if (!fmt.formatInfoInitialized)
fmt.initializeFormatInformation();
this.locked = fmt.locked;
this.hidden = fmt.hidden;
this.align = fmt.align;
this.valign = fmt.valign;
this.orientation = fmt.orientation;
this.wrap = fmt.wrap;
this.leftBorder = fmt.leftBorder;
this.rightBorder = fmt.rightBorder;
this.topBorder = fmt.topBorder;
this.bottomBorder = fmt.bottomBorder;
this.leftBorderColour = fmt.leftBorderColour;
this.rightBorderColour = fmt.rightBorderColour;
this.topBorderColour = fmt.topBorderColour;
this.bottomBorderColour = fmt.bottomBorderColour;
this.pattern = fmt.pattern;
this.xfFormatType = fmt.xfFormatType;
this.parentFormat = fmt.parentFormat;
this.indentation = fmt.indentation;
this.shrinkToFit = fmt.shrinkToFit;
this.backgroundColour = fmt.backgroundColour;
this.font = new FontRecord(fmt.getFont());
if (fmt.getFormat() == null) {
if (fmt.format.isBuiltIn()) {
this.format = fmt.format;
} else {
this.format = new FormatRecord((FormatRecord)fmt.format);
}
} else if (fmt.getFormat() instanceof BuiltInFormat) {
this.excelFormat = fmt.excelFormat;
this.format = (BuiltInFormat)fmt.excelFormat;
} else {
Assert.verify(fmt.formatInfoInitialized);
Assert.verify(fmt.excelFormat instanceof FormatRecord);
FormatRecord fr = new FormatRecord((FormatRecord)fmt.excelFormat);
this.excelFormat = fr;
this.format = fr;
}
this.biffType = biff8;
this.formatInfoInitialized = true;
this.read = false;
this.copied = false;
this.initialized = false;
}
public DateFormat getDateFormat() {
return this.dateFormat;
}
public NumberFormat getNumberFormat() {
return this.numberFormat;
}
public int getFormatRecord() {
return this.formatIndex;
}
public boolean isDate() {
return this.date;
}
public boolean isNumber() {
return this.number;
}
public byte[] getData() {
if (!this.formatInfoInitialized)
initializeFormatInformation();
byte[] data = new byte[20];
IntegerHelper.getTwoBytes(this.fontIndex, data, 0);
IntegerHelper.getTwoBytes(this.formatIndex, data, 2);
int cellAttributes = 0;
if (getLocked())
cellAttributes |= 0x1;
if (getHidden())
cellAttributes |= 0x2;
if (this.xfFormatType == style) {
cellAttributes |= 0x4;
this.parentFormat = 65535;
}
cellAttributes |= this.parentFormat << 4;
IntegerHelper.getTwoBytes(cellAttributes, data, 4);
int alignMask = this.align.getValue();
if (this.wrap)
alignMask |= 0x8;
alignMask |= this.valign.getValue() << 4;
alignMask |= this.orientation.getValue() << 8;
IntegerHelper.getTwoBytes(alignMask, data, 6);
data[9] = 16;
int borderMask = this.leftBorder.getValue();
borderMask |= this.rightBorder.getValue() << 4;
borderMask |= this.topBorder.getValue() << 8;
borderMask |= this.bottomBorder.getValue() << 12;
IntegerHelper.getTwoBytes(borderMask, data, 10);
if (borderMask != 0) {
byte lc = (byte)this.leftBorderColour.getValue();
byte rc = (byte)this.rightBorderColour.getValue();
byte tc = (byte)this.topBorderColour.getValue();
byte bc = (byte)this.bottomBorderColour.getValue();
int sideColourMask = lc & Byte.MAX_VALUE | (rc & Byte.MAX_VALUE) << 7;
int topColourMask = tc & Byte.MAX_VALUE | (bc & Byte.MAX_VALUE) << 7;
IntegerHelper.getTwoBytes(sideColourMask, data, 12);
IntegerHelper.getTwoBytes(topColourMask, data, 14);
}
int patternVal = this.pattern.getValue() << 10;
IntegerHelper.getTwoBytes(patternVal, data, 16);
int colourPaletteMask = this.backgroundColour.getValue();
colourPaletteMask |= 0x2000;
IntegerHelper.getTwoBytes(colourPaletteMask, data, 18);
this.options |= this.indentation & 0xF;
if (this.shrinkToFit) {
this.options |= 0x10;
} else {
this.options &= 0xEF;
}
data[8] = (byte)this.options;
if (this.biffType == biff8)
data[9] = this.usedAttributes;
return data;
}
protected final boolean getLocked() {
return this.locked;
}
protected final boolean getHidden() {
return this.hidden;
}
protected final void setXFLocked(boolean l) {
this.locked = l;
}
protected final void setXFCellOptions(int opt) {
this.options |= opt;
}
protected void setXFAlignment(Alignment a) {
Assert.verify(!this.initialized);
this.align = a;
}
protected void setXFIndentation(int i) {
Assert.verify(!this.initialized);
this.indentation = i;
}
protected void setXFShrinkToFit(boolean s) {
Assert.verify(!this.initialized);
this.shrinkToFit = s;
}
public Alignment getAlignment() {
if (!this.formatInfoInitialized)
initializeFormatInformation();
return this.align;
}
public int getIndentation() {
if (!this.formatInfoInitialized)
initializeFormatInformation();
return this.indentation;
}
public boolean isShrinkToFit() {
if (!this.formatInfoInitialized)
initializeFormatInformation();
return this.shrinkToFit;
}
public boolean isLocked() {
if (!this.formatInfoInitialized)
initializeFormatInformation();
return this.locked;
}
public VerticalAlignment getVerticalAlignment() {
if (!this.formatInfoInitialized)
initializeFormatInformation();
return this.valign;
}
public Orientation getOrientation() {
if (!this.formatInfoInitialized)
initializeFormatInformation();
return this.orientation;
}
protected void setXFBackground(Colour c, Pattern p) {
Assert.verify(!this.initialized);
this.backgroundColour = c;
this.pattern = p;
}
public Colour getBackgroundColour() {
if (!this.formatInfoInitialized)
initializeFormatInformation();
return this.backgroundColour;
}
public Pattern getPattern() {
if (!this.formatInfoInitialized)
initializeFormatInformation();
return this.pattern;
}
protected void setXFVerticalAlignment(VerticalAlignment va) {
Assert.verify(!this.initialized);
this.valign = va;
}
protected void setXFOrientation(Orientation o) {
Assert.verify(!this.initialized);
this.orientation = o;
}
protected void setXFWrap(boolean w) {
Assert.verify(!this.initialized);
this.wrap = w;
}
public boolean getWrap() {
if (!this.formatInfoInitialized)
initializeFormatInformation();
return this.wrap;
}
protected void setXFBorder(Border b, BorderLineStyle ls, Colour c) {
Assert.verify(!this.initialized);
if (c == Colour.BLACK)
c = Colour.PALETTE_BLACK;
if (b == Border.LEFT) {
this.leftBorder = ls;
this.leftBorderColour = c;
} else if (b == Border.RIGHT) {
this.rightBorder = ls;
this.rightBorderColour = c;
} else if (b == Border.TOP) {
this.topBorder = ls;
this.topBorderColour = c;
} else if (b == Border.BOTTOM) {
this.bottomBorder = ls;
this.bottomBorderColour = c;
}
}
public BorderLineStyle getBorder(Border border) {
return getBorderLine(border);
}
public BorderLineStyle getBorderLine(Border border) {
if (border == Border.NONE || border == Border.ALL)
return BorderLineStyle.NONE;
if (!this.formatInfoInitialized)
initializeFormatInformation();
if (border == Border.LEFT)
return this.leftBorder;
if (border == Border.RIGHT)
return this.rightBorder;
if (border == Border.TOP)
return this.topBorder;
if (border == Border.BOTTOM)
return this.bottomBorder;
return BorderLineStyle.NONE;
}
public Colour getBorderColour(Border border) {
if (border == Border.NONE || border == Border.ALL)
return Colour.PALETTE_BLACK;
if (!this.formatInfoInitialized)
initializeFormatInformation();
if (border == Border.LEFT)
return this.leftBorderColour;
if (border == Border.RIGHT)
return this.rightBorderColour;
if (border == Border.TOP)
return this.topBorderColour;
if (border == Border.BOTTOM)
return this.bottomBorderColour;
return Colour.BLACK;
}
public final boolean hasBorders() {
if (!this.formatInfoInitialized)
initializeFormatInformation();
if (this.leftBorder == BorderLineStyle.NONE && this.rightBorder == BorderLineStyle.NONE && this.topBorder == BorderLineStyle.NONE && this.bottomBorder == BorderLineStyle.NONE)
return false;
return true;
}
public final void initialize(int pos, FormattingRecords fr, Fonts fonts) throws NumFormatRecordsException {
this.xfIndex = pos;
this.formattingRecords = fr;
if (this.read || this.copied) {
this.initialized = true;
return;
}
if (!this.font.isInitialized())
fonts.addFont(this.font);
if (!this.format.isInitialized())
fr.addFormat(this.format);
this.fontIndex = this.font.getFontIndex();
this.formatIndex = this.format.getFormatIndex();
this.initialized = true;
}
public final void uninitialize() {
if (this.initialized == true)
logger.warn("A default format has been initialized");
this.initialized = false;
}
final void setXFIndex(int xfi) {
this.xfIndex = xfi;
}
public final int getXFIndex() {
return this.xfIndex;
}
public final boolean isInitialized() {
return this.initialized;
}
public final boolean isRead() {
return this.read;
}
public Format getFormat() {
if (!this.formatInfoInitialized)
initializeFormatInformation();
return this.excelFormat;
}
public Font getFont() {
if (!this.formatInfoInitialized)
initializeFormatInformation();
return this.font;
}
private void initializeFormatInformation() {
if (this.formatIndex < BuiltInFormat.builtIns.length && BuiltInFormat.builtIns[this.formatIndex] != null) {
this.excelFormat = BuiltInFormat.builtIns[this.formatIndex];
} else {
this.excelFormat = this.formattingRecords.getFormatRecord(this.formatIndex);
}
this.font = this.formattingRecords.getFonts().getFont(this.fontIndex);
byte[] data = getRecord().getData();
int cellAttributes = IntegerHelper.getInt(data[4], data[5]);
this.parentFormat = (cellAttributes & 0xFFF0) >> 4;
int formatType = cellAttributes & 0x4;
this.xfFormatType = (formatType == 0) ? cell : style;
this.locked = ((cellAttributes & 0x1) != 0);
this.hidden = ((cellAttributes & 0x2) != 0);
if (this.xfFormatType == cell && (this.parentFormat & 0xFFF) == 4095) {
this.parentFormat = 0;
logger.warn("Invalid parent format found - ignoring");
}
int alignMask = IntegerHelper.getInt(data[6], data[7]);
if ((alignMask & 0x8) != 0)
this.wrap = true;
this.align = Alignment.getAlignment(alignMask & 0x7);
this.valign = VerticalAlignment.getAlignment(alignMask >> 4 & 0x7);
this.orientation = Orientation.getOrientation(alignMask >> 8 & 0xFF);
int attr = IntegerHelper.getInt(data[8], data[9]);
this.indentation = attr & 0xF;
this.shrinkToFit = ((attr & 0x10) != 0);
if (this.biffType == biff8)
this.usedAttributes = data[9];
int borderMask = IntegerHelper.getInt(data[10], data[11]);
this.leftBorder = BorderLineStyle.getStyle(borderMask & 0x7);
this.rightBorder = BorderLineStyle.getStyle(borderMask >> 4 & 0x7);
this.topBorder = BorderLineStyle.getStyle(borderMask >> 8 & 0x7);
this.bottomBorder = BorderLineStyle.getStyle(borderMask >> 12 & 0x7);
int borderColourMask = IntegerHelper.getInt(data[12], data[13]);
this.leftBorderColour = Colour.getInternalColour(borderColourMask & 0x7F);
this.rightBorderColour = Colour.getInternalColour((borderColourMask & 0x3F80) >> 7);
borderColourMask = IntegerHelper.getInt(data[14], data[15]);
this.topBorderColour = Colour.getInternalColour(borderColourMask & 0x7F);
this.bottomBorderColour = Colour.getInternalColour((borderColourMask & 0x3F80) >> 7);
if (this.biffType == biff8) {
int patternVal = IntegerHelper.getInt(data[16], data[17]);
patternVal &= 0xFC00;
patternVal >>= 10;
this.pattern = Pattern.getPattern(patternVal);
int colourPaletteMask = IntegerHelper.getInt(data[18], data[19]);
this.backgroundColour = Colour.getInternalColour(colourPaletteMask & 0x3F);
if (this.backgroundColour == Colour.UNKNOWN || this.backgroundColour == Colour.DEFAULT_BACKGROUND1)
this.backgroundColour = Colour.DEFAULT_BACKGROUND;
} else {
this.pattern = Pattern.NONE;
this.backgroundColour = Colour.DEFAULT_BACKGROUND;
}
this.formatInfoInitialized = true;
}
public int hashCode() {
if (!this.formatInfoInitialized)
initializeFormatInformation();
int hashValue = 17;
int oddPrimeNumber = 37;
hashValue = oddPrimeNumber * hashValue + (this.hidden ? 1 : 0);
hashValue = oddPrimeNumber * hashValue + (this.locked ? 1 : 0);
hashValue = oddPrimeNumber * hashValue + (this.wrap ? 1 : 0);
hashValue = oddPrimeNumber * hashValue + (this.shrinkToFit ? 1 : 0);
if (this.xfFormatType == cell) {
hashValue = oddPrimeNumber * hashValue + 1;
} else if (this.xfFormatType == style) {
hashValue = oddPrimeNumber * hashValue + 2;
}
hashValue = oddPrimeNumber * hashValue + this.align.getValue() + 1;
hashValue = oddPrimeNumber * hashValue + this.valign.getValue() + 1;
hashValue = oddPrimeNumber * hashValue + this.orientation.getValue();
hashValue ^= this.leftBorder.getDescription().hashCode();
hashValue ^= this.rightBorder.getDescription().hashCode();
hashValue ^= this.topBorder.getDescription().hashCode();
hashValue ^= this.bottomBorder.getDescription().hashCode();
hashValue = oddPrimeNumber * hashValue + this.leftBorderColour.getValue();
hashValue = oddPrimeNumber * hashValue + this.rightBorderColour.getValue();
hashValue = oddPrimeNumber * hashValue + this.topBorderColour.getValue();
hashValue = oddPrimeNumber * hashValue + this.bottomBorderColour.getValue();
hashValue = oddPrimeNumber * hashValue + this.backgroundColour.getValue();
hashValue = oddPrimeNumber * hashValue + this.pattern.getValue() + 1;
hashValue = oddPrimeNumber * hashValue + this.usedAttributes;
hashValue = oddPrimeNumber * hashValue + this.parentFormat;
hashValue = oddPrimeNumber * hashValue + this.fontIndex;
hashValue = oddPrimeNumber * hashValue + this.formatIndex;
hashValue = oddPrimeNumber * hashValue + this.indentation;
return hashValue;
}
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof XFRecord))
return false;
XFRecord xfr = (XFRecord)o;
if (!this.formatInfoInitialized)
initializeFormatInformation();
if (!xfr.formatInfoInitialized)
xfr.initializeFormatInformation();
if (this.xfFormatType != xfr.xfFormatType || this.parentFormat != xfr.parentFormat || this.locked != xfr.locked || this.hidden != xfr.hidden || this.usedAttributes != xfr.usedAttributes)
return false;
if (this.align != xfr.align || this.valign != xfr.valign || this.orientation != xfr.orientation || this.wrap != xfr.wrap || this.shrinkToFit != xfr.shrinkToFit || this.indentation != xfr.indentation)
return false;
if (this.leftBorder != xfr.leftBorder || this.rightBorder != xfr.rightBorder || this.topBorder != xfr.topBorder || this.bottomBorder != xfr.bottomBorder)
return false;
if (this.leftBorderColour != xfr.leftBorderColour || this.rightBorderColour != xfr.rightBorderColour || this.topBorderColour != xfr.topBorderColour || this.bottomBorderColour != xfr.bottomBorderColour)
return false;
if (this.backgroundColour != xfr.backgroundColour || this.pattern != xfr.pattern)
return false;
if (this.initialized && xfr.initialized) {
if (this.fontIndex != xfr.fontIndex || this.formatIndex != xfr.formatIndex)
return false;
} else if (!this.font.equals(xfr.font) || !this.format.equals(xfr.format)) {
return false;
}
return true;
}
void setFormatIndex(int newindex) {
this.formatIndex = newindex;
}
int getFontIndex() {
return this.fontIndex;
}
void setFontIndex(int newindex) {
this.fontIndex = newindex;
}
protected void setXFDetails(XFType t, int pf) {
this.xfFormatType = t;
this.parentFormat = pf;
}
void rationalize(IndexMapping xfMapping) {
this.xfIndex = xfMapping.getNewIndex(this.xfIndex);
if (this.xfFormatType == cell)
this.parentFormat = xfMapping.getNewIndex(this.parentFormat);
}
public void setFont(FontRecord f) {
this.font = f;
}
}

View File

@@ -0,0 +1,33 @@
package jxl.biff.drawing;
import common.Logger;
class BStoreContainer extends EscherContainer {
private static Logger logger = Logger.getLogger(BStoreContainer.class);
private int numBlips;
public BStoreContainer(EscherRecordData erd) {
super(erd);
this.numBlips = getInstance();
}
public BStoreContainer() {
super(EscherRecordType.BSTORE_CONTAINER);
}
void setNumBlips(int count) {
this.numBlips = count;
setInstance(this.numBlips);
}
public int getNumBlips() {
return this.numBlips;
}
public BlipStoreEntry getDrawing(int i) {
EscherRecord[] children = getChildren();
BlipStoreEntry bse = (BlipStoreEntry)children[i];
return bse;
}
}

View File

@@ -0,0 +1,84 @@
package jxl.biff.drawing;
import common.Assert;
import common.Logger;
import java.io.IOException;
import jxl.biff.IntegerHelper;
class BlipStoreEntry extends EscherAtom {
private static Logger logger = Logger.getLogger(BlipStoreEntry.class);
private BlipType type;
private byte[] data;
private int imageDataLength;
private int referenceCount;
private boolean write;
private static final int IMAGE_DATA_OFFSET = 61;
public BlipStoreEntry(EscherRecordData erd) {
super(erd);
this.type = BlipType.getType(getInstance());
this.write = false;
byte[] bytes = getBytes();
this.referenceCount = IntegerHelper.getInt(bytes[24], bytes[25], bytes[26], bytes[27]);
}
public BlipStoreEntry(Drawing d) throws IOException {
super(EscherRecordType.BSE);
this.type = BlipType.PNG;
setVersion(2);
setInstance(this.type.getValue());
byte[] imageData = d.getImageBytes();
this.imageDataLength = imageData.length;
this.data = new byte[this.imageDataLength + 61];
System.arraycopy(imageData, 0, this.data, 61, this.imageDataLength);
this.referenceCount = d.getReferenceCount();
this.write = true;
}
public BlipType getBlipType() {
return this.type;
}
public byte[] getData() {
if (this.write) {
this.data[0] = (byte)this.type.getValue();
this.data[1] = (byte)this.type.getValue();
IntegerHelper.getFourBytes(this.imageDataLength + 8 + 17, this.data, 20);
IntegerHelper.getFourBytes(this.referenceCount, this.data, 24);
IntegerHelper.getFourBytes(0, this.data, 28);
this.data[32] = 0;
this.data[33] = 0;
this.data[34] = 126;
this.data[35] = 1;
this.data[36] = 0;
this.data[37] = 110;
IntegerHelper.getTwoBytes(61470, this.data, 38);
IntegerHelper.getFourBytes(this.imageDataLength + 17, this.data, 40);
} else {
this.data = getBytes();
}
return setHeaderData(this.data);
}
void dereference() {
this.referenceCount--;
Assert.verify((this.referenceCount >= 0));
}
int getReferenceCount() {
return this.referenceCount;
}
byte[] getImageData() {
byte[] allData = getBytes();
byte[] imageData = new byte[allData.length - 61];
System.arraycopy(allData, 61, imageData, 0, imageData.length);
return imageData;
}
}

View File

@@ -0,0 +1,57 @@
package jxl.biff.drawing;
final class BlipType {
private int value;
private String desc;
private static BlipType[] types = new BlipType[0];
private BlipType(int val, String d) {
this.value = val;
this.desc = d;
BlipType[] newtypes = new BlipType[types.length + 1];
System.arraycopy(types, 0, newtypes, 0, types.length);
newtypes[types.length] = this;
types = newtypes;
}
public String getDescription() {
return this.desc;
}
public int getValue() {
return this.value;
}
public static BlipType getType(int val) {
BlipType type = UNKNOWN;
for (int i = 0; i < types.length; i++) {
if ((types[i]).value == val) {
type = types[i];
break;
}
}
return type;
}
public static final BlipType ERROR = new BlipType(0, "Error");
public static final BlipType UNKNOWN = new BlipType(1, "Unknown");
public static final BlipType EMF = new BlipType(2, "EMF");
public static final BlipType WMF = new BlipType(3, "WMF");
public static final BlipType PICT = new BlipType(4, "PICT");
public static final BlipType JPEG = new BlipType(5, "JPEG");
public static final BlipType PNG = new BlipType(6, "PNG");
public static final BlipType DIB = new BlipType(7, "DIB");
public static final BlipType FIRST_CLIENT = new BlipType(32, "FIRST");
public static final BlipType LAST_CLIENT = new BlipType(255, "LAST");
}

View File

@@ -0,0 +1,359 @@
package jxl.biff.drawing;
import common.Assert;
import common.Logger;
import java.io.IOException;
import jxl.WorkbookSettings;
import jxl.biff.ByteData;
import jxl.biff.ContinueRecord;
import jxl.biff.IntegerHelper;
import jxl.biff.StringHelper;
import jxl.write.biff.File;
public class Button implements DrawingGroupObject {
private static Logger logger = Logger.getLogger(Button.class);
private EscherContainer readSpContainer;
private EscherContainer spContainer;
private MsoDrawingRecord msoDrawingRecord;
private ObjRecord objRecord;
private boolean initialized = false;
private int objectId;
private int blipId;
private int shapeId;
private int column;
private int row;
private double width;
private double height;
private int referenceCount;
private EscherContainer escherData;
private Origin origin;
private DrawingGroup drawingGroup;
private DrawingData drawingData;
private ShapeType type;
private int drawingNumber;
private MsoDrawingRecord mso;
private TextObjectRecord txo;
private ContinueRecord text;
private ContinueRecord formatting;
private String commentText;
private WorkbookSettings workbookSettings;
public Button(MsoDrawingRecord mso, ObjRecord obj, DrawingData dd, DrawingGroup dg, WorkbookSettings ws) {
this.drawingGroup = dg;
this.msoDrawingRecord = mso;
this.drawingData = dd;
this.objRecord = obj;
this.initialized = false;
this.workbookSettings = ws;
this.origin = Origin.READ;
this.drawingData.addData(this.msoDrawingRecord.getData());
this.drawingNumber = this.drawingData.getNumDrawings() - 1;
this.drawingGroup.addDrawing(this);
Assert.verify((mso != null && obj != null));
initialize();
}
public Button(DrawingGroupObject dgo, DrawingGroup dg, WorkbookSettings ws) {
Button d = (Button)dgo;
Assert.verify((d.origin == Origin.READ));
this.msoDrawingRecord = d.msoDrawingRecord;
this.objRecord = d.objRecord;
this.initialized = false;
this.origin = Origin.READ;
this.drawingData = d.drawingData;
this.drawingGroup = dg;
this.drawingNumber = d.drawingNumber;
this.drawingGroup.addDrawing(this);
this.mso = d.mso;
this.txo = d.txo;
this.text = d.text;
this.formatting = d.formatting;
this.workbookSettings = ws;
}
private void initialize() {
this.readSpContainer = this.drawingData.getSpContainer(this.drawingNumber);
Assert.verify((this.readSpContainer != null));
EscherRecord[] children = this.readSpContainer.getChildren();
Sp sp = (Sp)this.readSpContainer.getChildren()[0];
this.objectId = this.objRecord.getObjectId();
this.shapeId = sp.getShapeId();
this.type = ShapeType.getType(sp.getShapeType());
if (this.type == ShapeType.UNKNOWN)
logger.warn("Unknown shape type");
ClientAnchor clientAnchor = null;
for (int i = 0; i < children.length && clientAnchor == null; i++) {
if (children[i].getType() == EscherRecordType.CLIENT_ANCHOR)
clientAnchor = (ClientAnchor)children[i];
}
if (clientAnchor == null) {
logger.warn("Client anchor not found");
} else {
this.column = (int)clientAnchor.getX1() - 1;
this.row = (int)clientAnchor.getY1() + 1;
}
this.initialized = true;
}
public final void setObjectId(int objid, int bip, int sid) {
this.objectId = objid;
this.blipId = bip;
this.shapeId = sid;
if (this.origin == Origin.READ)
this.origin = Origin.READ_WRITE;
}
public final int getObjectId() {
if (!this.initialized)
initialize();
return this.objectId;
}
public final int getShapeId() {
if (!this.initialized)
initialize();
return this.shapeId;
}
public final int getBlipId() {
if (!this.initialized)
initialize();
return this.blipId;
}
public MsoDrawingRecord getMsoDrawingRecord() {
return this.msoDrawingRecord;
}
public EscherContainer getSpContainer() {
if (!this.initialized)
initialize();
if (this.origin == Origin.READ)
return getReadSpContainer();
Assert.verify(false);
return this.spContainer;
}
public void setDrawingGroup(DrawingGroup dg) {
this.drawingGroup = dg;
}
public DrawingGroup getDrawingGroup() {
return this.drawingGroup;
}
public Origin getOrigin() {
return this.origin;
}
public int getReferenceCount() {
return this.referenceCount;
}
public void setReferenceCount(int r) {
this.referenceCount = r;
}
public double getX() {
if (!this.initialized)
initialize();
return this.column;
}
public void setX(double x) {
if (this.origin == Origin.READ) {
if (!this.initialized)
initialize();
this.origin = Origin.READ_WRITE;
}
this.column = (int)x;
}
public double getY() {
if (!this.initialized)
initialize();
return this.row;
}
public void setY(double y) {
if (this.origin == Origin.READ) {
if (!this.initialized)
initialize();
this.origin = Origin.READ_WRITE;
}
this.row = (int)y;
}
public double getWidth() {
if (!this.initialized)
initialize();
return this.width;
}
public void setWidth(double w) {
if (this.origin == Origin.READ) {
if (!this.initialized)
initialize();
this.origin = Origin.READ_WRITE;
}
this.width = w;
}
public double getHeight() {
if (!this.initialized)
initialize();
return this.height;
}
public void setHeight(double h) {
if (this.origin == Origin.READ) {
if (!this.initialized)
initialize();
this.origin = Origin.READ_WRITE;
}
this.height = h;
}
private EscherContainer getReadSpContainer() {
if (!this.initialized)
initialize();
return this.readSpContainer;
}
public byte[] getImageData() {
Assert.verify((this.origin == Origin.READ || this.origin == Origin.READ_WRITE));
if (!this.initialized)
initialize();
return this.drawingGroup.getImageData(this.blipId);
}
public ShapeType getType() {
return this.type;
}
public void setTextObject(TextObjectRecord t) {
this.txo = t;
}
public void setText(ContinueRecord t) {
this.text = t;
}
public void setFormatting(ContinueRecord t) {
this.formatting = t;
}
public byte[] getImageBytes() {
Assert.verify(false);
return null;
}
public String getImageFilePath() {
Assert.verify(false);
return null;
}
public void addMso(MsoDrawingRecord d) {
this.mso = d;
this.drawingData.addRawData(this.mso.getData());
}
public void writeAdditionalRecords(File outputFile) throws IOException {
if (this.origin == Origin.READ) {
outputFile.write((ByteData)this.objRecord);
if (this.mso != null)
outputFile.write((ByteData)this.mso);
outputFile.write((ByteData)this.txo);
outputFile.write((ByteData)this.text);
if (this.formatting != null)
outputFile.write((ByteData)this.formatting);
return;
}
Assert.verify(false);
ObjRecord objRecord = new ObjRecord(this.objectId, ObjRecord.EXCELNOTE);
outputFile.write((ByteData)objRecord);
ClientTextBox textBox = new ClientTextBox();
MsoDrawingRecord msod = new MsoDrawingRecord(textBox.getData());
outputFile.write((ByteData)msod);
TextObjectRecord txo = new TextObjectRecord(getText());
outputFile.write((ByteData)txo);
byte[] textData = new byte[this.commentText.length() * 2 + 1];
textData[0] = 1;
StringHelper.getUnicodeBytes(this.commentText, textData, 1);
ContinueRecord textContinue = new ContinueRecord(textData);
outputFile.write((ByteData)textContinue);
byte[] frData = new byte[16];
IntegerHelper.getTwoBytes(0, frData, 0);
IntegerHelper.getTwoBytes(0, frData, 2);
IntegerHelper.getTwoBytes(this.commentText.length(), frData, 8);
IntegerHelper.getTwoBytes(0, frData, 10);
ContinueRecord frContinue = new ContinueRecord(frData);
outputFile.write((ByteData)frContinue);
}
public void writeTailRecords(File outputFile) {}
public int getRow() {
return 0;
}
public int getColumn() {
return 0;
}
public String getText() {
if (this.commentText == null) {
Assert.verify((this.text != null));
byte[] td = this.text.getData();
if (td[0] == 0) {
this.commentText = StringHelper.getString(td, td.length - 1, 1, this.workbookSettings);
} else {
this.commentText = StringHelper.getUnicodeString(td, (td.length - 1) / 2, 1);
}
}
return this.commentText;
}
public int hashCode() {
return this.commentText.hashCode();
}
public void setButtonText(String t) {
this.commentText = t;
if (this.origin == Origin.READ)
this.origin = Origin.READ_WRITE;
}
public boolean isFirst() {
return this.mso.isFirst();
}
public boolean isFormObject() {
return true;
}
}

View File

@@ -0,0 +1,111 @@
package jxl.biff.drawing;
import common.Assert;
import common.Logger;
import jxl.WorkbookSettings;
import jxl.biff.ByteData;
import jxl.biff.IndexMapping;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.read.biff.File;
public class Chart implements ByteData, EscherStream {
private static final Logger logger = Logger.getLogger(Chart.class);
private MsoDrawingRecord msoDrawingRecord;
private ObjRecord objRecord;
private int startpos;
private int endpos;
private File file;
private DrawingData drawingData;
private int drawingNumber;
private byte[] data;
private boolean initialized;
private WorkbookSettings workbookSettings;
public Chart(MsoDrawingRecord mso, ObjRecord obj, DrawingData dd, int sp, int ep, File f, WorkbookSettings ws) {
this.msoDrawingRecord = mso;
this.objRecord = obj;
this.startpos = sp;
this.endpos = ep;
this.file = f;
this.workbookSettings = ws;
if (this.msoDrawingRecord != null) {
this.drawingData = dd;
this.drawingData.addData(this.msoDrawingRecord.getRecord().getData());
this.drawingNumber = this.drawingData.getNumDrawings() - 1;
}
this.initialized = false;
Assert.verify(((mso != null && obj != null) || (mso == null && obj == null)));
}
public byte[] getBytes() {
if (!this.initialized)
initialize();
return this.data;
}
public byte[] getData() {
return this.msoDrawingRecord.getRecord().getData();
}
private void initialize() {
this.data = this.file.read(this.startpos, this.endpos - this.startpos);
this.initialized = true;
}
public void rationalize(IndexMapping xfMapping, IndexMapping fontMapping, IndexMapping formatMapping) {
if (!this.initialized)
initialize();
int pos = 0;
int code = 0;
int length = 0;
Type type = null;
while (pos < this.data.length) {
code = IntegerHelper.getInt(this.data[pos], this.data[pos + 1]);
length = IntegerHelper.getInt(this.data[pos + 2], this.data[pos + 3]);
type = Type.getType(code);
if (type == Type.FONTX) {
int fontind = IntegerHelper.getInt(this.data[pos + 4], this.data[pos + 5]);
IntegerHelper.getTwoBytes(fontMapping.getNewIndex(fontind), this.data, pos + 4);
} else if (type == Type.FBI) {
int fontind = IntegerHelper.getInt(this.data[pos + 12], this.data[pos + 13]);
IntegerHelper.getTwoBytes(fontMapping.getNewIndex(fontind), this.data, pos + 12);
} else if (type == Type.IFMT) {
int formind = IntegerHelper.getInt(this.data[pos + 4], this.data[pos + 5]);
IntegerHelper.getTwoBytes(formatMapping.getNewIndex(formind), this.data, pos + 4);
} else if (type == Type.ALRUNS) {
int numRuns = IntegerHelper.getInt(this.data[pos + 4], this.data[pos + 5]);
int fontPos = pos + 6;
for (int i = 0; i < numRuns; i++) {
int fontind = IntegerHelper.getInt(this.data[fontPos + 2], this.data[fontPos + 3]);
IntegerHelper.getTwoBytes(fontMapping.getNewIndex(fontind), this.data, fontPos + 2);
fontPos += 4;
}
}
pos += length + 4;
}
}
EscherContainer getSpContainer() {
EscherContainer spContainer = this.drawingData.getSpContainer(this.drawingNumber);
return spContainer;
}
MsoDrawingRecord getMsoDrawingRecord() {
return this.msoDrawingRecord;
}
ObjRecord getObjRecord() {
return this.objRecord;
}
}

View File

@@ -0,0 +1,77 @@
package jxl.biff.drawing;
import common.Logger;
import jxl.biff.IntegerHelper;
class ClientAnchor extends EscherAtom {
private static final Logger logger = Logger.getLogger(ClientAnchor.class);
private byte[] data;
private double x1;
private double y1;
private double x2;
private double y2;
public ClientAnchor(EscherRecordData erd) {
super(erd);
byte[] bytes = getBytes();
int x1Cell = IntegerHelper.getInt(bytes[2], bytes[3]);
int x1Fraction = IntegerHelper.getInt(bytes[4], bytes[5]);
this.x1 = x1Cell + x1Fraction / 1024.0D;
int y1Cell = IntegerHelper.getInt(bytes[6], bytes[7]);
int y1Fraction = IntegerHelper.getInt(bytes[8], bytes[9]);
this.y1 = y1Cell + y1Fraction / 256.0D;
int x2Cell = IntegerHelper.getInt(bytes[10], bytes[11]);
int x2Fraction = IntegerHelper.getInt(bytes[12], bytes[13]);
this.x2 = x2Cell + x2Fraction / 1024.0D;
int y2Cell = IntegerHelper.getInt(bytes[14], bytes[15]);
int y2Fraction = IntegerHelper.getInt(bytes[16], bytes[17]);
this.y2 = y2Cell + y2Fraction / 256.0D;
}
public ClientAnchor(double x1, double y1, double x2, double y2) {
super(EscherRecordType.CLIENT_ANCHOR);
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
byte[] getData() {
this.data = new byte[18];
IntegerHelper.getTwoBytes(2, this.data, 0);
IntegerHelper.getTwoBytes((int)this.x1, this.data, 2);
int x1fraction = (int)((this.x1 - (int)this.x1) * 1024.0D);
IntegerHelper.getTwoBytes(x1fraction, this.data, 4);
IntegerHelper.getTwoBytes((int)this.y1, this.data, 6);
int y1fraction = (int)((this.y1 - (int)this.y1) * 256.0D);
IntegerHelper.getTwoBytes(y1fraction, this.data, 8);
IntegerHelper.getTwoBytes((int)this.x2, this.data, 10);
int x2fraction = (int)((this.x2 - (int)this.x2) * 1024.0D);
IntegerHelper.getTwoBytes(x2fraction, this.data, 12);
IntegerHelper.getTwoBytes((int)this.y2, this.data, 14);
int y2fraction = (int)((this.y2 - (int)this.y2) * 256.0D);
IntegerHelper.getTwoBytes(y2fraction, this.data, 16);
return setHeaderData(this.data);
}
double getX1() {
return this.x1;
}
double getY1() {
return this.y1;
}
double getX2() {
return this.x2;
}
double getY2() {
return this.y2;
}
}

View File

@@ -0,0 +1,22 @@
package jxl.biff.drawing;
import common.Logger;
class ClientData extends EscherAtom {
private static Logger logger = Logger.getLogger(ClientData.class);
private byte[] data;
public ClientData(EscherRecordData erd) {
super(erd);
}
public ClientData() {
super(EscherRecordType.CLIENT_DATA);
}
byte[] getData() {
this.data = new byte[0];
return setHeaderData(this.data);
}
}

View File

@@ -0,0 +1,22 @@
package jxl.biff.drawing;
import common.Logger;
class ClientTextBox extends EscherAtom {
private static Logger logger = Logger.getLogger(ClientTextBox.class);
private byte[] data;
public ClientTextBox(EscherRecordData erd) {
super(erd);
}
public ClientTextBox() {
super(EscherRecordType.CLIENT_TEXT_BOX);
}
byte[] getData() {
this.data = new byte[0];
return setHeaderData(this.data);
}
}

View File

@@ -0,0 +1,405 @@
package jxl.biff.drawing;
import common.Assert;
import common.Logger;
import java.io.IOException;
import jxl.WorkbookSettings;
import jxl.biff.ByteData;
import jxl.biff.ContinueRecord;
import jxl.biff.IntegerHelper;
import jxl.biff.StringHelper;
import jxl.write.biff.File;
public class Comment implements DrawingGroupObject {
private static Logger logger = Logger.getLogger(Comment.class);
private EscherContainer readSpContainer;
private EscherContainer spContainer;
private MsoDrawingRecord msoDrawingRecord;
private ObjRecord objRecord;
private boolean initialized = false;
private int objectId;
private int blipId;
private int shapeId;
private int column;
private int row;
private double width;
private double height;
private int referenceCount;
private EscherContainer escherData;
private Origin origin;
private DrawingGroup drawingGroup;
private DrawingData drawingData;
private ShapeType type;
private int drawingNumber;
private MsoDrawingRecord mso;
private TextObjectRecord txo;
private NoteRecord note;
private ContinueRecord text;
private ContinueRecord formatting;
private String commentText;
private WorkbookSettings workbookSettings;
public Comment(MsoDrawingRecord mso, ObjRecord obj, DrawingData dd, DrawingGroup dg, WorkbookSettings ws) {
this.drawingGroup = dg;
this.msoDrawingRecord = mso;
this.drawingData = dd;
this.objRecord = obj;
this.initialized = false;
this.workbookSettings = ws;
this.origin = Origin.READ;
this.drawingData.addData(this.msoDrawingRecord.getData());
this.drawingNumber = this.drawingData.getNumDrawings() - 1;
this.drawingGroup.addDrawing(this);
Assert.verify((mso != null && obj != null));
if (!this.initialized)
initialize();
}
public Comment(DrawingGroupObject dgo, DrawingGroup dg, WorkbookSettings ws) {
Comment d = (Comment)dgo;
Assert.verify((d.origin == Origin.READ));
this.msoDrawingRecord = d.msoDrawingRecord;
this.objRecord = d.objRecord;
this.initialized = false;
this.origin = Origin.READ;
this.drawingData = d.drawingData;
this.drawingGroup = dg;
this.drawingNumber = d.drawingNumber;
this.drawingGroup.addDrawing(this);
this.mso = d.mso;
this.txo = d.txo;
this.text = d.text;
this.formatting = d.formatting;
this.note = d.note;
this.width = d.width;
this.height = d.height;
this.workbookSettings = ws;
}
public Comment(String text, int c, int r) {
this.initialized = true;
this.origin = Origin.WRITE;
this.column = c;
this.row = r;
this.referenceCount = 1;
this.type = ShapeType.TEXT_BOX;
this.commentText = text;
this.width = 3.0D;
this.height = 4.0D;
}
private void initialize() {
this.readSpContainer = this.drawingData.getSpContainer(this.drawingNumber);
Assert.verify((this.readSpContainer != null));
EscherRecord[] children = this.readSpContainer.getChildren();
Sp sp = (Sp)this.readSpContainer.getChildren()[0];
this.objectId = this.objRecord.getObjectId();
this.shapeId = sp.getShapeId();
this.type = ShapeType.getType(sp.getShapeType());
if (this.type == ShapeType.UNKNOWN)
logger.warn("Unknown shape type");
ClientAnchor clientAnchor = null;
for (int i = 0; i < children.length && clientAnchor == null; i++) {
if (children[i].getType() == EscherRecordType.CLIENT_ANCHOR)
clientAnchor = (ClientAnchor)children[i];
}
if (clientAnchor == null) {
logger.warn("client anchor not found");
} else {
this.column = (int)clientAnchor.getX1() - 1;
this.row = (int)clientAnchor.getY1() + 1;
this.width = clientAnchor.getX2() - clientAnchor.getX1();
this.height = clientAnchor.getY2() - clientAnchor.getY1();
}
this.initialized = true;
}
public final void setObjectId(int objid, int bip, int sid) {
this.objectId = objid;
this.blipId = bip;
this.shapeId = sid;
if (this.origin == Origin.READ)
this.origin = Origin.READ_WRITE;
}
public final int getObjectId() {
if (!this.initialized)
initialize();
return this.objectId;
}
public final int getShapeId() {
if (!this.initialized)
initialize();
return this.shapeId;
}
public final int getBlipId() {
if (!this.initialized)
initialize();
return this.blipId;
}
public MsoDrawingRecord getMsoDrawingRecord() {
return this.msoDrawingRecord;
}
public EscherContainer getSpContainer() {
if (!this.initialized)
initialize();
if (this.origin == Origin.READ)
return getReadSpContainer();
if (this.spContainer == null) {
this.spContainer = new SpContainer();
Sp sp = new Sp(this.type, this.shapeId, 2560);
this.spContainer.add(sp);
Opt opt = new Opt();
opt.addProperty(344, false, false, 0);
opt.addProperty(385, false, false, 134217808);
opt.addProperty(387, false, false, 134217808);
opt.addProperty(959, false, false, 131074);
this.spContainer.add(opt);
ClientAnchor clientAnchor = new ClientAnchor(this.column + 1.3D, Math.max(0.0D, this.row - 0.6D), this.column + 1.3D + this.width, this.row + this.height);
this.spContainer.add(clientAnchor);
ClientData clientData = new ClientData();
this.spContainer.add(clientData);
ClientTextBox clientTextBox = new ClientTextBox();
this.spContainer.add(clientTextBox);
}
return this.spContainer;
}
public void setDrawingGroup(DrawingGroup dg) {
this.drawingGroup = dg;
}
public DrawingGroup getDrawingGroup() {
return this.drawingGroup;
}
public Origin getOrigin() {
return this.origin;
}
public int getReferenceCount() {
return this.referenceCount;
}
public void setReferenceCount(int r) {
this.referenceCount = r;
}
public double getX() {
if (!this.initialized)
initialize();
return this.column;
}
public void setX(double x) {
if (this.origin == Origin.READ) {
if (!this.initialized)
initialize();
this.origin = Origin.READ_WRITE;
}
this.column = (int)x;
}
public double getY() {
if (!this.initialized)
initialize();
return this.row;
}
public void setY(double y) {
if (this.origin == Origin.READ) {
if (!this.initialized)
initialize();
this.origin = Origin.READ_WRITE;
}
this.row = (int)y;
}
public double getWidth() {
if (!this.initialized)
initialize();
return this.width;
}
public void setWidth(double w) {
if (this.origin == Origin.READ) {
if (!this.initialized)
initialize();
this.origin = Origin.READ_WRITE;
}
this.width = w;
}
public double getHeight() {
if (!this.initialized)
initialize();
return this.height;
}
public void setHeight(double h) {
if (this.origin == Origin.READ) {
if (!this.initialized)
initialize();
this.origin = Origin.READ_WRITE;
}
this.height = h;
}
private EscherContainer getReadSpContainer() {
if (!this.initialized)
initialize();
return this.readSpContainer;
}
public byte[] getImageData() {
Assert.verify((this.origin == Origin.READ || this.origin == Origin.READ_WRITE));
if (!this.initialized)
initialize();
return this.drawingGroup.getImageData(this.blipId);
}
public ShapeType getType() {
return this.type;
}
public void setTextObject(TextObjectRecord t) {
this.txo = t;
}
public void setNote(NoteRecord t) {
this.note = t;
}
public void setText(ContinueRecord t) {
this.text = t;
}
public void setFormatting(ContinueRecord t) {
this.formatting = t;
}
public byte[] getImageBytes() {
Assert.verify(false);
return null;
}
public String getImageFilePath() {
Assert.verify(false);
return null;
}
public void addMso(MsoDrawingRecord d) {
this.mso = d;
this.drawingData.addRawData(this.mso.getData());
}
public void writeAdditionalRecords(File outputFile) throws IOException {
if (this.origin == Origin.READ) {
outputFile.write((ByteData)this.objRecord);
if (this.mso != null)
outputFile.write((ByteData)this.mso);
outputFile.write((ByteData)this.txo);
outputFile.write((ByteData)this.text);
if (this.formatting != null)
outputFile.write((ByteData)this.formatting);
return;
}
ObjRecord objRecord = new ObjRecord(this.objectId, ObjRecord.EXCELNOTE);
outputFile.write((ByteData)objRecord);
ClientTextBox textBox = new ClientTextBox();
MsoDrawingRecord msod = new MsoDrawingRecord(textBox.getData());
outputFile.write((ByteData)msod);
TextObjectRecord txo = new TextObjectRecord(getText());
outputFile.write((ByteData)txo);
byte[] textData = new byte[this.commentText.length() * 2 + 1];
textData[0] = 1;
StringHelper.getUnicodeBytes(this.commentText, textData, 1);
ContinueRecord textContinue = new ContinueRecord(textData);
outputFile.write((ByteData)textContinue);
byte[] frData = new byte[16];
IntegerHelper.getTwoBytes(0, frData, 0);
IntegerHelper.getTwoBytes(0, frData, 2);
IntegerHelper.getTwoBytes(this.commentText.length(), frData, 8);
IntegerHelper.getTwoBytes(0, frData, 10);
ContinueRecord frContinue = new ContinueRecord(frData);
outputFile.write((ByteData)frContinue);
}
public void writeTailRecords(File outputFile) throws IOException {
if (this.origin == Origin.READ) {
outputFile.write((ByteData)this.note);
return;
}
NoteRecord noteRecord = new NoteRecord(this.column, this.row, this.objectId);
outputFile.write((ByteData)noteRecord);
}
public int getRow() {
return this.note.getRow();
}
public int getColumn() {
return this.note.getColumn();
}
public String getText() {
if (this.commentText == null) {
Assert.verify((this.text != null));
byte[] td = this.text.getData();
if (td[0] == 0) {
this.commentText = StringHelper.getString(td, td.length - 1, 1, this.workbookSettings);
} else {
this.commentText = StringHelper.getUnicodeString(td, (td.length - 1) / 2, 1);
}
}
return this.commentText;
}
public int hashCode() {
return this.commentText.hashCode();
}
public void setCommentText(String t) {
this.commentText = t;
if (this.origin == Origin.READ)
this.origin = Origin.READ_WRITE;
}
public boolean isFirst() {
return this.msoDrawingRecord.isFirst();
}
public boolean isFormObject() {
return true;
}
}

View File

@@ -0,0 +1,40 @@
package jxl.biff.drawing;
import jxl.biff.IntegerHelper;
class Dg extends EscherAtom {
private byte[] data;
private int drawingId;
private int shapeCount;
private int seed;
public Dg(EscherRecordData erd) {
super(erd);
this.drawingId = getInstance();
byte[] bytes = getBytes();
this.shapeCount = IntegerHelper.getInt(bytes[0], bytes[1], bytes[2], bytes[3]);
this.seed = IntegerHelper.getInt(bytes[4], bytes[5], bytes[6], bytes[7]);
}
public Dg(int numDrawings) {
super(EscherRecordType.DG);
this.drawingId = 1;
this.shapeCount = numDrawings + 1;
this.seed = 1024 + this.shapeCount + 1;
setInstance(this.drawingId);
}
public int getDrawingId() {
return this.drawingId;
}
byte[] getData() {
this.data = new byte[8];
IntegerHelper.getFourBytes(this.shapeCount, this.data, 0);
IntegerHelper.getFourBytes(this.seed, this.data, 4);
return setHeaderData(this.data);
}
}

View File

@@ -0,0 +1,7 @@
package jxl.biff.drawing;
class DgContainer extends EscherContainer {
public DgContainer() {
super(EscherRecordType.DG_CONTAINER);
}
}

View File

@@ -0,0 +1,91 @@
package jxl.biff.drawing;
import common.Logger;
import java.util.ArrayList;
import jxl.biff.IntegerHelper;
class Dgg extends EscherAtom {
private static Logger logger = Logger.getLogger(Dgg.class);
private byte[] data;
private int numClusters;
private int maxShapeId;
private int shapesSaved;
private int drawingsSaved;
private ArrayList clusters;
static final class Cluster {
int drawingGroupId;
int shapeIdsUsed;
Cluster(int dgId, int sids) {
this.drawingGroupId = dgId;
this.shapeIdsUsed = sids;
}
}
public Dgg(EscherRecordData erd) {
super(erd);
this.clusters = new ArrayList();
byte[] bytes = getBytes();
this.maxShapeId = IntegerHelper.getInt(bytes[0], bytes[1], bytes[2], bytes[3]);
this.numClusters = IntegerHelper.getInt(bytes[4], bytes[5], bytes[6], bytes[7]);
this.shapesSaved = IntegerHelper.getInt(bytes[8], bytes[9], bytes[10], bytes[11]);
this.drawingsSaved = IntegerHelper.getInt(bytes[12], bytes[13], bytes[14], bytes[15]);
int pos = 16;
for (int i = 0; i < this.numClusters; i++) {
int dgId = IntegerHelper.getInt(bytes[pos], bytes[pos + 1]);
int sids = IntegerHelper.getInt(bytes[pos + 2], bytes[pos + 3]);
Cluster c = new Cluster(dgId, sids);
this.clusters.add(c);
pos += 4;
}
}
public Dgg(int numShapes, int numDrawings) {
super(EscherRecordType.DGG);
this.shapesSaved = numShapes;
this.drawingsSaved = numDrawings;
this.clusters = new ArrayList();
}
void addCluster(int dgid, int sids) {
Cluster c = new Cluster(dgid, sids);
this.clusters.add(c);
}
byte[] getData() {
this.numClusters = this.clusters.size();
this.data = new byte[16 + this.numClusters * 4];
IntegerHelper.getFourBytes(1024 + this.shapesSaved, this.data, 0);
IntegerHelper.getFourBytes(this.numClusters, this.data, 4);
IntegerHelper.getFourBytes(this.shapesSaved, this.data, 8);
IntegerHelper.getFourBytes(1, this.data, 12);
int pos = 16;
for (int i = 0; i < this.numClusters; i++) {
Cluster c = this.clusters.get(i);
IntegerHelper.getTwoBytes(c.drawingGroupId, this.data, pos);
IntegerHelper.getTwoBytes(c.shapeIdsUsed, this.data, pos + 2);
pos += 4;
}
return setHeaderData(this.data);
}
int getShapesSaved() {
return this.shapesSaved;
}
int getDrawingsSaved() {
return this.drawingsSaved;
}
Cluster getCluster(int i) {
return this.clusters.get(i);
}
}

View File

@@ -0,0 +1,7 @@
package jxl.biff.drawing;
class DggContainer extends EscherContainer {
public DggContainer() {
super(EscherRecordType.DGG_CONTAINER);
}
}

View File

@@ -0,0 +1,345 @@
package jxl.biff.drawing;
import common.Assert;
import common.Logger;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import jxl.Image;
import jxl.biff.ByteData;
import jxl.write.biff.File;
public class Drawing implements DrawingGroupObject, Image {
private static Logger logger = Logger.getLogger(Drawing.class);
private EscherContainer readSpContainer;
private MsoDrawingRecord msoDrawingRecord;
private ObjRecord objRecord;
private boolean initialized = false;
private File imageFile;
private byte[] imageData;
private int objectId;
private int blipId;
private double x;
private double y;
private double width;
private double height;
private int referenceCount;
private EscherContainer escherData;
private Origin origin;
private DrawingGroup drawingGroup;
private DrawingData drawingData;
private ShapeType type;
private int shapeId;
private int drawingNumber;
public Drawing(MsoDrawingRecord mso, ObjRecord obj, DrawingData dd, DrawingGroup dg) {
this.drawingGroup = dg;
this.msoDrawingRecord = mso;
this.drawingData = dd;
this.objRecord = obj;
this.initialized = false;
this.origin = Origin.READ;
this.drawingData.addData(this.msoDrawingRecord.getData());
this.drawingNumber = this.drawingData.getNumDrawings() - 1;
this.drawingGroup.addDrawing(this);
Assert.verify((mso != null && obj != null));
initialize();
}
protected Drawing(DrawingGroupObject dgo, DrawingGroup dg) {
Drawing d = (Drawing)dgo;
Assert.verify((d.origin == Origin.READ));
this.msoDrawingRecord = d.msoDrawingRecord;
this.objRecord = d.objRecord;
this.initialized = false;
this.origin = Origin.READ;
this.drawingData = d.drawingData;
this.drawingGroup = dg;
this.drawingNumber = d.drawingNumber;
this.drawingGroup.addDrawing(this);
}
public Drawing(double x, double y, double width, double height, File image) {
this.imageFile = image;
this.initialized = true;
this.origin = Origin.WRITE;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.referenceCount = 1;
this.type = ShapeType.PICTURE_FRAME;
}
public Drawing(double x, double y, double width, double height, byte[] image) {
this.imageData = image;
this.initialized = true;
this.origin = Origin.WRITE;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.referenceCount = 1;
this.type = ShapeType.PICTURE_FRAME;
}
private void initialize() {
this.readSpContainer = this.drawingData.getSpContainer(this.drawingNumber);
Assert.verify((this.readSpContainer != null));
EscherRecord[] children = this.readSpContainer.getChildren();
Sp sp = (Sp)this.readSpContainer.getChildren()[0];
this.shapeId = sp.getShapeId();
this.objectId = this.objRecord.getObjectId();
this.type = ShapeType.getType(sp.getShapeType());
if (this.type == ShapeType.UNKNOWN)
logger.warn("Unknown shape type");
Opt opt = (Opt)this.readSpContainer.getChildren()[1];
if (opt.getProperty(260) != null)
this.blipId = (opt.getProperty(260)).value;
if (opt.getProperty(261) != null) {
this.imageFile = new File((opt.getProperty(261)).stringValue);
} else if (this.type == ShapeType.PICTURE_FRAME) {
logger.warn("no filename property for drawing");
this.imageFile = new File(Integer.toString(this.blipId));
}
ClientAnchor clientAnchor = null;
for (int i = 0; i < children.length && clientAnchor == null; i++) {
if (children[i].getType() == EscherRecordType.CLIENT_ANCHOR)
clientAnchor = (ClientAnchor)children[i];
}
if (clientAnchor == null) {
logger.warn("client anchor not found");
} else {
this.x = clientAnchor.getX1();
this.y = clientAnchor.getY1();
this.width = clientAnchor.getX2() - this.x;
this.height = clientAnchor.getY2() - this.y;
}
if (this.blipId == 0)
logger.warn("linked drawings are not supported");
this.initialized = true;
}
public File getImageFile() {
return this.imageFile;
}
public String getImageFilePath() {
if (this.imageFile == null)
return (this.blipId != 0) ? Integer.toString(this.blipId) : "__new__image__";
return this.imageFile.getPath();
}
public final void setObjectId(int objid, int bip, int sid) {
this.objectId = objid;
this.blipId = bip;
this.shapeId = sid;
if (this.origin == Origin.READ)
this.origin = Origin.READ_WRITE;
}
public final int getObjectId() {
if (!this.initialized)
initialize();
return this.objectId;
}
public int getShapeId() {
if (!this.initialized)
initialize();
return this.shapeId;
}
public final int getBlipId() {
if (!this.initialized)
initialize();
return this.blipId;
}
public MsoDrawingRecord getMsoDrawingRecord() {
return this.msoDrawingRecord;
}
public EscherContainer getSpContainer() {
if (!this.initialized)
initialize();
if (this.origin == Origin.READ)
return getReadSpContainer();
SpContainer spContainer = new SpContainer();
Sp sp = new Sp(this.type, this.shapeId, 2560);
spContainer.add(sp);
Opt opt = new Opt();
opt.addProperty(260, true, false, this.blipId);
if (this.type == ShapeType.PICTURE_FRAME) {
String filePath = (this.imageFile != null) ? this.imageFile.getPath() : "";
opt.addProperty(261, true, true, filePath.length() * 2, filePath);
opt.addProperty(447, false, false, 65536);
opt.addProperty(959, false, false, 524288);
spContainer.add(opt);
}
ClientAnchor clientAnchor = new ClientAnchor(this.x, this.y, this.x + this.width, this.y + this.height);
spContainer.add(clientAnchor);
ClientData clientData = new ClientData();
spContainer.add(clientData);
return spContainer;
}
public void setDrawingGroup(DrawingGroup dg) {
this.drawingGroup = dg;
}
public DrawingGroup getDrawingGroup() {
return this.drawingGroup;
}
public Origin getOrigin() {
return this.origin;
}
public int getReferenceCount() {
return this.referenceCount;
}
public void setReferenceCount(int r) {
this.referenceCount = r;
}
public double getX() {
if (!this.initialized)
initialize();
return this.x;
}
public void setX(double x) {
if (this.origin == Origin.READ) {
if (!this.initialized)
initialize();
this.origin = Origin.READ_WRITE;
}
this.x = x;
}
public double getY() {
if (!this.initialized)
initialize();
return this.y;
}
public void setY(double y) {
if (this.origin == Origin.READ) {
if (!this.initialized)
initialize();
this.origin = Origin.READ_WRITE;
}
this.y = y;
}
public double getWidth() {
if (!this.initialized)
initialize();
return this.width;
}
public void setWidth(double w) {
if (this.origin == Origin.READ) {
if (!this.initialized)
initialize();
this.origin = Origin.READ_WRITE;
}
this.width = w;
}
public double getHeight() {
if (!this.initialized)
initialize();
return this.height;
}
public void setHeight(double h) {
if (this.origin == Origin.READ) {
if (!this.initialized)
initialize();
this.origin = Origin.READ_WRITE;
}
this.height = h;
}
private EscherContainer getReadSpContainer() {
if (!this.initialized)
initialize();
return this.readSpContainer;
}
public byte[] getImageData() {
Assert.verify((this.origin == Origin.READ || this.origin == Origin.READ_WRITE));
if (!this.initialized)
initialize();
return this.drawingGroup.getImageData(this.blipId);
}
public byte[] getImageBytes() throws IOException {
if (this.origin == Origin.READ || this.origin == Origin.READ_WRITE)
return getImageData();
Assert.verify((this.origin == Origin.WRITE));
if (this.imageFile == null) {
Assert.verify((this.imageData != null));
return this.imageData;
}
byte[] data = new byte[(int)this.imageFile.length()];
FileInputStream fis = new FileInputStream(this.imageFile);
fis.read(data, 0, data.length);
fis.close();
return data;
}
public ShapeType getType() {
return this.type;
}
public void writeAdditionalRecords(File outputFile) throws IOException {
if (this.origin == Origin.READ) {
outputFile.write((ByteData)this.objRecord);
return;
}
ObjRecord objRecord = new ObjRecord(this.objectId, ObjRecord.PICTURE);
outputFile.write((ByteData)objRecord);
}
public void writeTailRecords(File outputFile) throws IOException {}
public double getColumn() {
return getX();
}
public double getRow() {
return getY();
}
public boolean isFirst() {
return this.msoDrawingRecord.isFirst();
}
public boolean isFormObject() {
return false;
}
}

View File

@@ -0,0 +1,93 @@
package jxl.biff.drawing;
import common.Assert;
import common.Logger;
import java.util.ArrayList;
public class DrawingData implements EscherStream {
private static Logger logger = Logger.getLogger(DrawingData.class);
private int numDrawings = 0;
private byte[] drawingData = null;
private boolean initialized = false;
private EscherRecord[] spContainers;
private void initialize() {
EscherRecordData er = new EscherRecordData(this, 0);
Assert.verify(er.isContainer());
EscherContainer dgContainer = new EscherContainer(er);
EscherRecord[] children = dgContainer.getChildren();
children = dgContainer.getChildren();
EscherContainer spgrContainer = null;
for (int i = 0; i < children.length && spgrContainer == null; i++) {
EscherRecord child = children[i];
if (child.getType() == EscherRecordType.SPGR_CONTAINER)
spgrContainer = (EscherContainer)child;
}
Assert.verify((spgrContainer != null));
EscherRecord[] spgrChildren = spgrContainer.getChildren();
boolean nestedContainers = false;
for (int j = 0; j < spgrChildren.length && !nestedContainers; j++) {
if (spgrChildren[j].getType() == EscherRecordType.SPGR_CONTAINER)
nestedContainers = true;
}
if (!nestedContainers) {
this.spContainers = spgrChildren;
} else {
ArrayList sps = new ArrayList();
getSpContainers(spgrContainer, sps);
this.spContainers = new EscherRecord[sps.size()];
this.spContainers = (EscherRecord[])sps.toArray((Object[])this.spContainers);
}
this.initialized = true;
}
private void getSpContainers(EscherContainer spgrContainer, ArrayList sps) {
EscherRecord[] spgrChildren = spgrContainer.getChildren();
for (int i = 0; i < spgrChildren.length; i++) {
if (spgrChildren[i].getType() == EscherRecordType.SP_CONTAINER) {
sps.add(spgrChildren[i]);
} else if (spgrChildren[i].getType() == EscherRecordType.SPGR_CONTAINER) {
getSpContainers((EscherContainer)spgrChildren[i], sps);
} else {
logger.warn("Spgr Containers contains a record other than Sp/Spgr containers");
}
}
}
public void addData(byte[] data) {
addRawData(data);
this.numDrawings++;
}
public void addRawData(byte[] data) {
if (this.drawingData == null) {
this.drawingData = data;
return;
}
byte[] newArray = new byte[this.drawingData.length + data.length];
System.arraycopy(this.drawingData, 0, newArray, 0, this.drawingData.length);
System.arraycopy(data, 0, newArray, this.drawingData.length, data.length);
this.drawingData = newArray;
this.initialized = false;
}
final int getNumDrawings() {
return this.numDrawings;
}
EscherContainer getSpContainer(int drawingNum) {
if (!this.initialized)
initialize();
EscherContainer spContainer = (EscherContainer)this.spContainers[drawingNum + 1];
Assert.verify((spContainer != null));
return spContainer;
}
public byte[] getData() {
return this.drawingData;
}
}

View File

@@ -0,0 +1,279 @@
package jxl.biff.drawing;
import common.Assert;
import common.Logger;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import jxl.biff.ByteData;
import jxl.read.biff.Record;
import jxl.write.biff.File;
public class DrawingGroup implements EscherStream {
private static Logger logger = Logger.getLogger(DrawingGroup.class);
private byte[] drawingData;
private EscherContainer escherData;
private BStoreContainer bstoreContainer;
private boolean initialized;
private ArrayList drawings;
private int numBlips;
private int numCharts;
private int drawingGroupId;
private boolean drawingsOmitted;
private Origin origin;
private HashMap imageFiles;
private int maxObjectId;
private int maxShapeId;
public DrawingGroup(Origin o) {
this.origin = o;
this.initialized = (o == Origin.WRITE);
this.drawings = new ArrayList();
this.imageFiles = new HashMap();
this.drawingsOmitted = false;
this.maxObjectId = 1;
this.maxShapeId = 1024;
}
public DrawingGroup(DrawingGroup dg) {
this.drawingData = dg.drawingData;
this.escherData = dg.escherData;
this.bstoreContainer = dg.bstoreContainer;
this.initialized = dg.initialized;
this.drawingData = dg.drawingData;
this.escherData = dg.escherData;
this.bstoreContainer = dg.bstoreContainer;
this.numBlips = dg.numBlips;
this.numCharts = dg.numCharts;
this.drawingGroupId = dg.drawingGroupId;
this.drawingsOmitted = dg.drawingsOmitted;
this.origin = dg.origin;
this.imageFiles = (HashMap)dg.imageFiles.clone();
this.maxObjectId = dg.maxObjectId;
this.maxShapeId = dg.maxShapeId;
this.drawings = new ArrayList();
}
public void add(MsoDrawingGroupRecord mso) {
addData(mso.getData());
}
public void add(Record cont) {
addData(cont.getData());
}
private void addData(byte[] msodata) {
if (this.drawingData == null) {
this.drawingData = new byte[msodata.length];
System.arraycopy(msodata, 0, this.drawingData, 0, msodata.length);
return;
}
byte[] newdata = new byte[this.drawingData.length + msodata.length];
System.arraycopy(this.drawingData, 0, newdata, 0, this.drawingData.length);
System.arraycopy(msodata, 0, newdata, this.drawingData.length, msodata.length);
this.drawingData = newdata;
}
final void addDrawing(DrawingGroupObject d) {
this.drawings.add(d);
this.maxObjectId = Math.max(this.maxObjectId, d.getObjectId());
this.maxShapeId = Math.max(this.maxShapeId, d.getShapeId());
}
public void add(Chart c) {
this.numCharts++;
}
public void add(DrawingGroupObject d) {
if (this.origin == Origin.READ) {
this.origin = Origin.READ_WRITE;
BStoreContainer bsc = getBStoreContainer();
Dgg dgg = (Dgg)this.escherData.getChildren()[0];
this.drawingGroupId = (dgg.getCluster(1)).drawingGroupId - this.numBlips - 1;
this.numBlips = (bsc != null) ? bsc.getNumBlips() : 0;
if (bsc != null)
Assert.verify((this.numBlips == bsc.getNumBlips()));
}
if (!(d instanceof Drawing)) {
this.maxObjectId++;
this.maxShapeId++;
d.setDrawingGroup(this);
d.setObjectId(this.maxObjectId, this.numBlips + 1, this.maxShapeId);
if (this.drawings.size() > this.maxObjectId)
logger.warn("drawings length " + this.drawings.size() + " exceeds the max object id " + this.maxObjectId);
return;
}
Drawing drawing = (Drawing)d;
Drawing refImage = (Drawing)this.imageFiles.get(d.getImageFilePath());
if (refImage == null) {
this.maxObjectId++;
this.maxShapeId++;
this.drawings.add(drawing);
drawing.setDrawingGroup(this);
drawing.setObjectId(this.maxObjectId, this.numBlips + 1, this.maxShapeId);
this.numBlips++;
this.imageFiles.put(drawing.getImageFilePath(), drawing);
} else {
refImage.setReferenceCount(refImage.getReferenceCount() + 1);
drawing.setDrawingGroup(this);
drawing.setObjectId(refImage.getObjectId(), refImage.getBlipId(), refImage.getShapeId());
}
}
public void remove(DrawingGroupObject d) {
if (getBStoreContainer() == null)
return;
if (this.origin == Origin.READ) {
this.origin = Origin.READ_WRITE;
this.numBlips = getBStoreContainer().getNumBlips();
Dgg dgg = (Dgg)this.escherData.getChildren()[0];
this.drawingGroupId = (dgg.getCluster(1)).drawingGroupId - this.numBlips - 1;
}
EscherRecord[] children = getBStoreContainer().getChildren();
BlipStoreEntry bse = (BlipStoreEntry)children[d.getBlipId() - 1];
bse.dereference();
if (bse.getReferenceCount() == 0) {
getBStoreContainer().remove(bse);
for (Iterator i = this.drawings.iterator(); i.hasNext(); ) {
DrawingGroupObject drawing = i.next();
if (drawing.getBlipId() > d.getBlipId())
drawing.setObjectId(drawing.getObjectId(), drawing.getBlipId() - 1, drawing.getShapeId());
}
this.numBlips--;
}
}
private void initialize() {
EscherRecordData er = new EscherRecordData(this, 0);
Assert.verify(er.isContainer());
this.escherData = new EscherContainer(er);
Assert.verify((this.escherData.getLength() == this.drawingData.length));
Assert.verify((this.escherData.getType() == EscherRecordType.DGG_CONTAINER));
this.initialized = true;
}
private BStoreContainer getBStoreContainer() {
if (this.bstoreContainer == null) {
if (!this.initialized)
initialize();
EscherRecord[] children = this.escherData.getChildren();
if (children.length > 1 && children[1].getType() == EscherRecordType.BSTORE_CONTAINER)
this.bstoreContainer = (BStoreContainer)children[1];
}
return this.bstoreContainer;
}
public byte[] getData() {
return this.drawingData;
}
public void write(File outputFile) throws IOException {
if (this.origin == Origin.WRITE) {
DggContainer dggContainer = new DggContainer();
Dgg dgg = new Dgg(this.numBlips + this.numCharts + 1, this.numBlips);
dgg.addCluster(1, 0);
dgg.addCluster(this.numBlips + 1, 0);
dggContainer.add(dgg);
int drawingsAdded = 0;
BStoreContainer bstoreCont = new BStoreContainer();
for (Iterator i = this.drawings.iterator(); i.hasNext(); ) {
Object o = i.next();
if (o instanceof Drawing) {
Drawing d = (Drawing)o;
BlipStoreEntry bse = new BlipStoreEntry(d);
bstoreCont.add(bse);
drawingsAdded++;
}
}
if (drawingsAdded > 0) {
bstoreCont.setNumBlips(drawingsAdded);
dggContainer.add(bstoreCont);
}
Opt opt = new Opt();
dggContainer.add(opt);
SplitMenuColors splitMenuColors = new SplitMenuColors();
dggContainer.add(splitMenuColors);
this.drawingData = dggContainer.getData();
} else if (this.origin == Origin.READ_WRITE) {
DggContainer dggContainer = new DggContainer();
Dgg dgg = new Dgg(this.numBlips + this.numCharts + 1, this.numBlips);
dgg.addCluster(1, 0);
dgg.addCluster(this.drawingGroupId + this.numBlips + 1, 0);
dggContainer.add(dgg);
BStoreContainer bstoreCont = new BStoreContainer();
bstoreCont.setNumBlips(this.numBlips);
BStoreContainer readBStoreContainer = getBStoreContainer();
if (readBStoreContainer != null) {
EscherRecord[] children = readBStoreContainer.getChildren();
for (int j = 0; j < children.length; j++) {
BlipStoreEntry bse = (BlipStoreEntry)children[j];
bstoreCont.add(bse);
}
}
for (Iterator i = this.drawings.iterator(); i.hasNext(); ) {
DrawingGroupObject dgo = i.next();
if (dgo instanceof Drawing) {
Drawing d = (Drawing)dgo;
if (d.getOrigin() != Origin.READ) {
BlipStoreEntry bse = new BlipStoreEntry(d);
bstoreCont.add(bse);
}
}
}
dggContainer.add(bstoreCont);
Opt opt = new Opt();
opt.addProperty(191, false, false, 524296);
opt.addProperty(385, false, false, 134217737);
opt.addProperty(448, false, false, 134217792);
dggContainer.add(opt);
SplitMenuColors splitMenuColors = new SplitMenuColors();
dggContainer.add(splitMenuColors);
this.drawingData = dggContainer.getData();
}
MsoDrawingGroupRecord msodg = new MsoDrawingGroupRecord(this.drawingData);
outputFile.write((ByteData)msodg);
}
final int getNumberOfBlips() {
return this.numBlips;
}
byte[] getImageData(int blipId) {
this.numBlips = getBStoreContainer().getNumBlips();
Assert.verify((blipId <= this.numBlips));
Assert.verify((this.origin == Origin.READ || this.origin == Origin.READ_WRITE));
EscherRecord[] children = getBStoreContainer().getChildren();
BlipStoreEntry bse = (BlipStoreEntry)children[blipId - 1];
return bse.getImageData();
}
public void setDrawingsOmitted(MsoDrawingRecord mso, ObjRecord obj) {
this.drawingsOmitted = true;
if (obj != null)
this.maxObjectId = Math.max(this.maxObjectId, obj.getObjectId());
}
public boolean hasDrawingsOmitted() {
return this.drawingsOmitted;
}
public void updateData(DrawingGroup dg) {
this.drawingsOmitted = dg.drawingsOmitted;
this.maxObjectId = dg.maxObjectId;
this.maxShapeId = dg.maxShapeId;
}
}

View File

@@ -0,0 +1,60 @@
package jxl.biff.drawing;
import java.io.IOException;
import jxl.write.biff.File;
public interface DrawingGroupObject {
void setObjectId(int paramInt1, int paramInt2, int paramInt3);
int getObjectId();
int getBlipId();
int getShapeId();
MsoDrawingRecord getMsoDrawingRecord();
EscherContainer getSpContainer();
void setDrawingGroup(DrawingGroup paramDrawingGroup);
DrawingGroup getDrawingGroup();
Origin getOrigin();
int getReferenceCount();
void setReferenceCount(int paramInt);
double getX();
void setX(double paramDouble);
double getY();
void setY(double paramDouble);
double getWidth();
void setWidth(double paramDouble);
double getHeight();
void setHeight(double paramDouble);
ShapeType getType();
byte[] getImageData();
byte[] getImageBytes() throws IOException;
String getImageFilePath();
void writeAdditionalRecords(File paramFile) throws IOException;
void writeTailRecords(File paramFile) throws IOException;
boolean isFirst();
boolean isFormObject();
}

View File

@@ -0,0 +1,20 @@
package jxl.biff.drawing;
import common.Logger;
class EscherAtom extends EscherRecord {
private static Logger logger = Logger.getLogger(EscherAtom.class);
public EscherAtom(EscherRecordData erd) {
super(erd);
}
protected EscherAtom(EscherRecordType type) {
super(type);
}
byte[] getData() {
logger.warn("escher atom getData called on object of type " + getClass().getName() + " code " + Integer.toString(getType().getValue(), 16));
return null;
}
}

View File

@@ -0,0 +1,99 @@
package jxl.biff.drawing;
import common.Logger;
import java.util.ArrayList;
import java.util.Iterator;
class EscherContainer extends EscherRecord {
private static Logger logger = Logger.getLogger(EscherContainer.class);
private boolean initialized;
private ArrayList children;
public EscherContainer(EscherRecordData erd) {
super(erd);
this.initialized = false;
this.children = new ArrayList();
}
protected EscherContainer(EscherRecordType type) {
super(type);
setContainer(true);
this.children = new ArrayList();
}
public EscherRecord[] getChildren() {
if (!this.initialized)
initialize();
Object[] ca = this.children.toArray((Object[])new EscherRecord[this.children.size()]);
return (EscherRecord[])ca;
}
public void add(EscherRecord child) {
this.children.add(child);
}
public void remove(EscherRecord child) {
this.children.remove(child);
}
private void initialize() {
int curpos = getPos() + 8;
int endpos = Math.min(getPos() + getLength(), getStreamLength());
EscherRecord newRecord = null;
while (curpos < endpos) {
EscherRecordData erd = new EscherRecordData(getEscherStream(), curpos);
EscherRecordType type = erd.getType();
if (type == EscherRecordType.DGG) {
newRecord = new Dgg(erd);
} else if (type == EscherRecordType.DG) {
newRecord = new Dg(erd);
} else if (type == EscherRecordType.BSTORE_CONTAINER) {
newRecord = new BStoreContainer(erd);
} else if (type == EscherRecordType.SPGR_CONTAINER) {
newRecord = new SpgrContainer(erd);
} else if (type == EscherRecordType.SP_CONTAINER) {
newRecord = new SpContainer(erd);
} else if (type == EscherRecordType.SPGR) {
newRecord = new Spgr(erd);
} else if (type == EscherRecordType.SP) {
newRecord = new Sp(erd);
} else if (type == EscherRecordType.CLIENT_ANCHOR) {
newRecord = new ClientAnchor(erd);
} else if (type == EscherRecordType.CLIENT_DATA) {
newRecord = new ClientData(erd);
} else if (type == EscherRecordType.BSE) {
newRecord = new BlipStoreEntry(erd);
} else if (type == EscherRecordType.OPT) {
newRecord = new Opt(erd);
} else if (type == EscherRecordType.SPLIT_MENU_COLORS) {
newRecord = new SplitMenuColors(erd);
} else if (type == EscherRecordType.CLIENT_TEXT_BOX) {
newRecord = new ClientTextBox(erd);
} else {
newRecord = new EscherAtom(erd);
}
this.children.add(newRecord);
curpos += newRecord.getLength();
}
this.initialized = true;
}
byte[] getData() {
if (!this.initialized)
initialize();
byte[] data = new byte[0];
for (Iterator i = this.children.iterator(); i.hasNext(); ) {
EscherRecord er = i.next();
byte[] childData = er.getData();
if (childData != null) {
byte[] newData = new byte[data.length + childData.length];
System.arraycopy(data, 0, newData, 0, data.length);
System.arraycopy(childData, 0, newData, data.length, childData.length);
data = newData;
}
}
return setHeaderData(data);
}
}

View File

@@ -0,0 +1,65 @@
package jxl.biff.drawing;
import common.Logger;
abstract class EscherRecord {
private static Logger logger = Logger.getLogger(EscherRecord.class);
protected EscherRecordData data;
protected static final int HEADER_LENGTH = 8;
protected EscherRecord(EscherRecordData erd) {
this.data = erd;
}
protected EscherRecord(EscherRecordType type) {
this.data = new EscherRecordData(type);
}
protected void setContainer(boolean cont) {
this.data.setContainer(cont);
}
public int getLength() {
return this.data.getLength() + 8;
}
protected final EscherStream getEscherStream() {
return this.data.getEscherStream();
}
protected final int getPos() {
return this.data.getPos();
}
protected final int getInstance() {
return this.data.getInstance();
}
protected final void setInstance(int i) {
this.data.setInstance(i);
}
protected final void setVersion(int v) {
this.data.setVersion(v);
}
public EscherRecordType getType() {
return this.data.getType();
}
final byte[] setHeaderData(byte[] d) {
return this.data.setHeaderData(d);
}
byte[] getBytes() {
return this.data.getBytes();
}
protected int getStreamLength() {
return this.data.getStreamLength();
}
abstract byte[] getData();
}

View File

@@ -0,0 +1,121 @@
package jxl.biff.drawing;
import common.Logger;
import jxl.biff.IntegerHelper;
final class EscherRecordData {
private static Logger logger = Logger.getLogger(EscherRecordData.class);
private int pos;
private int instance;
private int version;
private int recordId;
private int length;
private int streamLength;
private boolean container;
private EscherRecordType type;
private EscherStream escherStream;
public EscherRecordData(EscherStream dg, int p) {
this.escherStream = dg;
this.pos = p;
byte[] data = this.escherStream.getData();
this.streamLength = data.length;
int value = IntegerHelper.getInt(data[this.pos], data[this.pos + 1]);
this.instance = (value & 0xFFF0) >> 4;
this.version = value & 0xF;
this.recordId = IntegerHelper.getInt(data[this.pos + 2], data[this.pos + 3]);
this.length = IntegerHelper.getInt(data[this.pos + 4], data[this.pos + 5], data[this.pos + 6], data[this.pos + 7]);
if (this.version == 15) {
this.container = true;
} else {
this.container = false;
}
}
public EscherRecordData(EscherRecordType t) {
this.type = t;
this.recordId = this.type.getValue();
}
public boolean isContainer() {
return this.container;
}
public int getLength() {
return this.length;
}
public int getRecordId() {
return this.recordId;
}
EscherStream getDrawingGroup() {
return this.escherStream;
}
int getPos() {
return this.pos;
}
EscherRecordType getType() {
if (this.type == null)
this.type = EscherRecordType.getType(this.recordId);
return this.type;
}
int getInstance() {
return this.instance;
}
void setContainer(boolean c) {
this.container = c;
}
void setInstance(int inst) {
this.instance = inst;
}
void setLength(int l) {
this.length = l;
}
void setVersion(int v) {
this.version = v;
}
byte[] setHeaderData(byte[] d) {
byte[] data = new byte[d.length + 8];
System.arraycopy(d, 0, data, 8, d.length);
if (this.container)
this.version = 15;
int value = this.instance << 4;
value |= this.version;
IntegerHelper.getTwoBytes(value, data, 0);
IntegerHelper.getTwoBytes(this.recordId, data, 2);
IntegerHelper.getFourBytes(d.length, data, 4);
return data;
}
EscherStream getEscherStream() {
return this.escherStream;
}
byte[] getBytes() {
byte[] d = new byte[this.length];
System.arraycopy(this.escherStream.getData(), this.pos + 8, d, 0, this.length);
return d;
}
int getStreamLength() {
return this.streamLength;
}
}

View File

@@ -0,0 +1,62 @@
package jxl.biff.drawing;
final class EscherRecordType {
private int value;
private static EscherRecordType[] types = new EscherRecordType[0];
private EscherRecordType(int val) {
this.value = val;
EscherRecordType[] newtypes = new EscherRecordType[types.length + 1];
System.arraycopy(types, 0, newtypes, 0, types.length);
newtypes[types.length] = this;
types = newtypes;
}
public int getValue() {
return this.value;
}
public static EscherRecordType getType(int val) {
EscherRecordType type = UNKNOWN;
for (int i = 0; i < types.length; i++) {
if (val == (types[i]).value) {
type = types[i];
break;
}
}
return type;
}
public static final EscherRecordType UNKNOWN = new EscherRecordType(0);
public static final EscherRecordType DGG_CONTAINER = new EscherRecordType(61440);
public static final EscherRecordType BSTORE_CONTAINER = new EscherRecordType(61441);
public static final EscherRecordType DG_CONTAINER = new EscherRecordType(61442);
public static final EscherRecordType SPGR_CONTAINER = new EscherRecordType(61443);
public static final EscherRecordType SP_CONTAINER = new EscherRecordType(61444);
public static final EscherRecordType DGG = new EscherRecordType(61446);
public static final EscherRecordType BSE = new EscherRecordType(61447);
public static final EscherRecordType DG = new EscherRecordType(61448);
public static final EscherRecordType SPGR = new EscherRecordType(61449);
public static final EscherRecordType SP = new EscherRecordType(61450);
public static final EscherRecordType OPT = new EscherRecordType(61451);
public static final EscherRecordType CLIENT_ANCHOR = new EscherRecordType(61456);
public static final EscherRecordType CLIENT_DATA = new EscherRecordType(61457);
public static final EscherRecordType CLIENT_TEXT_BOX = new EscherRecordType(61453);
public static final EscherRecordType SPLIT_MENU_COLORS = new EscherRecordType(61726);
}

View File

@@ -0,0 +1,5 @@
package jxl.biff.drawing;
interface EscherStream {
byte[] getData();
}

View File

@@ -0,0 +1,23 @@
package jxl.biff.drawing;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
import jxl.read.biff.Record;
public class MsoDrawingGroupRecord extends WritableRecordData {
private byte[] data;
public MsoDrawingGroupRecord(Record t) {
super(t);
this.data = t.getData();
}
MsoDrawingGroupRecord(byte[] d) {
super(Type.MSODRAWINGGROUP);
this.data = d;
}
public byte[] getData() {
return this.data;
}
}

View File

@@ -0,0 +1,42 @@
package jxl.biff.drawing;
import common.Logger;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
import jxl.read.biff.Record;
public class MsoDrawingRecord extends WritableRecordData {
private static Logger logger = Logger.getLogger(MsoDrawingRecord.class);
private boolean first;
private byte[] data;
public MsoDrawingRecord(Record t) {
super(t);
this.data = getRecord().getData();
this.first = false;
}
public MsoDrawingRecord(byte[] d) {
super(Type.MSODRAWING);
this.data = d;
this.first = false;
}
public byte[] getData() {
return this.data;
}
public Record getRecord() {
return super.getRecord();
}
public void setFirst() {
this.first = true;
}
public boolean isFirst() {
return this.first;
}
}

View File

@@ -0,0 +1,63 @@
package jxl.biff.drawing;
import common.Logger;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
import jxl.read.biff.Record;
public class NoteRecord extends WritableRecordData {
private static Logger logger = Logger.getLogger(NoteRecord.class);
private byte[] data;
private int row;
private int column;
private int objectId;
public NoteRecord(Record t) {
super(t);
this.data = getRecord().getData();
this.row = IntegerHelper.getInt(this.data[0], this.data[1]);
this.column = IntegerHelper.getInt(this.data[2], this.data[3]);
this.objectId = IntegerHelper.getInt(this.data[6], this.data[7]);
}
public NoteRecord(byte[] d) {
super(Type.NOTE);
this.data = d;
}
public NoteRecord(int c, int r, int id) {
super(Type.NOTE);
this.row = r;
this.column = c;
this.objectId = id;
}
public byte[] getData() {
if (this.data != null)
return this.data;
String author = "";
this.data = new byte[8 + author.length() + 4];
IntegerHelper.getTwoBytes(this.row, this.data, 0);
IntegerHelper.getTwoBytes(this.column, this.data, 2);
IntegerHelper.getTwoBytes(this.objectId, this.data, 6);
IntegerHelper.getTwoBytes(author.length(), this.data, 8);
return this.data;
}
int getRow() {
return this.row;
}
int getColumn() {
return this.column;
}
public int getObjectId() {
return this.objectId;
}
}

View File

@@ -0,0 +1,177 @@
package jxl.biff.drawing;
import common.Assert;
import common.Logger;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
import jxl.read.biff.Record;
public class ObjRecord extends WritableRecordData {
private static final Logger logger = Logger.getLogger(ObjRecord.class);
private ObjType type;
private boolean read;
private int objectId;
private static final class ObjType {
public int value;
public String desc;
private static ObjType[] types = new ObjType[0];
ObjType(int v, String d) {
this.value = v;
this.desc = d;
ObjType[] oldtypes = types;
types = new ObjType[types.length + 1];
System.arraycopy(oldtypes, 0, types, 0, oldtypes.length);
types[oldtypes.length] = this;
}
public String toString() {
return this.desc;
}
public static ObjType getType(int val) {
ObjType retval = ObjRecord.UNKNOWN;
for (int i = 0; i < types.length && retval == ObjRecord.UNKNOWN; i++) {
if ((types[i]).value == val)
retval = types[i];
}
return retval;
}
}
public static final ObjType TBD2 = new ObjType(1, "TBD2");
public static final ObjType TBD = new ObjType(2, "TBD");
public static final ObjType CHART = new ObjType(5, "Chart");
public static final ObjType TEXT = new ObjType(6, "Text");
public static final ObjType BUTTON = new ObjType(7, "Button");
public static final ObjType PICTURE = new ObjType(8, "Picture");
public static final ObjType CHECKBOX = new ObjType(14, "Checkbox");
public static final ObjType OPTION = new ObjType(12, "Option");
public static final ObjType EDITBOX = new ObjType(13, "Edit Box");
public static final ObjType LABEL = new ObjType(14, "Label");
public static final ObjType DIALOGUEBOX = new ObjType(15, "Dialogue Box");
public static final ObjType LISTBOX = new ObjType(18, "List Box");
public static final ObjType GROUPBOX = new ObjType(19, "Group Box");
public static final ObjType COMBOBOX = new ObjType(20, "Combo Box");
public static final ObjType MSOFFICEDRAWING = new ObjType(30, "MS Office Drawing");
public static final ObjType FORMCONTROL = new ObjType(20, "Form Combo Box");
public static final ObjType EXCELNOTE = new ObjType(25, "Excel Note");
public static final ObjType UNKNOWN = new ObjType(255, "Unknown");
private static final int COMMON_DATA_LENGTH = 22;
private static final int CLIPBOARD_FORMAT_LENGTH = 6;
private static final int PICTURE_OPTION_LENGTH = 6;
private static final int NOTE_STRUCTURE_LENGTH = 26;
private static final int END_LENGTH = 4;
public ObjRecord(Record t) {
super(t);
byte[] data = t.getData();
int objtype = IntegerHelper.getInt(data[4], data[5]);
this.read = true;
this.type = ObjType.getType(objtype);
if (this.type == UNKNOWN)
logger.warn("unknown object type code " + objtype);
this.objectId = IntegerHelper.getInt(data[6], data[7]);
}
ObjRecord(int objId, ObjType t) {
super(Type.OBJ);
this.objectId = objId;
this.type = t;
}
public byte[] getData() {
if (this.read)
return getRecord().getData();
if (this.type == PICTURE || this.type == CHART)
return getPictureData();
if (this.type == EXCELNOTE)
return getNoteData();
Assert.verify(false);
return null;
}
private byte[] getPictureData() {
int dataLength = 38;
int pos = 0;
byte[] data = new byte[dataLength];
IntegerHelper.getTwoBytes(21, data, pos);
IntegerHelper.getTwoBytes(18, data, pos + 2);
IntegerHelper.getTwoBytes(this.type.value, data, pos + 4);
IntegerHelper.getTwoBytes(this.objectId, data, pos + 6);
IntegerHelper.getTwoBytes(24593, data, pos + 8);
pos += 22;
IntegerHelper.getTwoBytes(7, data, pos);
IntegerHelper.getTwoBytes(2, data, pos + 2);
IntegerHelper.getTwoBytes(65535, data, pos + 4);
pos += 6;
IntegerHelper.getTwoBytes(8, data, pos);
IntegerHelper.getTwoBytes(2, data, pos + 2);
IntegerHelper.getTwoBytes(1, data, pos + 4);
pos += 6;
IntegerHelper.getTwoBytes(0, data, pos);
IntegerHelper.getTwoBytes(0, data, pos + 2);
pos += 4;
return data;
}
private byte[] getNoteData() {
int dataLength = 52;
int pos = 0;
byte[] data = new byte[dataLength];
IntegerHelper.getTwoBytes(21, data, pos);
IntegerHelper.getTwoBytes(18, data, pos + 2);
IntegerHelper.getTwoBytes(this.type.value, data, pos + 4);
IntegerHelper.getTwoBytes(this.objectId, data, pos + 6);
IntegerHelper.getTwoBytes(16401, data, pos + 8);
pos += 22;
IntegerHelper.getTwoBytes(13, data, pos);
IntegerHelper.getTwoBytes(22, data, pos + 2);
pos += 26;
IntegerHelper.getTwoBytes(0, data, pos);
IntegerHelper.getTwoBytes(0, data, pos + 2);
pos += 4;
return data;
}
public Record getRecord() {
return super.getRecord();
}
public ObjType getType() {
return this.type;
}
int getObjectId() {
return this.objectId;
}
}

View File

@@ -0,0 +1,126 @@
package jxl.biff.drawing;
import common.Logger;
import java.util.ArrayList;
import java.util.Iterator;
import jxl.biff.IntegerHelper;
import jxl.biff.StringHelper;
class Opt extends EscherAtom {
private static Logger logger = Logger.getLogger(Opt.class);
private byte[] data;
private int numProperties;
private ArrayList properties;
static final class Property {
int id;
boolean blipId;
boolean complex;
int value;
String stringValue;
public Property(int i, boolean bl, boolean co, int v) {
this.id = i;
this.blipId = bl;
this.complex = co;
this.value = v;
}
public Property(int i, boolean bl, boolean co, int v, String s) {
this.id = i;
this.blipId = bl;
this.complex = co;
this.value = v;
this.stringValue = s;
}
}
public Opt(EscherRecordData erd) {
super(erd);
this.numProperties = getInstance();
readProperties();
}
private void readProperties() {
this.properties = new ArrayList();
int pos = 0;
byte[] bytes = getBytes();
for (int j = 0; j < this.numProperties; j++) {
int val = IntegerHelper.getInt(bytes[pos], bytes[pos + 1]);
int id = val & 0x3FFF;
int value = IntegerHelper.getInt(bytes[pos + 2], bytes[pos + 3], bytes[pos + 4], bytes[pos + 5]);
Property p = new Property(id, ((val & 0x4000) != 0), ((val & 0x8000) != 0), value);
pos += 6;
this.properties.add(p);
}
for (Iterator i = this.properties.iterator(); i.hasNext(); ) {
Property p = i.next();
if (p.complex) {
p.stringValue = StringHelper.getUnicodeString(bytes, p.value / 2, pos);
pos += p.value;
}
}
}
public Opt() {
super(EscherRecordType.OPT);
this.properties = new ArrayList();
setVersion(3);
}
byte[] getData() {
this.numProperties = this.properties.size();
setInstance(this.numProperties);
this.data = new byte[this.numProperties * 6];
int pos = 0;
for (Iterator iterator1 = this.properties.iterator(); iterator1.hasNext(); ) {
Property p = iterator1.next();
int val = p.id & 0x3FFF;
if (p.blipId)
val |= 0x4000;
if (p.complex)
val |= 0x8000;
IntegerHelper.getTwoBytes(val, this.data, pos);
IntegerHelper.getFourBytes(p.value, this.data, pos + 2);
pos += 6;
}
for (Iterator i = this.properties.iterator(); i.hasNext(); ) {
Property p = i.next();
if (p.complex && p.stringValue != null) {
byte[] newData = new byte[this.data.length + p.stringValue.length() * 2];
System.arraycopy(this.data, 0, newData, 0, this.data.length);
StringHelper.getUnicodeBytes(p.stringValue, newData, this.data.length);
this.data = newData;
}
}
return setHeaderData(this.data);
}
void addProperty(int id, boolean blip, boolean complex, int val) {
Property p = new Property(id, blip, complex, val);
this.properties.add(p);
}
void addProperty(int id, boolean blip, boolean complex, int val, String s) {
Property p = new Property(id, blip, complex, val, s);
this.properties.add(p);
}
Property getProperty(int id) {
boolean found = false;
Property p = null;
for (Iterator i = this.properties.iterator(); i.hasNext() && !found; ) {
p = i.next();
if (p.id == id)
found = true;
}
return found ? p : null;
}
}

View File

@@ -0,0 +1,9 @@
package jxl.biff.drawing;
public final class Origin {
public static final Origin READ = new Origin();
public static final Origin WRITE = new Origin();
public static final Origin READ_WRITE = new Origin();
}

Some files were not shown because too many files have changed in this diff Show More