diff options
author | afinkbein | 2009-01-14 23:33:02 +0000 |
---|---|---|
committer | afinkbein | 2009-01-14 23:33:02 +0000 |
commit | 2153ada75e53772a2707c53d1a4bfa3606a4f6ff (patch) | |
tree | d3448df6b2f87ffb89ff4d117d102d9771e1c88d | |
parent | 4bafcf506f5b9e21b740812c13c8b2224a3403b7 (diff) | |
download | org.eclipse.osee-2153ada75e53772a2707c53d1a4bfa3606a4f6ff.tar.gz org.eclipse.osee-2153ada75e53772a2707c53d1a4bfa3606a4f6ff.tar.xz org.eclipse.osee-2153ada75e53772a2707c53d1a4bfa3606a4f6ff.zip |
175 files changed, 18572 insertions, 0 deletions
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/.classpath b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/.classpath new file mode 100644 index 00000000000..6e16b23d695 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/.project b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/.project new file mode 100644 index 00000000000..c729976c89e --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.osee.framework.jdk.core</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/.settings/org.eclipse.jdt.core.prefs b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..0923db0af66 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,57 @@ +#Mon Aug 04 11:04:44 MST 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=ignore
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/META-INF/MANIFEST.MF b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..a0fa52c248b --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/META-INF/MANIFEST.MF @@ -0,0 +1,33 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: OSEE JDK Core Plug-in (Incubation) +Bundle-SymbolicName: org.eclipse.osee.framework.jdk.core;singleton:=true +Bundle-Version: 0.4.0.qualifier +Bundle-Vendor: Eclipse.org +Export-Package: org.eclipse.osee.framework.jdk.core.collection.tree, + org.eclipse.osee.framework.jdk.core.db, + org.eclipse.osee.framework.jdk.core.directory, + org.eclipse.osee.framework.jdk.core.persistence, + org.eclipse.osee.framework.jdk.core.reportdata, + org.eclipse.osee.framework.jdk.core.stateMachine, + org.eclipse.osee.framework.jdk.core.text, + org.eclipse.osee.framework.jdk.core.text.change, + org.eclipse.osee.framework.jdk.core.text.rules, + org.eclipse.osee.framework.jdk.core.text.tool, + org.eclipse.osee.framework.jdk.core.type, + org.eclipse.osee.framework.jdk.core.util, + org.eclipse.osee.framework.jdk.core.util.benchmark, + org.eclipse.osee.framework.jdk.core.util.images, + org.eclipse.osee.framework.jdk.core.util.io, + org.eclipse.osee.framework.jdk.core.util.io.streams, + org.eclipse.osee.framework.jdk.core.util.io.xml, + org.eclipse.osee.framework.jdk.core.util.network, + org.eclipse.osee.framework.jdk.core.util.requirement, + org.eclipse.osee.framework.jdk.core.util.time, + org.eclipse.osee.framework.jdk.core.util.windows, + org.eclipse.osee.framework.jdk.core.util.xml, + org.eclipse.osee.framework.jdk.core.util.xml.excel, + org.eclipse.osee.framework.jdk.core.util.xml.parser, + org.eclipse.osee.framework.jdk.core.validate +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/build.properties b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/build.properties new file mode 100644 index 00000000000..1917f359d93 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/build.properties @@ -0,0 +1,8 @@ +bin.includes = META-INF/,\ + lib/,\ + plugin.xml,\ + . +jars.compile.order = . +output.. = bin/ +source.. = src/ +source.. = src/ diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/plugin.xml b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/plugin.xml new file mode 100644 index 00000000000..95d86b58f64 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/plugin.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> +<plugin>
+ <extension-point id="DefaultMailServer" name="Default Mail Server" schema="schema/DefaultMailServer.exsd"/> +</plugin>
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/schema/DefaultMailServer.exsd b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/schema/DefaultMailServer.exsd new file mode 100644 index 00000000000..644d1553e72 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/schema/DefaultMailServer.exsd @@ -0,0 +1,102 @@ +<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.osee.framework.jdk.core">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.osee.framework.jdk.core" id="DefaultMailServer" name="Default Mail Server"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="mailServer"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="mailServer">
+ <complexType>
+ <attribute name="serverAddress" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/collection/tree/Tree.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/collection/tree/Tree.java new file mode 100644 index 00000000000..ee888853689 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/collection/tree/Tree.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.collection.tree; + +public class Tree<treeType> { + + private TreeNode<treeType> root; + + public Tree() { + this.root = new TreeNode<treeType>(); + } + + public Tree(treeType self) { + this.root = new TreeNode<treeType>(self); + } + + public TreeNode<treeType> getRoot() { + return root; + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/collection/tree/TreeNode.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/collection/tree/TreeNode.java new file mode 100644 index 00000000000..087ceead472 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/collection/tree/TreeNode.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.collection.tree; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class TreeNode<treeType> { + + private treeType myself; + private TreeNode<treeType> parent; + private List<TreeNode<treeType>> children; + + protected TreeNode(TreeNode<treeType> parent, treeType myself) { + this.parent = parent; + this.myself = myself; + this.children = new ArrayList<TreeNode<treeType>>(); + } + + public TreeNode(treeType myself) { + this(null, myself); + } + + public TreeNode() { + this(null); + } + + public TreeNode<treeType> getParent() { + return parent; + } + + public treeType getSelf() { + return myself; + } + + public List<TreeNode<treeType>> getChildren() { + return children; + } + + public TreeNode<treeType> addChild(treeType child) { + TreeNode<treeType> newchild = new TreeNode<treeType>(this, child); + this.children.add(newchild); + return newchild; + } + + public void addChildren(Collection<treeType> children) { + for (treeType child : children) { + this.addChild(child); + } + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/db/DbConfigFileInformation.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/db/DbConfigFileInformation.java new file mode 100644 index 00000000000..93cfa940eb9 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/db/DbConfigFileInformation.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.db; + +/** + * @author Roberto E. Escobar + */ +public class DbConfigFileInformation { + + public static String getSchemaFileExtension() { + return ".SCHEMA.xml"; + } + + public static String getDbDataFileExtension() { + return ".DATA.xml"; + } + + public static String getSkyNetFileExtension() { + return ".xml"; + } + + public static String getCSVFileExtension() { + return ".csv"; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/directory/DirectoryPerson.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/directory/DirectoryPerson.java new file mode 100644 index 00000000000..9224873eb64 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/directory/DirectoryPerson.java @@ -0,0 +1,413 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.directory; + +import java.io.Serializable; +import java.util.ArrayList; + +/** + * @author Jeff C. Phillips + */ +public class DirectoryPerson implements Comparable<Object>, Serializable { + + /** + * + */ + private static final long serialVersionUID = -2333305323300083640L; + private ArrayList<Integer> policies = null; + private int bemsid; + private int bluesId; + private String building; + private String city; + private String country; + private String department; + private String departmentName; + private String email; + private String externalCompany; + private String fullName; + private String hRDeptDesc; + private String hRDeptNumber; + private String mailCode; + private String mailStop; + private String manager; + private String personType; + private String phone; + private String searchName; + private String sponsor; + private String state; + private String title; + private String uSPersonStatus; + private boolean hasPolicy = false; + + public DirectoryPerson() { + policies = new ArrayList<Integer>(); + bemsid = -1; + bluesId = -1; + building = ""; + city = ""; + country = ""; + department = ""; + departmentName = ""; + email = ""; + externalCompany = ""; + fullName = ""; + hRDeptDesc = ""; + hRDeptNumber = ""; + mailCode = ""; + mailStop = ""; + manager = ""; + personType = ""; + phone = ""; + searchName = ""; + sponsor = ""; + state = ""; + title = ""; + uSPersonStatus = ""; + } + + /** + * @return Returns the fullName. + */ + public String getFullName() { + return fullName; + } + + /** + * @param fullName The fullName to set. + */ + public void setFullName(String fullName) { + this.fullName = fullName; + } + + /** + * @return Returns the bems. + */ + public int getBemsid() { + return bemsid; + } + + /** + * @param bems The bems to set. + */ + public void setBemsid(int bems) { + this.bemsid = bems; + } + + /** + * @return Returns the bluesId. + */ + public int getBluesId() { + return bluesId; + } + + /** + * @param bluesId The bluesId to set. + */ + public void setBluesId(int bluesId) { + this.bluesId = bluesId; + } + + /** + * @return Returns the building. + */ + public String getBuilding() { + return building; + } + + /** + * @param building The building to set. + */ + public void setBuilding(String building) { + this.building = building; + } + + /** + * @return Returns the city. + */ + public String getCity() { + return city; + } + + /** + * @param city The city to set. + */ + public void setCity(String city) { + this.city = city; + } + + /** + * @return Returns the country. + */ + public String getCountry() { + return country; + } + + /** + * @param country The country to set. + */ + public void setCountry(String country) { + this.country = country; + } + + /** + * @return Returns the department. + */ + public String getDepartment() { + return department; + } + + /** + * @param department The department to set. + */ + public void setDepartment(String department) { + this.department = department; + } + + /** + * @return Returns the departmentName. + */ + public String getDepartmentName() { + return departmentName; + } + + /** + * @param departmentName The departmentName to set. + */ + public void setDepartmentName(String departmentName) { + this.departmentName = departmentName; + } + + /** + * @return Returns the email. + */ + public String getEmail() { + return email; + } + + /** + * @param email The email to set. + */ + public void setEmail(String email) { + this.email = email; + } + + /** + * @return Returns the externalCompany. + */ + public String getExternalCompany() { + return externalCompany; + } + + /** + * @param externalCompany The externalCompany to set. + */ + public void setExternalCompany(String externalCompany) { + this.externalCompany = externalCompany; + } + + /** + * @return Returns the hRDeptDesc. + */ + public String getHRDeptDesc() { + return hRDeptDesc; + } + + /** + * @param deptDesc The hRDeptDesc to set. + */ + public void setHRDeptDesc(String deptDesc) { + hRDeptDesc = deptDesc; + } + + /** + * @return Returns the hRDeptNumber. + */ + public String getHRDeptNumber() { + return hRDeptNumber; + } + + /** + * @param deptNumber The hRDeptNumber to set. + */ + public void setHRDeptNumber(String deptNumber) { + hRDeptNumber = deptNumber; + } + + /** + * @return Returns the mailCode. + */ + public String getMailCode() { + return mailCode; + } + + /** + * @param mailCode The mailCode to set. + */ + public void setMailCode(String mailCode) { + this.mailCode = mailCode; + } + + /** + * @return Returns the mailStop. + */ + public String getMailStop() { + return mailStop; + } + + /** + * @param mailStop The mailStop to set. + */ + public void setMailStop(String mailStop) { + this.mailStop = mailStop; + } + + /** + * @return Returns the manager. + */ + public String getManager() { + return manager; + } + + /** + * @param manager The manager to set. + */ + public void setManager(String manager) { + this.manager = manager; + } + + /** + * @return Returns the personType. + */ + public String getPersonType() { + return personType; + } + + /** + * @param personType The personType to set. + */ + public void setPersonType(String personType) { + this.personType = personType; + } + + /** + * @return Returns the phone. + */ + public String getPhone() { + return phone; + } + + /** + * @param phone The phone to set. + */ + public void setPhone(String phone) { + this.phone = phone; + } + + /** + * @return Returns the searchName. + */ + public String getSearchName() { + return searchName; + } + + /** + * @param searchName The searchName to set. + */ + public void setSearchName(String searchName) { + this.searchName = searchName; + } + + /** + * @return Returns the sponsor. + */ + public String getSponsor() { + return sponsor; + } + + /** + * @param sponsor The sponsor to set. + */ + public void setSponsor(String sponsor) { + this.sponsor = sponsor; + } + + /** + * @return Returns the state. + */ + public String getState() { + return state; + } + + /** + * @param state The state to set. + */ + public void setState(String state) { + this.state = state; + } + + /** + * @return Returns the title. + */ + public String getTitle() { + return title; + } + + /** + * @param title The title to set. + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * @return Returns the uSPersonStatus. + */ + public String getUSPersonStatus() { + return uSPersonStatus; + } + + /** + * @param personStatus The uSPersonStatus to set. + */ + public void setUSPersonStatus(String personStatus) { + uSPersonStatus = personStatus; + } + + public int compareTo(Object person) { + return fullName.compareTo(((DirectoryPerson) person).fullName); + } + + /** + * @return Returns the policies. + */ + public ArrayList<Integer> getPolicies() { + return policies; + } + + /** + * @param policies The policies to set. + */ + public void setPolicies(ArrayList<Integer> policies) { + this.policies = policies; + } + + public boolean isHasPolicy() { + return hasPolicy; + } + + public void setHasPolicy(boolean hasPolicy) { + this.hasPolicy = hasPolicy; + } + + public String toString() { + return fullName + " : " + this.bemsid + " : " + email; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/persistence/TwoWayXmlizable.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/persistence/TwoWayXmlizable.java new file mode 100644 index 00000000000..698c50eb602 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/persistence/TwoWayXmlizable.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.persistence; + +import org.w3c.dom.Element; + +public interface TwoWayXmlizable extends Xmlizable { + public abstract void initializeFromXml(Element root); + + public abstract boolean isInitialized(); +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/persistence/Xmlizable.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/persistence/Xmlizable.java new file mode 100644 index 00000000000..83f89ff51d4 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/persistence/Xmlizable.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.persistence; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * @author Ryan D. Brooks + */ +public interface Xmlizable { + public Element toXml(Document doc); +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/reportdata/ReportData.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/reportdata/ReportData.java new file mode 100644 index 00000000000..d1414f1a522 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/reportdata/ReportData.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.reportdata; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.osee.framework.jdk.core.util.GUID; + +public class ReportData implements Serializable { + + private static final long serialVersionUID = 6645261625619889708L; + + private List<String> headers; + private List<ReportDataItem> items; + + /** + * Creates the ReportData class with the given headers. The number of headers should match the values passed into + * <code>addItem</code>. + * + * @param headers The headers for the data to be added. + */ + public ReportData(List<String> headers) { + this.headers = headers; + items = new ArrayList<ReportDataItem>(); + } + + /** + * Adds an item to the ReportData + * + * @param guid The GUID corresponding to the item added + * @param values The values (such as username, script name) associated with the item. These should match the headers. + */ + public void addItem(GUID guid, ArrayList<String> values) { + ReportDataItem item = new ReportDataItem(guid, values); + items.add(item); + } + + public void clearItems() { + items.clear(); + } + + /** + * @param headers The headers to set. + */ + public void setHeaders(List<String> headers) { + this.headers = headers; + } + + /** + * @return Returns the headers. + */ + public List<String> getHeaders() { + return headers; + } + + /** + * @return Returns the items. + */ + public List<ReportDataItem> getItems() { + return items; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/reportdata/ReportDataItem.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/reportdata/ReportDataItem.java new file mode 100644 index 00000000000..5ac525c7f08 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/reportdata/ReportDataItem.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.reportdata; + +import java.io.Serializable; +import java.util.ArrayList; +import org.eclipse.osee.framework.jdk.core.util.GUID; + +public class ReportDataItem implements Serializable { + + private static final long serialVersionUID = 7072248922173369711L; + + private GUID guid; + private ArrayList<String> cells; + + public ReportDataItem(GUID guid, ArrayList<String> items) { + this.guid = guid; + this.cells = items; + } + + /** + * @return Returns the guid. + */ + public GUID getGuid() { + return guid; + } + + /** + * @return Returns the cells. + */ + public ArrayList<String> getCells() { + return cells; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/reportdata/ReportDataListener.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/reportdata/ReportDataListener.java new file mode 100644 index 00000000000..a998d631fab --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/reportdata/ReportDataListener.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.reportdata; + +import java.rmi.Remote; +import java.rmi.RemoteException; + +public interface ReportDataListener extends Remote { + public void updateData(ReportData data) throws RemoteException; +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/stateMachine/IState.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/stateMachine/IState.java new file mode 100644 index 00000000000..ac8bb165bfa --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/stateMachine/IState.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.stateMachine; + +/** + * A single state in a contructed state machine. All implementers should calculate and control what the next state in + * the machine should be. + */ +public interface IState { + /** + * Called by the state machine controller to start this particular state. + * + * @return The next state the controller should run or null if the machine should terminate + */ + public IState run(); +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/stateMachine/StateController.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/stateMachine/StateController.java new file mode 100644 index 00000000000..f455b0306b7 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/stateMachine/StateController.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.stateMachine; + +/** + * Runs each state of the stateMachine defined. Each state will calculate and know which state to go to next so this is + * really a dumb controller, calling the run method of whatever state the current state returned from being run. + */ +public class StateController { + private IState nextState; + private boolean isRunning; + + public StateController(IState initialState) { + isRunning = true; + nextState = initialState; + } + + /** + * Calls the run method of the next state. + */ + public void runNextState() { + if (isRunning) nextState = nextState.run(); + if (nextState == null) isRunning = false; + } + + public boolean isRunning() { + return isRunning; + } + + /** + * causes machine to terminate on next ivocation of the controller's run method. + */ + public void turnMachineOff() { + isRunning = false; + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/stateMachine/WaitState.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/stateMachine/WaitState.java new file mode 100644 index 00000000000..b586792c21b --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/stateMachine/WaitState.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.stateMachine; + +/** + * allows a state machine to wait for a certain number of cycles before continuing. Notice that if a state needs to wait + * only one cycle, a wait state should not be used as it would really be two cycles ( one to run the wait state then one + * to start the next state). Instead that state could simply return an instance of the next state to run as normal. + */ +public class WaitState implements IState { + + int iterationsToWait; + IState nextRealStateToRun; + + /** + * @param iterationsToWait The number of times this state will be run + * @param nextRealStateToRun The next state to run after waiting + */ + public WaitState(int iterationsToWait, IState nextRealStateToRun) { + this.iterationsToWait = iterationsToWait; + this.nextRealStateToRun = nextRealStateToRun; + } + + public IState run() { + iterationsToWait--; + if (iterationsToWait <= 0) + return nextRealStateToRun; + else + return this; + + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/CsdmParams.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/CsdmParams.java new file mode 100644 index 00000000000..3f18b02abc9 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/CsdmParams.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; +import org.eclipse.osee.framework.jdk.core.util.Lib; + +/** + * @author Ryan D. Brooks + */ +public class CsdmParams { + protected BufferedReader in; + protected BufferedWriter out; + + public CsdmParams() { + try { + in = new BufferedReader(new InputStreamReader(System.in)); + out = new BufferedWriter(new FileWriter("csdm_params.csv")); + } catch (IOException ex) { + System.out.println(ex); + } + } + + protected void finalize() throws IOException { + out.close(); + in.close(); + } + + public static void main(String args[]) throws IOException { + CsdmParams gen = new CsdmParams(); + gen.genThreats(); + gen.finalize(); + } + + public void genThreats() throws IOException { + for (int i = 0; i < 32; i++) { + String numStr = Lib.padLeading(String.valueOf(i), '0', 2); + out.write("THRT_LAT_" + numStr + ",IEEE64,19346,\n"); + out.write("THRT_LAT_Z_" + numStr + ",IEEE64,19347,\n"); + out.write("THRT_LONG_" + numStr + ",IEEE64,19346,\n"); + out.write("THRT_LONG_Z_" + numStr + ",IEEE64,19347,\n"); + out.write("THRT_DETECT_" + numStr + ",IEEE64,19346,\n"); + out.write("THRT_DETECT_Z_" + numStr + ",IEEE64,19347,\n"); + out.write("THRT_LETHAL_" + numStr + ",IEEE64,19346,\n"); + out.write("THRT_LETHAL_Z_" + numStr + ",IEEE64,19347,\n"); + out.write("THRT_HEIGHT_ABOVE_" + numStr + ",ANALOG,19154,-2_147_483_648 to 2_147_483_647\n"); + out.write("THRT_COUNT_" + numStr + ",ANALOG,5461,0 to 255\n"); + out.write("THRT_STAT_OK_" + numStr + ",ENUM,162,\"0=FALSE, 1=TRUE\"\n"); + out.write("SPARE,SPARE,0,\n"); + } + } + + public void parseAda() throws IOException { + String line = null; + while ((line = in.readLine()) != null) { + StringTokenizer strTok = new StringTokenizer(line, " ."); + if (strTok.countTokens() == 4) { + String adaName = strTok.nextToken(); + out.write(adaName + ", "); + out.write(strTok.nextToken() + ", "); + out.write(strTok.nextToken() + ", "); + out.write(strTok.nextToken() + "\n"); + } + } + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/ExtractComments.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/ExtractComments.java new file mode 100644 index 00000000000..de9f0a9dbed --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/ExtractComments.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + +/** + * @author Ryan D. Brooks + */ +public class ExtractComments { + protected BufferedReader in; + protected String line; + protected ArrayList<String> comments; + protected int count; + + public ExtractComments() { + in = null; + line = null; + comments = new ArrayList<String>(); + } + + public Object[] extract(String sourceFile) { + try { + in = new BufferedReader(new FileReader(sourceFile)); + } catch (FileNotFoundException ex) { + System.err.println(ex); + throw new IllegalArgumentException(ex.toString()); + } + + try { + while ((line = in.readLine()) != null) { + handleComments(); + } + } catch (IOException ex) { + System.err.println(ex); + System.exit(2); + } + return comments.toArray(); + } + + protected void handleComments() { + try { + while (line != null) { + String tLine = line.trim(); + if (tLine.startsWith("/*")) { + comments.add(++count + line); + while (tLine != null && !tLine.endsWith("*/")) { + tLine = in.readLine().trim(); + comments.add(++count + line); + } + } else if (!tLine.startsWith("//")) { + //a logical LOC might have a comment folloing it on the same line + line = stripOffComment(tLine); + return; + } + comments.add(++count + line); + line = in.readLine(); + } + } catch (IOException ex) { + System.err.println(ex); + return; + } + } + + public String stripOffComment(String line) { + int pos = line.lastIndexOf("//"); + if (pos != -1) { //if a comment is indeed there (maybe) + //the single line comment symbol might be part of a string literal + //this is hard because the string delimiter might also be part of a string literal + if (!insideStringLiteral(line, pos)) { + comments.add(++count + this.line); + return line.substring(0, pos).trim(); + } + } + count++; + return line; + } + + public boolean insideStringLiteral(String str, int pos) { + int index = 0; + boolean inside = false; + + char[] chars = new char[str.length()]; + str.getChars(0, chars.length, chars, 0); + + while (index < pos) { + if (chars[index] == '\\' && chars[index + 1] == '\"') { + index++; // skip over literal quotation marks + } else if (chars[index] == '\"') { + inside = !inside; + } + index++; + } + return inside; + } + + public static void main(String[] args) { + if (args.length < 1) { + System.out.println("Usage: ExtractComments [source file]"); + return; + } + ExtractComments app = new ExtractComments(); + Object[] text = app.extract(args[0]); + + try { + FileWriter out = new FileWriter("comments.txt"); + for (int i = 0; i < text.length; i++) { + String str = (String) text[i]; + out.write(str, 0, str.length()); + out.write('\n'); + } + out.close(); + } catch (IOException ex) { + System.err.println(ex); + return; + } + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/ExtractText.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/ExtractText.java new file mode 100644 index 00000000000..cb789e6b39b --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/ExtractText.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +/** + * @author Ryan D. Brooks + */ +public class ExtractText { + protected String line; + protected int lineNum; + protected BufferedReader in; + protected FileWriter out; + + public ExtractText(String sourceFile) { + try { + in = new BufferedReader(new FileReader(sourceFile)); + out = new FileWriter("sourceText.txt"); + line = null; + lineNum = 0; + + while ((line = in.readLine()) != null) { + int pos = line.indexOf("/*"); + if (pos != -1) { // beginning of block comment unless in a string literal + if (!insideStringLiteral(line, pos)) { + //find whole block and write to file + pos = line.indexOf("*/"); + while (line != null && pos == -1) { + writeText(); + line = in.readLine(); + pos = line.indexOf("*/"); + } + writeText(); + } else { // line contains a string + writeText(); + } + } else if (line.indexOf("//") != -1) { // line contains a single line comment or string literal + writeText(); + } else if ((pos = line.indexOf("\"")) != -1 && line.charAt(pos + 1) != '\'') { // line contains a string literal + writeText(); + } + // line does not contain text + lineNum++; + } + in.close(); + out.close(); + } catch (IOException ex) { + System.err.println(ex); + return; + } + } + + protected void writeText() throws IOException { + String str = String.valueOf(++lineNum); + out.write(str, 0, str.length()); + out.write(line, 0, line.length()); + out.write('\n'); + } + + public static boolean insideStringLiteral(String str, int pos) { + int index = 0; + boolean inside = false; + + char[] chars = new char[str.length()]; + str.getChars(0, chars.length, chars, 0); + + while (index < pos) { + if (chars[index] == '\\' && chars[index + 1] == '\"') { + index++; // skip over literal quotation marks + } else if (chars[index] == '\"') { + inside = !inside; + } + index++; + } + return inside; + } + + public static void main(String[] args) { + if (args.length < 1) { + System.out.println("Usage: ExtractText [source file]"); + return; + } + new ExtractText(args[0]); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/FileToBufferConvert.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/FileToBufferConvert.java new file mode 100644 index 00000000000..2d4e94cd6a9 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/FileToBufferConvert.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text; + +import java.io.File; +import java.io.IOException; +import java.text.ParseException; + +/** + * @author Ryan D. Brooks + */ +public interface FileToBufferConvert { + public CharSequence fileToCharSequence(File file) throws IOException, ParseException; +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/FindResults.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/FindResults.java new file mode 100644 index 00000000000..12a468b175b --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/FindResults.java @@ -0,0 +1,192 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +/** + * @author Ryan D. Brooks + */ +public class FindResults { + private HashMap<String, HashMap<File, List<String>>> results; + + public FindResults(int initialCapacity) { + results = new HashMap<String, HashMap<File, List<String>>>(initialCapacity * 4 / 3); + } + + public void addMatch(String pattern, File file, String region) { + HashMap<File, List<String>> fileMatches = results.get(pattern); + + if (fileMatches == null) { + fileMatches = new HashMap<File, List<String>>(); + results.put(pattern, fileMatches); + } + + List<String> regions = fileMatches.get(file); + if (regions == null) { + regions = new LinkedList<String>(); + fileMatches.put(file, regions); + } + regions.add(region); + } + + public void writeFindResutls(Writer out) throws IOException { + for (FindResults.FindResultsIterator i = iterator(); i.hasNext();) { + // write out the file name, pattern, and region surrounding match + out.write(i.currentPattern); + out.write('@'); + out.write(i.currentFile.getName()); + out.write('@'); + if (i.currentRegion != null) { + out.write(i.currentRegion); + } + out.write("\n"); + } + } + + public FindResultsIterator iterator() { + return new FindResultsIterator(); + } + + /** + * @author Ryan D. Brooks + */ + public class FindResultsIterator { + private Iterator<Entry<String, HashMap<File, List<String>>>> patternIterator; + private Iterator<Entry<File, List<String>>> fileIterator; + private Iterator<String> listIterator; + private boolean more; + public String currentPattern; + public File currentFile; + public String currentRegion; + + private FindResultsIterator() { + reset(); + } + + public void reset() { + this.more = true; + this.patternIterator = results.entrySet().iterator(); + this.listIterator = null; + this.fileIterator = null; + } + + // assumption every the list and file itorator's will have at least one item + private void primePump() { + if (listIterator == null || !listIterator.hasNext()) { + if (fileIterator == null || !fileIterator.hasNext()) { + if (!patternIterator.hasNext()) { + more = false; + return; + } + Map.Entry<String, HashMap<File, List<String>>> entry = patternIterator.next(); + currentPattern = entry.getKey(); + HashMap<File, List<String>> fileMatches = entry.getValue(); + fileIterator = fileMatches.entrySet().iterator(); + } + Map.Entry<File, List<String>> entry = fileIterator.next(); + currentFile = entry.getKey(); + List<String> list = entry.getValue(); + listIterator = list.iterator(); + } + currentRegion = listIterator.next(); + } + + public boolean hasNext() { + primePump(); + return more; + } + } + + /** + * Returns a simple set of all files that had matches (or anti-matches) + */ + public Set<File> getFileSet() { + Set<File> files = new LinkedHashSet<File>(1000); + for (Iterator<Entry<String, HashMap<File, List<String>>>> i = results.entrySet().iterator(); i.hasNext();) { + Map.Entry<String, HashMap<File, List<String>>> entry = i.next(); + HashMap<File, List<String>> fileMatches = entry.getValue(); + files.addAll(fileMatches.keySet()); + } + return files; + } + + public HashMap<String, List<File>> getRegionToFileMapping() { + HashMap<String, List<File>> mapping = new HashMap<String, List<File>>(1000); + for (FindResultsIterator i = iterator(); i.hasNext();) { + List<File> files = mapping.get(i.currentRegion); + if (files == null) { + files = new LinkedList<File>(); + mapping.put(i.currentRegion, files); + } + files.add(i.currentFile); + } + return mapping; + } + + public IteratorPerPattern getIteratorForPattern(String pattern) { + return new IteratorPerPattern(pattern); + } + + /** + * @author Ryan D. Brooks + */ + public class IteratorPerPattern { + private String pattern; + private Iterator<Entry<File, List<String>>> fileIterator; + private Iterator<String> listIterator; + private boolean more; + public File currentFile; + public String currentRegion; + + private IteratorPerPattern(String pattern) { + this.pattern = pattern; + reset(); + } + + public void reset() { + HashMap<File, List<String>> fileMatches = results.get(pattern); + this.fileIterator = fileMatches.entrySet().iterator(); + this.listIterator = null; + this.more = true; + } + + // assumption every the list and file itorator's will have at least one item + private void primePump() { + if (listIterator == null || !listIterator.hasNext()) { + if (!fileIterator.hasNext()) { + more = false; + return; + } + Map.Entry<File, List<String>> entry = fileIterator.next(); + currentFile = entry.getKey(); + List<String> list = entry.getValue(); + listIterator = list.iterator(); + } + currentRegion = listIterator.next(); + } + + public boolean hasNext() { + primePump(); + return more; + } + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/Range.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/Range.java new file mode 100644 index 00000000000..370ebeba21b --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/Range.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text; + +/** + * @author Ryan D. Brooks + */ +public class Range { + public int start; + public int end; + public int length; + + public Range(int start, int end) { + this.start = start; + this.end = end; + this.length = end - start; + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/Rule.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/Rule.java new file mode 100644 index 00000000000..1b6bcbdf6e5 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/Rule.java @@ -0,0 +1,194 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Collection; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.regex.Pattern; +import javax.xml.parsers.ParserConfigurationException; +import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet; +import org.eclipse.osee.framework.jdk.core.util.Lib; + +/** + * @author Ryan D. Brooks + */ +public abstract class Rule { + private String outExtension; + private String currentOutfileName; + private File inputFile; + private String subdirectoryName; + private Pattern fileNamePattern; + protected boolean ruleWasApplicable; + protected Logger logger; + + public Rule() { + this("done"); + } + + public Rule(String outExtension) { + this.outExtension = outExtension; + this.ruleWasApplicable = false; + logger = Logger.getLogger(this.getClass().getName()); + logger.setLevel(Level.ALL); + this.subdirectoryName = null; + } + + public abstract ChangeSet computeChanges(CharSequence seq); + + public void process(Collection<File> list) { + for (File file : list) { + try { + process(file); + } catch (Exception ex) { + System.out.println(currentOutfileName + ": " + ex.getMessage()); + } + } + } + + public void process(File file) throws IOException { + if (file.isDirectory()) { + List<File> files = Lib.recursivelyListFiles(file, fileNamePattern); + for (File aFile : files) { + try { + process(aFile); + } catch (Exception ex) { + System.out.println(currentOutfileName + ": " + ex.getMessage()); + } + } + } else { + inputFile = file; + process(file, getResultFile(file)); + } + } + + public void process(File inFile, File outFile) throws IOException { + File subdirectory; + if (subdirectoryName != null) { + File parent = outFile.getParentFile(); + subdirectory = new File(parent, subdirectoryName); + subdirectory.mkdir(); + outFile = new File(subdirectory, outFile.getName()); + } + + this.currentOutfileName = outFile.getName(); + if (inFile.exists()) { + RulesLogHandler handler = null; + ChangeSet changeSet = null; + try { + handler = new RulesLogHandler(new File(Lib.changeExtension(outFile.getPath(), "xml"))); + logger.addHandler(handler); + ruleWasApplicable = false; + changeSet = computeChanges(Lib.fileToCharBuffer(inFile)); + } catch (ParserConfigurationException ex) { + logger.log(Level.SEVERE, ex.toString(), ex); + } finally { + if (handler != null) { + handler.close(); + logger.removeHandler(handler); + } + } + if (ruleWasApplicable) { + if (subdirectoryName == null) { + System.out.println("Rule was applied to " + currentOutfileName); + } else + System.out.println("Rule was applied to " + subdirectoryName + currentOutfileName); + + if (changeSet != null) changeSet.applyChanges(outFile); + } + // else { + // System.out.println("Not applicable to " + currentFileName); + // } + + } else { + System.out.println("The file " + inFile + " does not exist!"); + } + } + + protected File getResultFile(File file) { + + if (outExtension == null) { + return file; + } + + return new File(Lib.removeExtension(file.getPath()) + "." + outExtension); + } + + public static void main(String[] args) throws Exception { + if (args.length < 3) { + System.out.println("Usage: " + Rule.class.getName() + " <ruleClassPath> <ruleClass> <file list>"); + return; + } + + String ruleName = args[1]; + String classPath = args[0]; + try { + URLClassLoader classLoader = new URLClassLoader(new URL[] {Lib.getUrlFromString(classPath)}); + System.out.println("class path: " + classLoader.getURLs()[0]); + Object obj = classLoader.loadClass(ruleName).newInstance(); + + if (obj instanceof org.eclipse.osee.framework.jdk.core.text.Rule) { + Rule rule = (Rule) obj; + for (int i = 2; i < args.length; i++) { + try { + rule.process(new File(args[i])); + } catch (Exception ex) { + System.out.println("Exception in Rule!!! " + rule.currentOutfileName + ": " + ex.getMessage()); + ex.printStackTrace(); + } + } + } else { + throw new IllegalArgumentException(ruleName + " is not of type text.Rule."); + } + } catch (InstantiationException ex) { + System.out.println(ex); + } catch (IllegalAccessException ex) { + System.out.println(ex); + } catch (ClassNotFoundException ex) { + System.out.println(ex); + } + } + + public boolean ruleWasApplicable() { + return ruleWasApplicable; + } + + /** + * @return Returns the currentFileName. + */ + public String getCurrentOutfileName() { + return currentOutfileName; + } + + /** + * @param ruleWasApplicable The ruleWasApplicable to set. + */ + public void setRuleWasApplicable(boolean ruleWasApplicable) { + this.ruleWasApplicable = ruleWasApplicable; + } + + public File getInputFile() { + return inputFile; + } + + public void setSubdirectoryNameToPlaceResultFilesIn(String subdirectoryName) { + this.subdirectoryName = subdirectoryName; + } + + public void setFileNamePattern(Pattern fileNamePattern) { + this.fileNamePattern = fileNamePattern; + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/RuleRecord.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/RuleRecord.java new file mode 100644 index 00000000000..e8b736dcf6f --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/RuleRecord.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text; + +import java.util.logging.Level; +import java.util.logging.LogRecord; +import org.eclipse.osee.framework.jdk.core.persistence.Xmlizable; +import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * @author Michael A. Winston + */ +public class RuleRecord extends LogRecord implements Xmlizable { + + private static final long serialVersionUID = 6974861818239720347L; + + /** + * RuleRecord Constructor. This is an abstract class so this constructor is called via the super() call from the + * extended class. This sets the source, the logging level, the log message and whether a timestamp should be + * included. + * + * @param level The logging level. + * @param msg The log message. + */ + public RuleRecord(Level level, String msg) { + super(level, msg); + } + + /** + * Converts log element to XML format. + * + * @return xml formated element. + */ + public Element toXml(Document doc) { + Element recordElement = Jaxp.createElement(doc, getLevel().getName(), getMessage()); + return recordElement; + } + +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/RulesLogHandler.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/RulesLogHandler.java new file mode 100644 index 00000000000..fefecb6e140 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/RulesLogHandler.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text; + +import java.io.File; +import java.io.IOException; +import java.util.logging.Handler; +import java.util.logging.LogRecord; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; +import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import com.sun.org.apache.xml.internal.serialize.OutputFormat; + +/** + * @author Ryan D. Brooks + * @author Andrew M. Finkbeiner + */ +public class RulesLogHandler extends Handler { + + private Document document; + private File outFile; + private Element rootElement; + + /** + * RulesLogHandler Constructor. Sets the file to log to and the test script that will be logged. It also establishes + * the XML format to be used. + * + * @param outFile Reference to the file that will be used to output the log. + * @throws ParserConfigurationException + */ + public RulesLogHandler(File outFile) throws ParserConfigurationException { + super(); + this.outFile = outFile; + document = Jaxp.newDocument(); + rootElement = document.createElement("Rule"); + document.appendChild(rootElement); + } + + /** + * Write out the log records as XML. + */ + public void writeOutFile() { + // only write the XML file if there is something to write + if (rootElement.hasChildNodes()) { + try { + // create an XMLOutputter that indents using 3 spaces and uses new lines + OutputFormat format = new OutputFormat(document); + format.setIndenting(true); + format.setIndent(3); + Jaxp.writeXmlDocument(document, outFile, format); + } catch (IOException ex) { + ex.printStackTrace(); + } catch (TransformerException ex) { + ex.printStackTrace(); + } + } + } + + /* + * (non-Javadoc) + * + * @see java.util.logging.Handler#publish(java.util.logging.LogRecord) + */ + public void publish(LogRecord logRecord) { + if (!isLoggable(logRecord)) { + return; + } + + if (logRecord instanceof RuleRecord) { + RuleRecord record = (RuleRecord) logRecord; + rootElement.appendChild(record.toXml(document)); + } else { + rootElement.appendChild(Jaxp.createElement(document, logRecord.getLevel().getName(), logRecord.getMessage())); + } + } + + /* + * (non-Javadoc) + * + * @see java.util.logging.Handler#close() + */ + public void close() throws SecurityException { + writeOutFile(); + } + + /* + * (non-Javadoc) don't call this method + * + * @see java.util.logging.Handler#flush() + */ + public void flush() { + throw new UnsupportedOperationException(); + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/ChOps.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/ChOps.java new file mode 100644 index 00000000000..3b622798e7f --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/ChOps.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.change; + +/** + * @author Ryan D. Brooks + */ +public class ChOps { + + /** + * take a string containing one or more "\n" and replace with a new line char then replace all "\\n" with "\n" + * + * @param src + * @param srcStartIndex + * @param srcEndIndex + * @return char[] + */ + public static char[] embedNewLines(char[] src, int srcStartIndex, int srcEndIndex) { + int stop = srcEndIndex - 1; //don't loop for the last char so we can use src[i+1] + int replaceCount = 0; + for (int i = srcStartIndex; i < stop; i++) { + if (src[i] == '\\') { + i++; + if (src[i] == '\\' || src[i] == 'n') { + replaceCount++; + } + } + } + + char[] result = new char[srcEndIndex - srcStartIndex - replaceCount]; + + int srcPos = srcStartIndex; + for (int i = 0; i < result.length; i++) { + if (src[srcPos] == '\\') { + if (src[srcPos + 1] == '\\') { + srcPos += 2; // skip over the two escaped chars + result[i] = '\\'; // and replace them here + } else if (src[srcPos + 1] == 'n') { + srcPos += 2; // skip over the two escaped chars + result[i] = '\n'; // and replace them here + } else { + result[i] = src[srcPos++]; + } + } else { + result[i] = src[srcPos++]; + } + } + return result; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/ChangeSet.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/ChangeSet.java new file mode 100644 index 00000000000..dabd111d967 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/ChangeSet.java @@ -0,0 +1,256 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.change; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.nio.CharBuffer; +import java.util.regex.Matcher; + +/** + * @author Ryan D. Brooks + */ +public class ChangeSet { + private CharacterChanger firstChange; + private CharacterChanger lastChange; + private char[] sourceChars; + private CharSequence source; + + public ChangeSet() { + this(""); + } + + public ChangeSet(CharSequence source) { + if (source instanceof CharBuffer) { + CharBuffer charBuf = (CharBuffer) source; + if (charBuf.hasArray()) { + sourceChars = charBuf.array(); + return; + } + } + if (source instanceof String) { + sourceChars = ((String) source).toCharArray(); + } + this.source = source; + } + + private int copyFromSource(int srcStrartIndex, int srcEndIndex, char[] dest, int destPos) { + if (sourceChars != null) { + int length = srcEndIndex - srcStrartIndex; + System.arraycopy(sourceChars, srcStrartIndex, dest, destPos, length); + return destPos + length; + } else { + for (int i = srcStrartIndex; i < srcEndIndex; i++) { + dest[destPos++] = source.charAt(i); + } + return destPos; + } + } + + private void writeFromSource(int srcStrartIndex, int srcEndIndex, Writer writer) throws IOException { + if (sourceChars != null) { + writer.write(sourceChars, srcStrartIndex, srcEndIndex - srcStrartIndex); + } else { + for (int i = srcStrartIndex; i < srcEndIndex; i++) { + writer.write(source.charAt(i)); + } + } + } + + public int getSourceLength() { + if (sourceChars == null) { + return source.length(); + } + return sourceChars.length; + } + + public void applyChanges(char[] dest, int destPos) { + int lastEndIndex = 0; + + CharacterChanger change = firstChange; + while (change != null) { + destPos = copyFromSource(lastEndIndex, change.getStartIndex(), dest, destPos); + lastEndIndex = change.getEndIndex(); + destPos = change.applyChange(dest, destPos); + change = change.next(); + } + copyFromSource(lastEndIndex, getSourceLength(), dest, destPos); + } + + /** + * Make sure this writer is buffered if source is only a CharSequence + * + * @param writer + * @throws IOException + */ + public void applyChanges(Writer writer) throws IOException { + int lastEndIndex = 0; + + CharacterChanger change = firstChange; + while (change != null) { + writeFromSource(lastEndIndex, change.getStartIndex(), writer); + lastEndIndex = change.getEndIndex(); + change.applyChange(writer); + change = change.next(); + } + writeFromSource(lastEndIndex, getSourceLength(), writer); + } + + public void applyChanges(File outFile) throws IOException { + BufferedWriter writer = new BufferedWriter(new FileWriter(outFile)); + applyChanges(writer); + writer.close(); + } + + public void insertBefore(int index, char[] newChars, int offset, int length, boolean copy) { + addChanger(new CharArrayChange(index, index, newChars, offset, length, copy)); + } + + public void insertBefore(int index, char[] newChars, int offset, int length) { + addChanger(new CharArrayChange(index, index, newChars, offset, length)); + } + + public void insertBefore(int index, char[] newChars) { + addChanger(new CharArrayChange(index, index, newChars)); + } + + public void insertBefore(int index, char newChar) { + addChanger(new CharChange(index, index, newChar)); + } + + public void insertBefore(int index, String newChar) { + insertBefore(index, newChar.toCharArray()); + } + + public void replace(int srcStartIndex, int srcEndIndex, char[] newChars, int offset, int length) { + addChanger(new CharArrayChange(srcStartIndex, srcEndIndex, newChars, offset, length)); + } + + public void replace(int srcStartIndex, int srcEndIndex, char[] newChars) { + addChanger(new CharArrayChange(srcStartIndex, srcEndIndex, newChars)); + } + + public void replace(int srcStartIndex, int srcEndIndex, char newChar) { + addChanger(new CharChange(srcStartIndex, srcEndIndex, newChar)); + } + + public void replace(int srcStartIndex, int srcEndIndex, String newChar) { + replace(srcStartIndex, srcEndIndex, newChar.toCharArray()); + } + + public void delete(int srcStartIndex, int srcEndIndex) { + addChanger(new DeleteChange(srcStartIndex, srcEndIndex)); + } + + /** + * Replaces may not overlap. Deletes may overlap, but they must be combined into a single delete. Optionally you may + * combine adjacent deletes. Adjacent inserts may be done at the same index if start is < last end and not a delete + * since all changes are placed in order and normalized as they are added to the list of changes is always in order + * and normalized + */ + private void addChanger(CharacterChanger changer) { + if (firstChange == null) { // if the change set is currently empty + firstChange = changer; // no normalization needed since there is only one changer + lastChange = firstChange; + } else { + if (changer.getStartIndex() < lastChange.getStartIndex()) { // if change belongs somewhere before the end + + CharacterChanger current = firstChange; + CharacterChanger previous = null; + // search for insertion point + while (current.getStartIndex() <= changer.getStartIndex()) { + previous = current; + current = current.next(); // there should always be a next since we already checked that this changer does not belong on the end + } + addNormalized(previous, changer, current); + } else { // changer belongs on the end so skip search for insertion point + addNormalized(lastChange, changer, null); + } + } + } + + private void addNormalized(CharacterChanger previous, CharacterChanger changer, CharacterChanger next) { + // assumptions: if next is non-null, changer.srcEndIndex < next.srcStartIndex + // previous.srcEndIndex <= changer.srcEndIndex + // the current set of changes have no overlaps (i.e. is already normalized) + + // if these changes are adjacent deletes, just combine them + if (lastChange instanceof DeleteChange && next instanceof DeleteChange) { + //lastChange.setDeletionRange + } + + if (previous == null) { // if belongs at the head + firstChange = changer; + } else { // else insert in between + overlapping(previous.getEndIndex(), changer.getStartIndex()); + previous.setNext(changer); + } + if (next == null) { + lastChange = changer; + } else { + overlapping(changer.getEndIndex(), next.getStartIndex()); + changer.setNext(next); + } + } + + private void overlapping(int a, int b) { + if (a > b) { + throw new IllegalArgumentException( + "Overlapping changes are not currently allowed " + a + " > " + b + " " + new String(sourceChars, b - 4, + 20)); + } + } + + public int getLengthDelta() { + int lengthDelta = 0; + + CharacterChanger change = firstChange; + while (change != null) { + lengthDelta += change.getLengthDelta(); + change = change.next(); + } + return lengthDelta; + } + + public CharSequence applyChangesToSelf() { + this.sourceChars = toCharArray(); + this.source = CharBuffer.wrap(sourceChars); + this.firstChange = null; + this.lastChange = null; + return source; + } + + public char[] toCharArray() { + char[] chars = new char[getLengthDelta() + getSourceLength()]; + applyChanges(chars, 0); + return chars; + } + + public String toString() { + return new String(toCharArray()); + } + + /** + * This function calls reset(source) on your matcher and will replace all matched items in the ChangesSet source. + * + * @param matcher + * @param replacement + */ + public void replaceAll(Matcher matcher, String replacement) { + matcher.reset(source); + while (matcher.find()) { + replace(matcher.start(), matcher.end(), replacement); + } + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/CharArrayChange.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/CharArrayChange.java new file mode 100644 index 00000000000..5dc45cb6aff --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/CharArrayChange.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.change; + +import java.io.IOException; +import java.io.Writer; + +/** + * @author Ryan D. Brooks + */ +public class CharArrayChange implements CharacterChanger { + private int srcStartIndex; + private int srcEndIndex; + private char[] newChars; + private int offset; + private int length; + private CharacterChanger next; + + public CharArrayChange(int srcStartIndex, int srcEndIndex, char[] newChars, int offset, int length, boolean copy) { + super(); + this.srcStartIndex = srcStartIndex; + this.srcEndIndex = srcEndIndex; + if (copy) { + this.newChars = new char[newChars.length]; + System.arraycopy(newChars, 0, this.newChars, 0, newChars.length); + } else { + this.newChars = newChars; + } + this.offset = offset; + this.length = length; + } + + /** + * + */ + public CharArrayChange(int srcStartIndex, int srcEndIndex, char[] newChars, int offset, int length) { + this(srcStartIndex, srcEndIndex, newChars, offset, length, false); + } + + public CharArrayChange(int srcStartIndex, int srcEndIndex, char[] newChars) { + this(srcStartIndex, srcEndIndex, newChars, 0, newChars.length); + } + + /* (non-Javadoc) + * @see text.change.CharacterChanger#getStartIndex() + */ + public int getStartIndex() { + return srcStartIndex; + } + + /* (non-Javadoc) + * @see text.change.CharacterChanger#getEndIndex() + */ + public int getEndIndex() { + return srcEndIndex; + } + + /* (non-Javadoc) + * @see text.change.CharacterChanger#applyChange(char[], int) + */ + public int applyChange(char[] dest, int destPos) { + System.arraycopy(newChars, offset, dest, destPos, length); + return destPos + length; + } + + public void applyChange(Writer writer) throws IOException { + writer.write(newChars, offset, length); + } + + /* (non-Javadoc) + * @see text.change.CharacterChanger#next() + */ + public CharacterChanger next() { + return next; + } + + /* (non-Javadoc) + * @see text.change.CharacterChanger#setNext(text.change.CharacterChanger) + */ + public void setNext(CharacterChanger next) { + this.next = next; + } + + public int getLengthDelta() { + return length - srcEndIndex + srcStartIndex; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/CharChange.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/CharChange.java new file mode 100644 index 00000000000..691ac97487e --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/CharChange.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.change; + +import java.io.IOException; +import java.io.Writer; + +/** + * @author Ryan D. Brooks + */ +public class CharChange implements CharacterChanger { + private int srcStartIndex; + private int srcEndIndex; + private char newChar; + private CharacterChanger next; + + /** + * + */ + public CharChange(int srcStartIndex, int srcEndIndex, char newChar) { + super(); + this.srcStartIndex = srcStartIndex; + this.srcEndIndex = srcEndIndex; + this.newChar = newChar; + } + + /* (non-Javadoc) + * @see text.change.CharacterChanger#getStartIndex() + */ + public int getStartIndex() { + return srcStartIndex; + } + + /* (non-Javadoc) + * @see text.change.CharacterChanger#getEndIndex() + */ + public int getEndIndex() { + return srcEndIndex; + } + + /* (non-Javadoc) + * @see text.change.CharacterChanger#applyChange(char[], int) + */ + public int applyChange(char[] dest, int destPos) { + dest[destPos] = newChar; + return destPos + 1; + } + + public void applyChange(Writer writer) throws IOException { + writer.write(newChar); + } + + /* (non-Javadoc) + * @see text.change.CharacterChanger#next() + */ + public CharacterChanger next() { + return next; + } + + /* (non-Javadoc) + * @see text.change.CharacterChanger#setNext(text.change.CharacterChanger) + */ + public void setNext(CharacterChanger next) { + this.next = next; + } + + public int getLengthDelta() { + return 1 - srcEndIndex + srcStartIndex; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/CharacterChanger.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/CharacterChanger.java new file mode 100644 index 00000000000..ad667c15221 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/CharacterChanger.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.change; + +import java.io.IOException; +import java.io.Writer; + +/** + * @author Ryan D. Brooks + */ +public interface CharacterChanger { + public int getStartIndex(); + + public int getEndIndex(); + + public int applyChange(char[] dest, int destPos); + + public void applyChange(Writer writer) throws IOException; + + public CharacterChanger next(); + + public void setNext(CharacterChanger next); + + public int getLengthDelta(); +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/DeleteChange.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/DeleteChange.java new file mode 100644 index 00000000000..3e25a2b6148 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/change/DeleteChange.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.change; + +import java.io.Writer; + +/** + * @author Ryan D. Brooks + */ +public class DeleteChange implements CharacterChanger { + private int srcStartIndex; + private int srcEndIndex; + private CharacterChanger next; + + /** + * + */ + public DeleteChange(int srcStartIndex, int srcEndIndex) { + super(); + this.srcStartIndex = srcStartIndex; + this.srcEndIndex = srcEndIndex; + } + + public void coalesce(DeleteChange overlapping) { + DeleteChange changeA = null; + DeleteChange changeB = null; + + // make changeA be the one with the smaller srcStartIndex + if (overlapping.srcStartIndex < srcStartIndex) { + changeA = overlapping; + changeB = this; + } else { + changeA = this; + changeB = overlapping; + } + + if (changeB.srcStartIndex > changeA.srcEndIndex) { // Note: delete 2,5 is not adjacent to 6,7 (char 5 is not deleted) + throw new IllegalArgumentException("Tried to coalesce non-adjacent, non-overlapping DeleteChanges"); + } + this.srcStartIndex = changeA.srcStartIndex; + this.srcEndIndex = changeB.srcEndIndex; + } + + /* (non-Javadoc) + * @see text.change.CharacterChanger#getStartIndex() + */ + public int getStartIndex() { + return srcStartIndex; + } + + /* (non-Javadoc) + * @see text.change.CharacterChanger#getEndIndex() + */ + public int getEndIndex() { + return srcEndIndex; + } + + /* (non-Javadoc) + * @see text.change.CharacterChanger#applyChange(char[], int) + */ + public int applyChange(char[] dest, int destPos) { + return destPos; + } + + public void applyChange(Writer writer) { + return; + } + + /* (non-Javadoc) + * @see text.change.CharacterChanger#next() + */ + public CharacterChanger next() { + return next; + } + + /* (non-Javadoc) + * @see text.change.CharacterChanger#setNext(text.change.CharacterChanger) + */ + public void setNext(CharacterChanger next) { + this.next = next; + } + + public int getLengthDelta() { + return srcStartIndex - srcEndIndex; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/AdddistributionStatement.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/AdddistributionStatement.java new file mode 100644 index 00000000000..31be09cec4a --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/AdddistributionStatement.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.rules; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.osee.framework.jdk.core.text.Rule; +import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet; + +/** + * @author Ryan D. Brooks + */ +public class AdddistributionStatement extends Rule { + private static final Pattern classDeclarationP = + Pattern.compile("^[/\\s\\*]*(?:Created on [^\n]+)?[\\s\\*]*(?:PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE)?[/\\s\\*]*package"); + private static final char[] distributionStatement = + "/*******************************************************************************\n * Copyright (c) 2004, 2007 Boeing.\n * All rights reserved. This program and the accompanying materials\n * are made available under the terms of the Eclipse Public License v1.0\n * which accompanies this distribution, and is available at\n * http://www.eclipse.org/legal/epl-v10.html\n *\n * Contributors:\n * Boeing - initial API and implementation\n *******************************************************************************/\n".toCharArray(); + + public AdddistributionStatement() { + super(null); + setFileNamePattern(Pattern.compile(".*\\.java")); + } + + public ChangeSet computeChanges(CharSequence seq) { + ChangeSet changeSet = new ChangeSet(seq); + + Matcher matcher = classDeclarationP.matcher(seq); + if (matcher.find()) { + setRuleWasApplicable(true); + changeSet.replace(0, matcher.end(), distributionStatement); + } + + return changeSet; + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/HtmlTableBuilder.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/HtmlTableBuilder.java new file mode 100644 index 00000000000..31a0a1cc544 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/HtmlTableBuilder.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.rules; + +import java.io.File; +import java.io.IOException; +import org.eclipse.osee.framework.jdk.core.text.Rule; +import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet; + +/** + * @author Ryan D. Brooks + */ +public class HtmlTableBuilder extends Rule { + + public HtmlTableBuilder() { + super("html"); + } + + public ChangeSet computeChanges(CharSequence seq) { + ChangeSet changeSet = new ChangeSet(seq); + + changeSet.insertBefore(0, "<html>\n<body>\n<table cellpadding=2 cellspacing=0 border=1>\n".toCharArray()); + + char[] rowStartChars = {'\t', '<', 't', 'r', '>', '\n'}; + char[] cellStartChars = "\t\t<td>".toCharArray(); + char[] cellEndChars = "</td>\n".toCharArray(); + char[] rowEndChars = {'\t', '<', '/', 't', 'r', '>', '\n'}; + + int lineStart = 0; + int lineEnd = 0; + int length = seq.length(); + for (int i = 0; i < length; i++) { + if (seq.charAt(i) == '\n') { /* find the lineEnd of a line */ + lineEnd = i + 1; + changeSet.insertBefore(lineStart, rowStartChars); + + int tabStart = lineStart; + for (int k = lineStart; k < lineEnd; k++) { + if (seq.charAt(k) == '\t' || k == i) { // if tab or end of line + changeSet.insertBefore(tabStart, cellStartChars); + tabStart = k + 1; + changeSet.replace(k, tabStart, cellEndChars); + } + } + changeSet.insertBefore(lineEnd, rowEndChars); + lineStart = lineEnd; + } + } + changeSet.insertBefore(length, "</table>\n</body>\n</html>".toCharArray()); + + return changeSet; + } + + public static void main(String[] args) throws IOException { + StringBuffer buffer = new StringBuffer(); + buffer.append(System.getProperty("user.home")); + buffer.append(File.separator); + buffer.append(HtmlTableBuilder.class.getName()); + buffer.append(".table.txt"); + new HtmlTableBuilder().process(new File(buffer.toString())); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/HushHtmlScriptErrors.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/HushHtmlScriptErrors.java new file mode 100644 index 00000000000..1e99155e0d1 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/HushHtmlScriptErrors.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.rules; + +import java.io.File; +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.osee.framework.jdk.core.text.Rule; +import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet; + +/** + * This rule is to be used on html files. It adds error handling so that unsupported java scripting calls do not result + * in pesky windows being shown to the user. For example, when javadoc produced API's are viewed through the eclipse + * help system and the javadoc attempts to set the title of the parent. + * + * @author Robert A. Fisher + */ +public class HushHtmlScriptErrors extends Rule { + + // This is the code that must be entered in to the HTML to hush script errors + private final static String HUSH = + "\nfunction handleError() {\n" + "return true;\n" + "}\n\n" + "window.onerror = handleError;\n"; + + public HushHtmlScriptErrors() { + super(null); + } + + public ChangeSet computeChanges(CharSequence seq) { + Pattern detectHusherInPlace = Pattern.compile("function handleError"); + Pattern findJavaScriptArea = Pattern.compile("<SCRIPT type=\"text/javascript\">"); + ChangeSet changeSet = new ChangeSet(seq); + + // Only add in hushing if it is not in place + Matcher matchHusher = detectHusherInPlace.matcher(seq); + if (!matchHusher.find()) { + + Matcher matcher = findJavaScriptArea.matcher(seq); + if (matcher.find()) { + ruleWasApplicable = true; + + changeSet.insertBefore(matcher.end() + 1, HUSH); + } + } + + return changeSet; + } + + public static void main(String[] args) { + HushHtmlScriptErrors hushRule = new HushHtmlScriptErrors(); + for (int i = 0; i < args.length; i++) { + try { + System.out.print("File " + (i + 1) + "/" + (args.length) + ":"); + hushRule.process(new File(args[i])); + } catch (Exception ex) { + System.out.println("Exception in Rule!!! " + hushRule.getCurrentOutfileName() + ": " + ex.getMessage()); + ex.printStackTrace(); + } + } + System.out.println("Finished"); + } + + /* + * (non-Javadoc) + * @see org.eclipse.osee.framework.jdk.core.text.Rule#process(java.io.File, java.io.File) + */ + public void process(File inFile, File outFile) throws IOException { + //Filter files being processed by this to only be of type .html + if (inFile.getName().endsWith(".html")) super.process(inFile, outFile); + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/MultilineStrLiteral.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/MultilineStrLiteral.java new file mode 100644 index 00000000000..39a783f5205 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/MultilineStrLiteral.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.rules; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.osee.framework.jdk.core.text.Rule; +import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet; + +/** + * @author Ryan D. Brooks + */ +public class MultilineStrLiteral extends Rule { + public static final Pattern wrappedStrLiteralP = Pattern.compile("\n[^\"\n]+(\"[ \t]*\n)[^\"]*?\n(\\s*\")"); + public static final Pattern signleLineP = Pattern.compile("[^\n]*\n"); + + public MultilineStrLiteral() { + super(null); // don't change extension on resulting file (i.e. overwrite the original file) + } + + public ChangeSet computeChanges(CharSequence seq) { + Matcher signleLineM = signleLineP.matcher(""); + Matcher wrappedStrLiteralM = wrappedStrLiteralP.matcher(seq); + ChangeSet changeSet = new ChangeSet(seq); + char[] terminateLineChars = new char[] {'\\', 'n', '\"'}; + + while (wrappedStrLiteralM.find()) { + ruleWasApplicable = true; + // delete the first quote and following white-space up to and including the first new line + changeSet.delete(wrappedStrLiteralM.start(1), wrappedStrLiteralM.end(1)); + + int subIndex = wrappedStrLiteralM.end(1); + signleLineM.reset(seq.subSequence(subIndex, wrappedStrLiteralM.start(2))); + while (signleLineM.find()) { + changeSet.insertBefore(subIndex + signleLineM.start(0), '\"'); + changeSet.insertBefore(subIndex + signleLineM.end(0) - 1, terminateLineChars); + } + changeSet.delete(wrappedStrLiteralM.start(2) - 1, wrappedStrLiteralM.end(2)); + } + return changeSet; + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/ReplaceAll.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/ReplaceAll.java new file mode 100644 index 00000000000..24a8df394c8 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/ReplaceAll.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.rules; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.osee.framework.jdk.core.text.Rule; +import org.eclipse.osee.framework.jdk.core.text.change.ChOps; +import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet; +import org.eclipse.osee.framework.jdk.core.util.Lib; + +/** + * @author Ryan D. Brooks + */ +public class ReplaceAll extends Rule { + private Pattern pattern; + private char[][] replacements; + + public ReplaceAll(Pattern pattern, String replacement) { + this(pattern, new String[] {replacement}); + } + + public ReplaceAll(Pattern pattern, String[] replacements) { + super(null); // don't change extension on resulting file (i.e. overwrite the original file) + this.pattern = pattern; + this.replacements = new char[replacements.length][]; + for (int i = 0; i < replacements.length; i++) { + char[] chars = replacements[i].toCharArray(); + this.replacements[i] = ChOps.embedNewLines(chars, 0, chars.length); + } + } + + public ReplaceAll(String patternStr, String[] replacements) { + this(Pattern.compile(patternStr), replacements); + } + + public ReplaceAll(String patternStr, String replacement) { + this(Pattern.compile(patternStr), replacement); + } + + public ChangeSet computeChanges(CharSequence seq) { + Matcher matcher = pattern.matcher(seq); + + ChangeSet changeSet = new ChangeSet(seq); + + while (matcher.find()) { + ruleWasApplicable = true; + + int numGroups = matcher.groupCount(); + if (numGroups == 0) { + changeSet.replace(matcher.start(), matcher.end(), replacements[0]); + } else { + for (int i = 0; i < numGroups; i++) { + int start = matcher.start(i + 1); + if (start > -1) { + changeSet.replace(start, matcher.end(i + 1), replacements[i]); + } + } + } + } + return changeSet; + } + + public static void main(String[] args) { + if (args.length < 3) { + System.out.println("Usage: java text.rules.ReplaceAll <pattern> <replace str or file> <directory> <fileName pattern>"); + return; + } + + try { + Rule rule = null; + if (new File(args[1]).exists()) { + List<String> list = Lib.readListFromFile(args[1]); + String[] strs = new String[list.size()]; + list.toArray(strs); + rule = new ReplaceAll(Pattern.compile(args[0]), strs); + } else { + rule = new ReplaceAll(Pattern.compile(args[0]), args[1]); + } + + rule.process(Lib.recursivelyListFiles(new File(args[2]), Pattern.compile(args[3]))); + } catch (IOException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/Unique.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/Unique.java new file mode 100644 index 00000000000..7d2cc4d26f1 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/rules/Unique.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.rules; + +import java.util.LinkedHashSet; +import org.eclipse.osee.framework.jdk.core.text.Rule; +import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet; + +/** + * @author Ryan D. Brooks + */ +public class Unique extends Rule { + public ChangeSet computeChanges(CharSequence seq) { + LinkedHashSet<Object> set = new LinkedHashSet<Object>(); + int start = 0; + int end = 0; + int length = seq.length(); + ChangeSet changeSet = new ChangeSet(seq); + + for (int i = 0; i < length; i++) { + if (seq.charAt(i) == '\n') { + end = i + 1; + if (!set.add(seq.subSequence(start, end))) { // if set already contains this line + changeSet.delete(start, end); // then skip over it + } + start = end; + } + } + ruleWasApplicable = true; + return changeSet; + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/CompareLists.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/CompareLists.java new file mode 100644 index 00000000000..aa1e4e358b5 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/CompareLists.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.tool; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; +import org.eclipse.osee.framework.jdk.core.util.Collections; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.jdk.core.util.io.MatchFilter; + +/** + * @author Ryan D. Brooks + */ +public class CompareLists { + + public static void main(String[] args) throws IOException { + + if (args.length != 4 && args.length != 2) { + System.out.println("Usage: java text.CompareLists <directory_1> <ext_1> <directory_2> <ext_2>"); + System.out.println("or : java text.CompareLists <path1> <path2>"); + return; + } + + if (args.length == 4) { + writeDiff(Lib.readListFromDir(args[0], new MatchFilter(".*\\." + args[1])), Lib.readListFromDir(args[2], + new MatchFilter(".*\\." + args[3])), new File("list_diff.txt"), + "Directory \"" + args[0] + "\", files with extension \"" + args[1] + "\"", + "Directory \"" + args[2] + "\", files with extension \"" + args[3] + "\""); + } else { + writeDiff(Lib.readListFromFile(args[0]), Lib.readListFromFile(args[1]), new File("list_diff.txt"), args[0], + args[1]); + } + } + + @SuppressWarnings("unchecked") + public static void writeDiff(Collection listA, Collection listB, File file, String listDescription1, String listDescription2) throws IOException { + BufferedWriter out = new BufferedWriter(new FileWriter(file)); + //Enforce uniqueness + Set setA = Collections.toSet(listA); + Set setB = Collections.toSet(listB); + + out.write("Items only in list A (" + listDescription1 + ")\n\n"); + List complement = Collections.setComplement(setA, setB); + for (int i = 0; i < complement.size(); i++) { + out.write(complement.get(i) + "\n"); + } + + out.write("\nItems only in list B (" + listDescription2 + ")\n\n"); + complement = Collections.setComplement(setB, setA); + for (int i = 0; i < complement.size(); i++) { + out.write(complement.get(i) + "\n"); + } + + //The intersection of two sets A and B is the set of elements common to A and B. + out.write("\nItems in both lists\n\n"); + ArrayList intersection = Collections.setIntersection(setA, setB); + for (int i = 0; i < intersection.size(); i++) { + out.write(intersection.get(i) + "\n"); + } + out.close(); + System.out.println("Finished processing. Output is in file \"list_diff.txt\""); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/CountAscii.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/CountAscii.java new file mode 100644 index 00000000000..bc673406169 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/CountAscii.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.tool; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import org.eclipse.osee.framework.jdk.core.util.io.MatchFilter; + +/** + * @author Ryan D. Brooks + */ +public class CountAscii { + + public static void main(String[] args) throws IOException { + if (args.length < 1) { + System.out.println("Usage: java text.CountAscii <directory of files>"); + return; + } + + int[] letterCount = new int[128]; + + File directory = new File(args[0]); + File[] files = directory.listFiles(new MatchFilter(".*\\.c")); + System.out.println("Found " + files.length + " files."); + + for (int i = 0; i < files.length; i++) { + BufferedReader in = new BufferedReader(new FileReader(files[i])); + int c = 0; + + while ((c = in.read()) != -1) { + letterCount[c]++; + } + in.close(); + } + + for (int i = 0; i < letterCount.length; i++) { + System.out.println((char) i + ": " + letterCount[i]); + } + /* + int total = 0; + for(int i=0; i<letterCount.length; i++) { + total += letterCount[i]; + }*/ + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/Find.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/Find.java new file mode 100644 index 00000000000..4a8d25ac1c0 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/Find.java @@ -0,0 +1,234 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.tool; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.osee.framework.jdk.core.text.FileToBufferConvert; +import org.eclipse.osee.framework.jdk.core.text.FindResults; +import org.eclipse.osee.framework.jdk.core.util.Lib; + +/** + * @author Ryan D. Brooks + */ +public class Find { + private Collection<File> files; + private FindResults results; + private FileToBufferConvert converter; + private int precedingCount; + private int trailingCount; + private Matcher[] matchers; + private boolean[] matcherUsed; + + /** + * @param patterns a Collection of strings that are regular expressions + * @param files + * @param converter + */ + public Find(Collection<String> patterns, Collection<File> files, FileToBufferConvert converter) { + this.files = files; + this.converter = converter; + this.precedingCount = 0; + this.trailingCount = 0; + this.results = new FindResults(patterns.size()); + + this.matchers = new Matcher[patterns.size()]; + int i = 0; + for (String pattern : patterns) { + // the empty string is never used in the search because a matcher.reset happens first + matchers[i++] = Pattern.compile(pattern).matcher(""); + } + this.matcherUsed = new boolean[matchers.length]; + } + + private static FileToBufferConvert simpleToBuffer = new SimpleFileToBufferConvert(); + + private static ArrayList<String> toList(String pattern) { + ArrayList<String> patterns = new ArrayList<String>(); + patterns.add(pattern); + return patterns; + } + + public Find(String pattern, File topLevelSearchDir, String fileNamePattern) { + this(toList(pattern), Lib.recursivelyListFiles(topLevelSearchDir, Pattern.compile(fileNamePattern)), + simpleToBuffer); + } + + public static void main(String[] args) throws IOException { + if (args.length < 7) { + System.out.println("Usage: java text.Find <pattern-list file or pattern> <search directory> <fileName pattern> <leading pad> <trailing pad> <negative: true|false> <ignoreComments: true|false>"); + return; + } + + ArrayList<String> patterns = null; + if (new File(args[0]).exists()) { + patterns = Lib.readListFromFile(args[0]); + } else { + patterns = new ArrayList<String>(); + patterns.add(args[0]); + } + File resultFile = new File("results.txt"); + BufferedWriter out = new BufferedWriter(new FileWriter(resultFile)); + + List<File> files = Lib.recursivelyListFiles(new File(args[1]), Pattern.compile(args[2])); + System.out.println("Searching " + files.size() + " files..."); + if (files.size() == 0) { + return; + } + + FileToBufferConvert toBuffer = null; + if (Boolean.valueOf(args[6]).booleanValue()) { + toBuffer = new StripBlockComments(); + } else { + toBuffer = simpleToBuffer; + } + + Find app = new Find(patterns, files, toBuffer); + app.setRegionPadding(Integer.parseInt(args[3]), Integer.parseInt(args[4])); + + if (Boolean.valueOf(args[5]).booleanValue()) { + app.findMeNot(); + } else { + app.find(999999, true); + } + OutputStreamWriter stdOut = new OutputStreamWriter(System.out); + stdOut.write(resultFile.getAbsolutePath()); + + app.writeUnusedPatterns(stdOut); + app.getResults().writeFindResutls(out); + out.close(); + } + + public void setRegionPadding(int precedingCount, int trailingCount) { + this.precedingCount = precedingCount; + this.trailingCount = trailingCount; + } + + public FindResults getResults() { + return results; + } + + /** + * Search a given file for all patterns: maxIsPerPattern == true up to maxMatches of any single pattern (then search + * the same file for the next pattern) otherwise up to a maxMatches for all patterns in a given file(then end search + * of that file and start on the next one) + * + * @param maxMatches + * @param maxIsPerPattern + */ + public void find(int maxMatches, boolean maxIsPerPattern) { + for (Iterator<File> iter = files.iterator(); iter.hasNext();) { // for each file + + File file = iter.next(); + CharSequence buf = null; + try { + buf = converter.fileToCharSequence(file); + } catch (Exception ex) { + System.out.println("In File " + file + ": " + ex); + continue; + } + + int numMatches = 0; + for (int i = 0; i < matchers.length; i++) { + matchers[i].reset(buf); + if (maxIsPerPattern) { + numMatches = 0; // new pattern matcher so reset the match count + } + + if (numMatches == maxMatches) { // can only be true if maxIsPerPattern is false + break; // don't look for any more matches in this file + } + + // find each pattern at most maxMatches per file + while (matchers[i].find() && numMatches++ < maxMatches) { + matcherUsed[i] = true; + // System.out.println(files[f].getName() + " " + matchers[i].group()); + + String region = null; + if (matchers[i].groupCount() == 0) { + if (precedingCount == 0 && trailingCount == 0) { + region = matchers[i].group(); + } else { + int start = matchers[i].start() - precedingCount; + if (start < 0) { + start = 0; + } + int end = matchers[i].end() + trailingCount; + if (end > buf.length()) { + end = buf.length(); + } + region = buf.subSequence(start, end).toString(); + } + } else { + region = matchers[i].group(1); + } + results.addMatch(matchers[i].pattern().pattern(), file, region); + } + } + } + } + + /** + * Search a given file list for all patterns: maxIsPerPattern == true up to maxMatches of any single pattern (then + * search the same file for the next pattern) otherwise up to a maxMatches for all patterns in a given file(then end + * search of that file and start on the next one) + */ + public void findMeNot() { + for (Iterator<File> iter = files.iterator(); iter.hasNext();) { // for each file + + File file = iter.next(); + CharSequence buf = null; + try { + buf = converter.fileToCharSequence(file); + } catch (ParseException ex) { + System.out.println(ex); + continue; + } catch (IOException ex) { + System.out.println(ex); + continue; + } + + for (int i = 0; i < matchers.length; i++) { + matchers[i].reset(buf); + if (!matchers[i].find()) { + matcherUsed[i] = true; + results.addMatch(matchers[i].pattern().pattern(), file, "findMeNot"); + } + } + } + } + + public void writeUnusedPatterns(Writer out) throws IOException { + boolean titleNotYetPrinted = true; + for (int i = 0; i < matcherUsed.length; i++) { + if (!matcherUsed[i]) { + if (titleNotYetPrinted) { + out.write("Patterns that were never used\n"); + titleNotYetPrinted = false; + } + out.write(matchers[i].pattern().pattern()); + out.write('\n'); + } + } + out.flush(); + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/FindNonLocalFunctionCalls.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/FindNonLocalFunctionCalls.java new file mode 100644 index 00000000000..bedf4967960 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/FindNonLocalFunctionCalls.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.tool; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.osee.framework.jdk.core.util.Lib; + +/** + * @author Ryan D. Brooks + */ +public class FindNonLocalFunctionCalls { + public static final Pattern functionCallPattern = Pattern.compile("\\W(\\w+)\\s*\\([^;{]*?\\)\\s*;"); + public static final Pattern functionDefPattern = Pattern.compile("\\W(\\w+)\\s*\\([^;{]*?\\)\\s*\\{"); + private LinkedHashSet<String> set; + private File[] files; + + public FindNonLocalFunctionCalls(File[] files) { + this.files = files; + set = new LinkedHashSet<String>(); + } + + public static void main(String[] args) { + File[] files = new File[args.length]; + for (int i = 0; i < args.length; i++) { + files[i] = new File(args[i]); + } + FindNonLocalFunctionCalls app = new FindNonLocalFunctionCalls(files); + app.searchFiles(); + app.print(); + } + + public void searchFiles() { + for (int i = 0; i < files.length; i++) { + try { + look(Lib.stripBlockComments(Lib.fileToCharBuffer(files[i]))); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + private void look(CharSequence seq) { + ArrayList<String> localFunctions = new ArrayList<String>(); + Matcher functionDefM = functionDefPattern.matcher(seq); + while (functionDefM.find()) { + localFunctions.add(functionDefM.group(1)); + } + + Matcher functionCallM = functionCallPattern.matcher(seq); + while (functionCallM.find()) { + if (!localFunctions.contains(functionCallM.group(1))) { + set.add(functionCallM.group(1)); + } + } + } + + public Set<String> getResultSet() { + return set; + } + + public void print() { + ArrayList<String> list = new ArrayList<String>(set); + Collections.sort(list); + for (Iterator<String> iter = list.iterator(); iter.hasNext();) { + System.out.println(iter.next()); + } + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/FunctionCallStats.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/FunctionCallStats.java new file mode 100644 index 00000000000..d2c3e634862 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/FunctionCallStats.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.tool; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Pattern; +import org.eclipse.osee.framework.jdk.core.text.FindResults; +import org.eclipse.osee.framework.jdk.core.util.Lib; + +/** + * @author Ryan D. Brooks + */ +public class FunctionCallStats { + @SuppressWarnings("unchecked") + public static void main(String[] args) throws IOException { + if (args.length < 2) { + System.out.println("Usage: FunctionCallStats <search directory> <fileName pattern>"); + return; + } + + ArrayList<String> patterns = new ArrayList<String>(); + patterns.add("\\W(\\w+)\\s*\\([^;{]*?\\)\\s*;"); + + BufferedWriter out = new BufferedWriter(new FileWriter("results.csv")); + + List files = Lib.recursivelyListFiles(new File(args[0]), Pattern.compile(args[1])); + System.out.println("Searching " + files.size() + " files..."); + + FindNonLocalFunctionCalls nonLocalFindApp = + new FindNonLocalFunctionCalls((File[]) files.toArray(new File[files.size()])); + nonLocalFindApp.searchFiles(); + Set nonLocalFunctions = nonLocalFindApp.getResultSet(); + + Find app = new Find(patterns, files, new StripBlockComments()); + app.setRegionPadding(0, 0); + app.find(999999, true); + FindResults results = app.getResults(); + + class Counter { + public int count = 0; + } + + String lastFileName = null; + HashMap functions = new HashMap(1000); + for (FindResults.FindResultsIterator i = results.iterator(); i.hasNext();) { + String currentFileName = i.currentFile.getName(); + + if (i.currentRegion != null) { + if (!currentFileName.equals(lastFileName)) { + for (Iterator functionsIterator = functions.entrySet().iterator(); functionsIterator.hasNext();) { + Map.Entry entry = (Map.Entry) functionsIterator.next(); + String functionName = (String) entry.getKey(); + if (nonLocalFunctions.contains(functionName)) { + out.write(lastFileName); + out.write(','); + out.write(functionName); + out.write(','); + out.write(String.valueOf(((Counter) entry.getValue()).count)); + out.write('\n'); + } + } + lastFileName = currentFileName; + functions.clear(); + } + + Counter counter = (Counter) functions.get(i.currentRegion); + if (counter == null) { + counter = new Counter(); + } + counter.count++; + functions.put(i.currentRegion, counter); + } + } + out.close(); + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/ReplaceRcsLog.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/ReplaceRcsLog.java new file mode 100644 index 00000000000..e850b3500f5 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/ReplaceRcsLog.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.tool; + +import java.io.File; +import java.io.IOException; +import java.nio.CharBuffer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.osee.framework.jdk.core.text.Range; +import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.jdk.core.util.io.MatchFilter; + +/** + * @author Ryan D. Brooks + */ +public class ReplaceRcsLog { + private static final Pattern logStartP = Pattern.compile("\\$Log.*\\s+"); + private static final Pattern revP = Pattern.compile("Revision \\d+\\.\\d+.*"); + private static final Pattern revEndP = Pattern.compile("\n[* \t/\\\\]*\n"); + + public static void main(String[] args) { + if (args.length < 3) { + System.out.println("Usage: java text.ReplaceRcsLog <dir for history> <dir for content> <result dir>"); + return; + } + + ReplaceRcsLog app = new ReplaceRcsLog(); + app.replaceRcsLogs(new File(args[0]), new File(args[1]), new File(args[2])); + } + + /** + * @param directoryA directory of test files will have their rcs log extracted + * @param directoryB directory of test files that will have their content preserved and log replaced + * @param resultDir + */ + public void replaceRcsLogs(File directoryA, File directoryB, File resultDir) { + File[] files = directoryA.listFiles(new MatchFilter(".*\\.(c|mac|h)")); + + for (int i = 0; i < files.length; i++) { + File fileB = new File(directoryB, files[i].getName()); + if (fileB.exists()) { + replaceRcsLog(files[i], fileB, new File(resultDir, files[i].getName())); + } + } + } + + public void replaceRcsLog(File historyFile, File contentFile, File resultFile) { + + CharBuffer historySeq; + CharBuffer contentSeq; + try { + historySeq = Lib.fileToCharBuffer(historyFile); + Range historyRange = findRcsLog(historySeq); + + contentSeq = Lib.fileToCharBuffer(contentFile); + Range contentRange = findRcsLog(contentSeq); + + ChangeSet changeSet = new ChangeSet(contentSeq); + changeSet.replace(contentRange.start, contentRange.end, historySeq.array(), historyRange.start, + historyRange.length); + changeSet.applyChanges(resultFile); + } catch (IOException ex) { + ex.printStackTrace(); + return; + } catch (IllegalArgumentException ex) { + System.out.println(historyFile + ": " + ex.getMessage()); + return; + } + } + + public static Range findRcsLog(CharSequence seq) throws IllegalArgumentException { + Matcher logStartM = logStartP.matcher(seq); + if (!logStartM.find()) { + throw new IllegalArgumentException(" is missing $Log"); + } + int firstRevStartIndex = logStartM.end(); // first char of actual revision info + + Matcher revM = revP.matcher(seq); + int lastRevStartIndex = 0; + while (revM.find()) { + lastRevStartIndex = revM.start(); + } // this loop with cause the last revsion to be found (usually 1.1) + + Matcher revEndM = revEndP.matcher(seq); + int lastRevEndIndex = 0; + if (!revEndM.find(lastRevStartIndex)) { + throw new IllegalArgumentException(" didn't find end of revision info"); + } + lastRevEndIndex = revEndM.start() + 1; // include the last new line + + return new Range(firstRevStartIndex, lastRevEndIndex); + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/RpcrSignalChanges.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/RpcrSignalChanges.java new file mode 100644 index 00000000000..8287766f7f0 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/RpcrSignalChanges.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.tool; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.NoSuchElementException; +import java.util.StringTokenizer; + +/** + * @author Ryan D. Brooks + */ +public class RpcrSignalChanges { + public String rpcrName; + public ArrayList<String> signals; + public boolean mux; + + public RpcrSignalChanges(File file) throws IOException { + rpcrName = file.getName().substring(0, 4); + this.signals = new ArrayList<String>(500); + + BufferedReader in = null; + try { + in = new BufferedReader(new FileReader(file)); + } catch (FileNotFoundException ex) { + System.err.println(ex); + throw new IllegalArgumentException(ex.toString()); + } + + String line = null; + // if line 6 starts with " Signal Name", then these are mux changes + for (int j = 0; j < 6; j++) { + line = in.readLine(); + } + + mux = line.startsWith(" Signal Name"); + + while ((line = in.readLine()) != null) { + String result = extractSignal(line); + if (result != null) { + signals.add(result); + } + } + in.close(); + } + + protected String extractSignal(String line) { + try { + StringTokenizer tok = new StringTokenizer(line); + if (!tok.hasMoreTokens()) { + System.out.println("blank line"); + return null; + } + String changeSymbol = tok.nextToken(); + + if (changeSymbol.equals("+") || changeSymbol.equals(">")) { + if (!tok.nextToken().equals("is:")) { + throw new IllegalArgumentException("Ryan --> you didn't think of everyting. Duh!"); + } + if (line.charAt(6) != ' ') { // there is either a mux name or a fiber interface + if (mux) { + return line.substring(6, 25).trim(); + } else { + tok.nextToken(); // skip interface name + String elementName = tok.nextToken(); + String lmName = tok.nextToken(); + return "l_" + lmName.toLowerCase() + "__" + elementName.toLowerCase(); + } + } + } + } catch (NoSuchElementException ex) { + System.out.println(ex + line); + System.exit(1); + } + return null; + } + + public boolean affectsLine(String line) { + for (int i = 0; i < signals.size(); i++) { + if (line.indexOf((String) signals.get(i)) != -1) { + return true; + } + } + return false; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/SignalChanges.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/SignalChanges.java new file mode 100644 index 00000000000..1ad00a7b132 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/SignalChanges.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.tool; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import org.eclipse.osee.framework.jdk.core.util.io.MatchFilter; + +/** + * @author Ryan D. Brooks + */ +public class SignalChanges { + + public static void main(String[] args) throws IOException { + if (args.length < 1) { + System.out.println("Usage: java text.SignalChanges <.dat directory> <scirpt source directory>"); + return; + } + + ArrayList<Object> list = loadList(args[0]); + writeSignalChanges(list, new File(args[0], "cdb_changes.txt"), new File(args[0], "mux_changes.txt")); + writeChangeVerification(args[1], list); + } + + // return list of RpcrSignalChanges found in the dat files in the given directory + public static ArrayList<Object> loadList(String path) throws IOException { + ArrayList<Object> list = new ArrayList<Object>(20); + + File directory = new File(path); + File[] files = directory.listFiles(new MatchFilter(".*\\.txt")); + Arrays.sort(files); + System.out.println("Found " + files.length + " dat files in " + path + "."); + + for (int i = 0; i < files.length; i++) { + list.add(new RpcrSignalChanges(files[i])); + } + return list; + } + + public static void writeChangeVerification(String scriptsPath, ArrayList<Object> changesList) throws IOException { + BufferedWriter out = new BufferedWriter(new FileWriter("rpcr_list.txt")); + + File directory = new File(scriptsPath); + File[] files = directory.listFiles(new MatchFilter(".*\\.c")); + Arrays.sort(files); + System.out.println("Found " + files.length + " script files in " + scriptsPath + "."); + + for (int i = 0; i < changesList.size(); i++) { + RpcrSignalChanges rpCh = (RpcrSignalChanges) changesList.get(i); + out.write(rpCh.rpcrName + "\n"); + + for (int j = 0; j < files.length; j++) { + BufferedReader in = new BufferedReader(new FileReader(files[j])); + + String line = null; + while ((line = in.readLine()) != null) { + if (rpCh.affectsLine(line)) { + out.write("\t" + files[j].getName() + "\n"); + break; + } + } + in.close(); + } + out.flush(); + } + out.close(); + } + + public static void writeSignalChanges(ArrayList<Object> changesList, File outputFile, File muxOutputFile) throws IOException { + BufferedWriter out = new BufferedWriter(new FileWriter(outputFile)); + BufferedWriter muxOut = new BufferedWriter(new FileWriter(muxOutputFile)); + + for (int i = 0; i < changesList.size(); i++) { + RpcrSignalChanges rpcrCng = (RpcrSignalChanges) changesList.get(i); + if (rpcrCng.mux) { + for (int j = 0; j < rpcrCng.signals.size(); j++) { + muxOut.write(rpcrCng.rpcrName + "," + rpcrCng.signals.get(j) + "\n"); + } + } else { + for (int j = 0; j < rpcrCng.signals.size(); j++) { + out.write(rpcrCng.rpcrName + " " + rpcrCng.signals.get(j) + "\n"); + } + } + } + out.close(); + muxOut.close(); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/SimpleFileToBufferConvert.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/SimpleFileToBufferConvert.java new file mode 100644 index 00000000000..a1b4b14c210 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/SimpleFileToBufferConvert.java @@ -0,0 +1,29 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.text.tool;
+
+import java.io.File;
+import java.io.IOException;
+import org.eclipse.osee.framework.jdk.core.text.FileToBufferConvert;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class SimpleFileToBufferConvert implements FileToBufferConvert {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.jdk.core.text.FileToBufferConvert#fileToCharSequence(java.io.File)
+ */
+ public CharSequence fileToCharSequence(File file) throws IOException {
+ return Lib.fileToCharBuffer(file);
+ }
+}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/SourceCount.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/SourceCount.java new file mode 100644 index 00000000000..94c1ad4c9ea --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/SourceCount.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.tool; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +/** + * @author Ryan D. Brooks + */ +public class SourceCount { + protected BufferedReader in; + protected String line; + + public SourceCount() { + in = null; + line = null; + } + + public int countLOC(String sourceFile) { + try { + in = new BufferedReader(new FileReader(sourceFile)); + } catch (FileNotFoundException ex) { + System.err.println(ex); + System.exit(1); + } + + int count = 0; + try { + while ((line = in.readLine()) != null) { + ignoreComments(); + if (line != null) { //a comment might be the last line of the file + if (line.endsWith("{") || line.endsWith(";")) { // if logical LOC + count++; + } + } + } + } catch (IOException ex) { + System.err.println(ex); + System.exit(2); + } + return count; + } + + protected void ignoreComments() { + try { + while (line != null) { + line = line.trim(); + if (line.startsWith("/*")) { + while (line != null && !line.endsWith("*/")) { + line = in.readLine().trim(); + } + } else if (!line.startsWith("//")) { + //a logical LOC might have a comment folloing it on the same line + line = stripOffComment(line); + return; + } + line = in.readLine(); + } + } catch (IOException ex) { + System.err.println(ex); + System.exit(2); + } + } + + public static String stripOffComment(String line) { + int pos = line.lastIndexOf("//"); + if (pos != -1) { //if a comment is indeed there (maybe) + //the single line comment symbol might be part of a string literal + //this is hard because the string delimiter might also be part of a string literal + if (!insideStringLiteral(line, pos)) { + return line.substring(0, pos).trim(); + } + } + return line; + } + + public static boolean insideStringLiteral(String str, int pos) { + int index = 0; + boolean inside = false; + + char[] chars = new char[str.length()]; + str.getChars(0, chars.length, chars, 0); + + while (index < pos) { + if (chars[index] == '\\' && chars[index + 1] == '\"') { + index++; // skip over literal quotation marks + } else if (chars[index] == '\"') { + inside = !inside; + } + index++; + } + return inside; + } + + public static void main(String[] args) { + if (args.length < 1) { + System.out.println("Usage: SourceCount [source file]"); + return; + } + SourceCount app = new SourceCount(); + int loc = app.countLOC(args[0]); + System.out.println("Logical LOC: " + loc); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/StripBlockComments.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/StripBlockComments.java new file mode 100644 index 00000000000..56329b1acff --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/text/tool/StripBlockComments.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.text.tool; + +import java.io.File; +import java.io.IOException; +import org.eclipse.osee.framework.jdk.core.text.FileToBufferConvert; +import org.eclipse.osee.framework.jdk.core.util.Lib; + +/** + * @author Ryan D. Brooks + */ +public class StripBlockComments implements FileToBufferConvert { + public CharSequence fileToCharSequence(File file) throws IOException { + return Lib.stripBlockComments(Lib.fileToCharBuffer(file)); + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/AddingDoubleMap.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/AddingDoubleMap.java new file mode 100644 index 00000000000..8d6022bda3f --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/AddingDoubleMap.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Set; +import java.util.Map.Entry; + +/** + * @author Donald G. Dunne + */ +public class AddingDoubleMap<K> { + private final HashMap<K, MutableDouble> addingMap; + + public AddingDoubleMap(int initialCapacity) { + addingMap = new HashMap<K, MutableDouble>(initialCapacity); + } + + public AddingDoubleMap() { + addingMap = new HashMap<K, MutableDouble>(); + } + + public double get(K key) { + for (Entry<K, MutableDouble> entry : getCounts()) { + if (entry.getKey().equals(key)) return entry.getValue().getValue(); + } + return 0; + } + + public boolean contains(K key) { + for (Entry<K, MutableDouble> entry : getCounts()) { + if (entry.getKey().equals(key)) return true; + } + return false; + } + + public void put(K key, double byAmmount) { + MutableDouble count = addingMap.get(key); + if (count == null) { + addingMap.put(key, new MutableDouble(byAmmount)); + } else { + count.getValueAndInc(byAmmount); + } + } + + public void put(Collection<K> keys, double byAmmount) { + for (K key : keys) { + put(key, byAmmount); + } + } + + public Set<Entry<K, MutableDouble>> getCounts() { + return addingMap.entrySet(); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/CompositeKey.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/CompositeKey.java new file mode 100644 index 00000000000..80cea411895 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/CompositeKey.java @@ -0,0 +1,81 @@ +/*
+ * Created on Nov 14, 2008
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.framework.jdk.core.type;
+
+/**
+ * @author Ken J. Aguilar
+ */
+public final class CompositeKey<A, B> {
+ private A key1;
+ private B key2;
+
+ public CompositeKey() {
+ this(null, null);
+ }
+
+ public CompositeKey(A key1, B key2) {
+ setKeys(key1, key2);
+ }
+
+ public A getKey1() {
+ return key1;
+ }
+
+ public B getKey2() {
+ return key2;
+ }
+
+ public CompositeKey<A, B> setKeys(A key1, B key2) {
+ this.key1 = key1;
+ this.key2 = key2;
+ return this;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof CompositeKey) {
+ final CompositeKey<A, B> otherKey = (CompositeKey<A, B>) obj;
+ boolean result = true;
+ if (otherKey.key1 != null && key1 != null) {
+ result &= otherKey.key1.equals(key1);
+ } else {
+ result &= otherKey.key1 == null && key1 == null;
+ }
+ if (otherKey.key2 != null && key2 != null) {
+ result &= otherKey.key2.equals(key2);
+ } else {
+ result &= otherKey.key2 == null && key2 == null;
+ }
+ return result;
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ final int constant = 31;
+ int hashCode = 11;
+ if (key1 != null) {
+ hashCode = hashCode * constant + key1.hashCode();
+ } else {
+ hashCode = hashCode * constant;
+ }
+ if (key2 != null) {
+ hashCode = hashCode * constant + key2.hashCode();
+ } else {
+ hashCode = hashCode * constant;
+ }
+ return hashCode;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "key1: \"" + key1 + "\" + key2: \"" + key2 + "\"";
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/CompositeKeyHashMap.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/CompositeKeyHashMap.java new file mode 100644 index 00000000000..bb2650a6973 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/CompositeKeyHashMap.java @@ -0,0 +1,175 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * A hash map implementation that uses composite keys. This class is not thread safe. + * + * @author Ken J. Aguilar + * @param <KeyOne> + * @param <KeyTwo> + * @param <Value> + */ +public class CompositeKeyHashMap<KeyOne, KeyTwo, Value> implements Map<CompositeKey<KeyOne, KeyTwo>, Value> { + private final HashCollection<KeyOne, KeyTwo> signleKeyMap = new HashCollection<KeyOne, KeyTwo>(); + private final Map<CompositeKey<KeyOne, KeyTwo>, Value> map; + + private final ThreadLocal<CompositeKey<KeyOne, KeyTwo>> threadLocalKey = + new ThreadLocal<CompositeKey<KeyOne, KeyTwo>>() { + + @Override + protected CompositeKey<KeyOne, KeyTwo> initialValue() { + return new CompositeKey<KeyOne, KeyTwo>(); + } + + }; + + public CompositeKeyHashMap() { + this(50); + } + + public CompositeKeyHashMap(Map<CompositeKey<KeyOne, KeyTwo>, Value> map) { + this.map = map; + } + + public CompositeKeyHashMap(int initialCapacity) { + map = new HashMap<CompositeKey<KeyOne, KeyTwo>, Value>(initialCapacity); + } + + public void clear() { + map.clear(); + signleKeyMap.clear(); + } + + /* (non-Javadoc) + * @see java.util.Map#containsKey(java.lang.Object) + */ + /** + * Use this method to determine if any puts(keyOne, anything) have occurred + * + * @param keyOne + * @return whether the map contains the key keyOne + */ + public boolean containsKey(Object key1) { + return signleKeyMap.containsKey((KeyOne) key1); + } + + /** + * @param key1 + * @param key2 + * @return whether the map contains the compound key <keyOne, keyTwo> + */ + public boolean containsKey(KeyOne key1, KeyTwo key2) { + return map.containsKey(threadLocalKey.get().setKeys(key1, key2)); + } + + /** + * determines if at least one of the compound keys are mapped to this value + * + * @param value + * @return whether the map contains this value + */ + public boolean containsValue(Object value) { + return signleKeyMap.containsValue(value); + } + + public Set<Map.Entry<CompositeKey<KeyOne, KeyTwo>, Value>> entrySet() { + return map.entrySet(); + } + + public Value get(Object key) { + throw new UnsupportedOperationException("use getValues() instead"); + } + + public List<Value> getValues(KeyOne key1) { + Collection<KeyTwo> key2s = signleKeyMap.getValues(key1); + ArrayList<Value> values = new ArrayList<Value>(key2s.size()); + for (KeyTwo key2 : key2s) { + values.add(get(key1, key2)); + } + return values; + } + + public Value get(KeyOne key1, KeyTwo key2) { + return map.get(threadLocalKey.get().setKeys(key1, key2)); + } + + public boolean isEmpty() { + return map.isEmpty(); + } + + public Set<CompositeKey<KeyOne, KeyTwo>> keySet() { + return map.keySet(); + } + + public Value put(CompositeKey<KeyOne, KeyTwo> key, Value value) { + signleKeyMap.put(key.getKey1(), key.getKey2()); + return map.put(key, value); + } + + public Value put(KeyOne key1, KeyTwo key2, Value value) { + signleKeyMap.put(key1, key2); + return map.put(new CompositeKey<KeyOne, KeyTwo>(key1, key2), value); + } + + public void putAll(Map<? extends CompositeKey<KeyOne, KeyTwo>, ? extends Value> copyMap) { + map.putAll(copyMap); + + for (CompositeKey<KeyOne, KeyTwo> key : copyMap.keySet()) { + signleKeyMap.put(key.getKey1(), key.getKey2()); + } + } + + /* (non-Javadoc) + * @see java.util.Map#remove(java.lang.Object) + */ + public Value remove(Object key) { + throw new UnsupportedOperationException("use removeValues() instead"); + } + + /** + * @param key1 + * @return the previous value associated with key, or null if there was no mapping for key. + */ + public Collection<Value> removeValues(KeyOne key1) { + Collection<KeyTwo> key2s = signleKeyMap.getValues(key1); + if (key2s == null) { + return null; + } + ArrayList<Value> values = new ArrayList<Value>(key2s.size()); + for (KeyTwo key2 : key2s) { + values.add(map.remove(threadLocalKey.get().setKeys(key1, key2))); + } + signleKeyMap.removeValues(key1); + return values; + } + + public Value remove(KeyOne key1, KeyTwo key2) { + Value value = map.remove(threadLocalKey.get().setKeys(key1, key2)); + signleKeyMap.removeValue(key1, key2); + return value; + } + + public int size() { + return map.size(); + } + + public Collection<Value> values() { + return map.values(); + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/CompositeKeyQuadHashMap.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/CompositeKeyQuadHashMap.java new file mode 100644 index 00000000000..4e925755815 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/CompositeKeyQuadHashMap.java @@ -0,0 +1,179 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * A hash map implementation that uses composite keys. This class is not thread safe. + * + * @author Ken J. Aguilar + * @param <KeyOne> + * @param <KeyTwo> + * @param <Value> + */ +public class CompositeKeyQuadHashMap<KeyOne, KeyTwo, KeyThree, KeyFour, Value> implements Map<CompositeKeyQuadHashMap.CompositeKey<KeyOne, KeyTwo, KeyThree, KeyFour>, Value> { + + private final Map<CompositeKey<KeyOne, KeyTwo, KeyThree, KeyFour>, Value> map; + + private final ThreadLocal<CompositeKey<KeyOne, KeyTwo, KeyThree, KeyFour>> threadLocalKey = + new ThreadLocal<CompositeKey<KeyOne, KeyTwo, KeyThree, KeyFour>>() { + + @Override + protected CompositeKey<KeyOne, KeyTwo, KeyThree, KeyFour> initialValue() { + return new CompositeKey<KeyOne, KeyTwo, KeyThree, KeyFour>(); + } + + }; + + public static final class CompositeKey<A, B, C, D> { + private A key1; + private B key2; + private C key3; + private D key4; + + public CompositeKey() { + + } + + public CompositeKey(A key1, B key2, C key3, D key4) { + setKeys(key1, key2, key3, key4); + } + + public A getKey1() { + return key1; + } + + public B getKey2() { + return key2; + } + + public C getKey3() { + return key3; + } + + public D getKey4() { + return key4; + } + + public CompositeKey<A, B, C, D> setKeys(A key1, B key2, C key3, D key4) { + this.key1 = key1; + this.key2 = key2; + this.key3 = key3; + this.key4 = key4; + return this; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof CompositeKey) { + final CompositeKey<A, B, C, D> otherKey = (CompositeKey<A, B, C, D>) obj; + return otherKey.key1.equals(key1) && otherKey.key2.equals(key2) && otherKey.key3.equals(key3) && otherKey.key4.equals(key4); + } + return false; + } + + @Override + public int hashCode() { + int hashCode = 11; + hashCode = hashCode * 31 + key1.hashCode(); + hashCode = hashCode * 31 + key2.hashCode(); + hashCode = hashCode * 31 + key3.hashCode(); + hashCode = hashCode * 31 + key4.hashCode(); + return hashCode; + } + + } + + public CompositeKeyQuadHashMap() { + map = new HashMap<CompositeKey<KeyOne, KeyTwo, KeyThree, KeyFour>, Value>(); + } + + public CompositeKeyQuadHashMap(Map<CompositeKey<KeyOne, KeyTwo, KeyThree, KeyFour>, Value> map) { + this.map = map; + } + + public CompositeKeyQuadHashMap(int initialCapacity) { + map = new HashMap<CompositeKey<KeyOne, KeyTwo, KeyThree, KeyFour>, Value>(initialCapacity); + } + + public void clear() { + map.clear(); + } + + public boolean containsKey(Object key) { + return map.containsKey(key); + } + + public boolean containsKey(KeyOne a, KeyTwo b, KeyThree c, KeyFour d) { + return map.containsKey(threadLocalKey.get().setKeys(a, b, c, d)); + } + + public boolean containsValue(Object value) { + return map.containsValue(value); + } + + public Set<Map.Entry<CompositeKey<KeyOne, KeyTwo, KeyThree, KeyFour>, Value>> entrySet() { + return map.entrySet(); + } + + public Value get(Object key) { + if (CompositeKey.class.isInstance(key)) { + return map.get(key); + } else { + throw new IllegalArgumentException(String.format("Expected Type [CompositeKey], got type [%s].", + key.getClass().getName())); + } + } + + public Value get(KeyOne a, KeyTwo b, KeyThree c, KeyFour d) { + return map.get(threadLocalKey.get().setKeys(a, b, c, d)); + } + + public boolean isEmpty() { + return map.isEmpty(); + } + + public Set<CompositeKey<KeyOne, KeyTwo, KeyThree, KeyFour>> keySet() { + return map.keySet(); + } + + public Value put(CompositeKey<KeyOne, KeyTwo, KeyThree, KeyFour> key, Value value) { + return map.put(key, value); + } + + public Value put(KeyOne a, KeyTwo b, KeyThree c, KeyFour d, Value value) { + return map.put(new CompositeKey<KeyOne, KeyTwo, KeyThree, KeyFour>(a, b, c, d), value); + } + + public void putAll(Map<? extends CompositeKey<KeyOne, KeyTwo, KeyThree, KeyFour>, ? extends Value> m) { + map.putAll(m); + } + + public Value remove(Object key) { + return map.remove(key); + } + + public Value remove(KeyOne a, KeyTwo b, KeyThree c, KeyFour d) { + return map.remove(threadLocalKey.get().setKeys(a, b, c, d)); + } + + public int size() { + return map.size(); + } + + public Collection<Value> values() { + return map.values(); + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/CompositeKeyTripleHashMap.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/CompositeKeyTripleHashMap.java new file mode 100644 index 00000000000..803d470081e --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/CompositeKeyTripleHashMap.java @@ -0,0 +1,172 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * A hash map implementation that uses composite keys. This class is not thread safe. + * + * @author Ken J. Aguilar + * @param <KeyOne> + * @param <KeyTwo> + * @param <Value> + */ +public class CompositeKeyTripleHashMap<KeyOne, KeyTwo, KeyThree, Value> implements Map<CompositeKeyTripleHashMap.CompositeKey<KeyOne, KeyTwo, KeyThree>, Value> { + + private final Map<CompositeKey<KeyOne, KeyTwo, KeyThree>, Value> map; + + private final ThreadLocal<CompositeKey<KeyOne, KeyTwo, KeyThree>> threadLocalKey = + new ThreadLocal<CompositeKey<KeyOne, KeyTwo, KeyThree>>() { + + @Override + protected CompositeKey<KeyOne, KeyTwo, KeyThree> initialValue() { + return new CompositeKey<KeyOne, KeyTwo, KeyThree>(); + } + + }; + + public static final class CompositeKey<A, B, C> { + private A key1; + private B key2; + private C key3; + + public CompositeKey() { + + } + + public CompositeKey(A key1, B key2, C key3) { + setKeys(key1, key2, key3); + } + + public A getKey1() { + return key1; + } + + public B getKey2() { + return key2; + } + + public C getKey3() { + return key3; + } + + public CompositeKey<A, B, C> setKeys(A key1, B key2, C key3) { + this.key1 = key1; + this.key2 = key2; + this.key3 = key3; + return this; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof CompositeKey) { + final CompositeKey<A, B, C> otherKey = (CompositeKey<A, B, C>) obj; + return otherKey.key1.equals(key1) && otherKey.key2.equals(key2) && otherKey.key3.equals(key3); + } + return false; + } + + @Override + public int hashCode() { + int hashCode = 11; + hashCode = hashCode * 31 + key1.hashCode(); + hashCode = hashCode * 31 + key2.hashCode(); + hashCode = hashCode * 31 + key3.hashCode(); + return hashCode; + } + + } + + public CompositeKeyTripleHashMap() { + map = new HashMap<CompositeKey<KeyOne, KeyTwo, KeyThree>, Value>(); + } + + public CompositeKeyTripleHashMap(Map<CompositeKey<KeyOne, KeyTwo, KeyThree>, Value> map) { + this.map = map; + } + + public CompositeKeyTripleHashMap(int initialCapacity) { + map = new HashMap<CompositeKey<KeyOne, KeyTwo, KeyThree>, Value>(initialCapacity); + } + + public void clear() { + map.clear(); + } + + public boolean containsKey(Object key) { + return map.containsKey(key); + } + + public boolean containsKey(KeyOne a, KeyTwo b, KeyThree c) { + return map.containsKey(threadLocalKey.get().setKeys(a, b, c)); + } + + public boolean containsValue(Object value) { + return map.containsValue(value); + } + + public Set<Map.Entry<CompositeKey<KeyOne, KeyTwo, KeyThree>, Value>> entrySet() { + return map.entrySet(); + } + + public Value get(Object key) { + if (CompositeKey.class.isInstance(key)) { + return map.get(key); + } else { + throw new IllegalArgumentException(String.format("Expected Type [CompositeKey], got type [%s].", + key.getClass().getName())); + } + } + + public Value get(KeyOne a, KeyTwo b, KeyThree c) { + return map.get(threadLocalKey.get().setKeys(a, b, c)); + } + + public boolean isEmpty() { + return map.isEmpty(); + } + + public Set<CompositeKey<KeyOne, KeyTwo, KeyThree>> keySet() { + return map.keySet(); + } + + public Value put(CompositeKey<KeyOne, KeyTwo, KeyThree> key, Value value) { + return map.put(key, value); + } + + public Value put(KeyOne a, KeyTwo b, KeyThree c, Value value) { + return map.put(new CompositeKey<KeyOne, KeyTwo, KeyThree>(a, b, c), value); + } + + public void putAll(Map<? extends CompositeKey<KeyOne, KeyTwo, KeyThree>, ? extends Value> m) { + map.putAll(m); + } + + public Value remove(Object key) { + return map.remove(key); + } + + public Value remove(KeyOne a, KeyTwo b, KeyThree c) { + return map.remove(threadLocalKey.get().setKeys(a, b, c)); + } + + public int size() { + return map.size(); + } + + public Collection<Value> values() { + return map.values(); + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/CountingMap.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/CountingMap.java new file mode 100644 index 00000000000..71e2115cb06 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/CountingMap.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Set; +import java.util.Map.Entry; + +/** + * @author Ryan D. Brooks + */ +public class CountingMap<K> { + private final HashMap<K, MutableInteger> countingMap; + + public CountingMap(int initialCapacity) { + countingMap = new HashMap<K, MutableInteger>(initialCapacity); + } + + public CountingMap() { + countingMap = new HashMap<K, MutableInteger>(); + } + + public int get(K key) { + MutableInteger count = countingMap.get(key); + if (count == null) { + return 0; + } + return count.getValue(); + } + + public boolean contains(K key) { + return countingMap.containsKey(key); + } + + public void put(K key) { + MutableInteger count = countingMap.get(key); + if (count == null) { + countingMap.put(key, new MutableInteger(1)); + } else { + count.getValueAndInc(); + } + } + + public void put(K key, int byAmt) { + MutableInteger count = countingMap.get(key); + if (count == null) { + countingMap.put(key, new MutableInteger(byAmt)); + } else { + count.getValueAndInc(byAmt); + } + } + + public void put(Collection<K> keys) { + for (K key : keys) { + put(key); + } + } + + public Set<Entry<K, MutableInteger>> getCounts() { + return countingMap.entrySet(); + } + + public void clear() { + countingMap.clear(); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/DoubleKeyCountingMap.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/DoubleKeyCountingMap.java new file mode 100644 index 00000000000..25041c7a324 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/DoubleKeyCountingMap.java @@ -0,0 +1,182 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * @author Donald G. Dunne + */ +public class DoubleKeyCountingMap<KeyOne, KeyTwo> { + + HashMap<KeyOne, HashMap<KeyTwo, MutableInteger>> k1ToHashMap; + + public DoubleKeyCountingMap() { + k1ToHashMap = new HashMap<KeyOne, HashMap<KeyTwo, MutableInteger>>(); + } + + public DoubleKeyCountingMap(int initialCapacity) { + k1ToHashMap = new HashMap<KeyOne, HashMap<KeyTwo, MutableInteger>>(initialCapacity); + } + + public Map<KeyOne, KeyTwo> keySet() { + Map<KeyOne, KeyTwo> keySet = new HashMap<KeyOne, KeyTwo>(); + for (KeyOne one : k1ToHashMap.keySet()) { + for (KeyTwo two : k1ToHashMap.get(one).keySet()) { + keySet.put(one, two); + } + } + return keySet; + + } + + public Collection<MutableInteger> get(KeyOne k1) { + HashMap<KeyTwo, MutableInteger> o = k1ToHashMap.get(k1); + if (o == null) { + return null; + } + return o.values(); + } + + public MutableInteger get(KeyOne k1, KeyTwo k2) { + HashMap<KeyTwo, MutableInteger> o = k1ToHashMap.get(k1); + if (o != null) { + return o.get(k2); + } + return null; + } + + public MutableInteger put(KeyOne k1, KeyTwo k2, int v) { + MutableInteger returnV = null; + HashMap<KeyTwo, MutableInteger> o = k1ToHashMap.get(k1); + if (o != null) { + returnV = o.put(k2, new MutableInteger(v)); + } else { + o = new HashMap<KeyTwo, MutableInteger>(20); + returnV = o.put(k2, new MutableInteger(v)); + k1ToHashMap.put(k1, o); + } + return returnV; + } + + public MutableInteger add(KeyOne k1, KeyTwo k2, int v) { + MutableInteger returnV = null; + HashMap<KeyTwo, MutableInteger> o = k1ToHashMap.get(k1); + if (o != null) { + returnV = o.get(k2); + if (returnV != null) { + returnV.getValueAndInc(v); + o.put(k2, returnV); + } else { + o.put(k2, new MutableInteger(v)); + } + } else { + o = new HashMap<KeyTwo, MutableInteger>(20); + returnV = o.put(k2, new MutableInteger(v)); + k1ToHashMap.put(k1, o); + } + return returnV; + } + + public MutableInteger remove(KeyOne k1, KeyTwo k2) { + MutableInteger value = null; + HashMap<KeyTwo, MutableInteger> o = k1ToHashMap.get(k1); + if (o != null) { + value = o.remove(k2); + if (o.size() == 0) { + k1ToHashMap.remove(k1); + } + } + return value; + } + + @Override + public String toString() { + return k1ToHashMap.toString(); + } + + /** + * The collection provided by this method is not backed by this DoubleKeyHashMap, and thusly any modifications to + * Collection will not modify the map, and future modifications to the map will not modify the Collection. + * + * @return Return value collection + */ + public Collection<MutableInteger> allValues() { + Collection<MutableInteger> values = new HashSet<MutableInteger>(); + for (HashMap<KeyTwo, MutableInteger> map : k1ToHashMap.values()) { + values.addAll(map.values()); + } + return values; + } + + public Collection<MutableInteger> allValues(KeyOne key) { + HashMap<KeyTwo, MutableInteger> map = k1ToHashMap.get(key); + if (map != null) { + return new HashSet<MutableInteger>(map.values()); + } + return new HashSet<MutableInteger>(); + } + + public Map<KeyTwo, MutableInteger> getSubHash(KeyOne k1) { + return k1ToHashMap.get(k1); + } + + public boolean containsKey(KeyOne k1, KeyTwo k2) { + return (k1ToHashMap.containsKey(k1) && k1ToHashMap.get(k1).containsKey(k2)); + } + + public void clear() { + k1ToHashMap.clear(); + } + + public boolean isEmpty() { + return k1ToHashMap.size() == 0; + } + + public Set<KeyOne> getKeySetOne() { + return k1ToHashMap.keySet(); + } + + public Collection<? extends Map<KeyTwo, MutableInteger>> getInnerMaps() { + return k1ToHashMap.values(); + } + + /** + * Test for DoubleKeyCountingMap + * + * @param args + */ + public static void main(String[] args) { + DoubleKeyCountingMap<String, String> map = new DoubleKeyCountingMap<String, String>(23); + map.put("aaa", "now", 4); + System.out.println("Value should be 4 and is -> " + map.get("aaa", "now")); + for (int x = 1; x < 3; x++) { + map.add("aaa", "now", x); + } + map.add("bbb", "now", 4); + map.add("bbb", "now", 1); + map.add("aaa", "the", 3); + System.out.println("Value aaa,now should be 7 and is -> " + map.get("aaa", "now")); + System.out.println("Value bbb,now should be 5 and is -> " + map.get("bbb", "now")); + System.out.println("Value aaa,the should be 3 and is -> " + map.get("aaa", "the")); + + for (String key1 : map.getKeySetOne()) { + Map<String, MutableInteger> resolutionToCountMap = map.getSubHash(key1); + for (String key2 : resolutionToCountMap.keySet()) { + System.out.println(key1 + "," + key2 + "," + resolutionToCountMap.get(key2).getValue()); + } + } + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/DoubleKeyHashMap.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/DoubleKeyHashMap.java new file mode 100644 index 00000000000..56bfa5c0a89 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/DoubleKeyHashMap.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class DoubleKeyHashMap<KeyOne, KeyTwo, Value> { + + HashMap<KeyOne, HashMap<KeyTwo, Value>> k1ToHashMap; + + public DoubleKeyHashMap() { + k1ToHashMap = new HashMap<KeyOne, HashMap<KeyTwo, Value>>(); + } + + public Map<KeyOne, KeyTwo> keySet() { + Map<KeyOne, KeyTwo> keySet = new HashMap<KeyOne, KeyTwo>(); + for (KeyOne one : k1ToHashMap.keySet()) { + for (KeyTwo two : k1ToHashMap.get(one).keySet()) { + keySet.put(one, two); + } + } + return keySet; + + } + + public Collection<Value> get(KeyOne k1) { + HashMap<KeyTwo, Value> o = k1ToHashMap.get(k1); + if (o == null) { + return null; + } + return o.values(); + } + + public Value get(KeyOne k1, KeyTwo k2) { + HashMap<KeyTwo, Value> o = k1ToHashMap.get(k1); + if (o != null) { + return o.get(k2); + } + return null; + } + + public Value put(KeyOne k1, KeyTwo k2, Value v) { + Value returnV = null; + HashMap<KeyTwo, Value> o = k1ToHashMap.get(k1); + if (o != null) { + returnV = o.put(k2, v); + } else { + o = new HashMap<KeyTwo, Value>(20); + returnV = o.put(k2, v); + k1ToHashMap.put(k1, o); + } + return returnV; + } + + public Value remove(KeyOne k1, KeyTwo k2) { + Value value = null; + HashMap<KeyTwo, Value> o = k1ToHashMap.get(k1); + if (o != null) { + value = o.remove(k2); + if (o.size() == 0) { + k1ToHashMap.remove(k1); + } + } + return value; + } + + public String toString() { + return k1ToHashMap.toString(); + } + + /** + * The collection provided by this method is not backed by this DoubleKeyHashMap, and thusly any modifications to + * Collection will not modify the map, and future modifications to the map will not modify the Collection. + * + * @return Return value collection + */ + public Collection<Value> allValues() { + Collection<Value> values = new HashSet<Value>(); + for (HashMap<KeyTwo, Value> map : k1ToHashMap.values()) { + values.addAll(map.values()); + } + return values; + } + + public Collection<Value> allValues(KeyOne key) { + HashMap<KeyTwo, Value> map = k1ToHashMap.get(key); + if (map != null) { + return new HashSet<Value>(map.values()); + } + return new HashSet<Value>(); + } + + public Map<KeyTwo, Value> getSubHash(KeyOne k1) { + return k1ToHashMap.get(k1); + } + + public boolean containsKey(KeyOne k1, KeyTwo k2) { + return (k1ToHashMap.containsKey(k1) && k1ToHashMap.get(k1).containsKey(k2)); + } + + public void clear() { + k1ToHashMap.clear(); + } + + public boolean isEmpty() { + return k1ToHashMap.size() == 0; + } + + public Set<KeyOne> getKeySetOne() { + return k1ToHashMap.keySet(); + } + + public Collection<? extends Map<KeyTwo, Value>> getInnerMaps() { + return k1ToHashMap.values(); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/DoublePoint.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/DoublePoint.java new file mode 100644 index 00000000000..88e1d4bd022 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/DoublePoint.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +/** + * @author Charles Shaw + */ +public class DoublePoint { + + protected double x; + protected double y; + + /** + * @param x The x coordinate of the point. + * @param y The y coordinate of the point. + */ + public DoublePoint(double x, double y) { + super(); + this.x = x; + this.y = y; + } + + public DoublePoint() { + super(); + this.x = 0.0; + this.y = 0.0; + } + + public double getX() { + return x; + } + + public void setX(double x) { + this.x = x; + } + + public double getY() { + return y; + } + + public void setY(double y) { + this.y = y; + } + + public boolean equals(Object object) { + boolean matches = false; + + if (object instanceof DoublePoint) { + DoublePoint point = (DoublePoint) object; + matches = (point.x == this.x) && (point.y == this.y); + } + + return matches; + } + + public String toString() { + return "(" + x + ", " + y + ")"; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/FixedSizePriorityQueue.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/FixedSizePriorityQueue.java new file mode 100644 index 00000000000..6df849ff64f --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/FixedSizePriorityQueue.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +import java.util.Comparator; +import java.util.PriorityQueue; + +/** + * Creates a PriorityQueue of fixed size. Once the queue has become full, attempts to add elements will result in the + * least (or smallest) element being removed from the queue. + * + * @author David Diepenbrock + */ +public class FixedSizePriorityQueue<E> extends PriorityQueue<E> { + + private static final long serialVersionUID = 6408445028193363641L; + + private final int qSize; + + public FixedSizePriorityQueue(int size, Comparator<E> comparator) { + super(size, comparator); + this.qSize = size; + } + + public FixedSizePriorityQueue(int size) { + super(size); + this.qSize = size; + } + + public FixedSizePriorityQueue(int size, E initialElement) { + this(size); + this.add(initialElement); + } + + @Override + public boolean add(E o) { + return this.offer(o); + } + + @Override + public boolean offer(E o) { + if (size() >= qSize) this.poll(); + return super.offer(o); + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollection.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollection.java new file mode 100644 index 00000000000..a4caa19fe70 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollection.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +import java.util.Collection; + +/** + * A Map of keys to multiple values. Collections of values are stored in the Map. The type of Collection can be + * specified at construction, if desired. All Collections returned by methods are backed by the HashCollection, so + * changes to the HashCollection are reflected in the Collection, and vice-versa. However, modifications to the + * Collection outside of this class are generally discouraged because removal of the last item would then not guarantee + * removal of the key. + * <p> + * The implementation is tied to the HashCollectionPlus class, providing a null Object for the "plus" object. + * + * @author David Diepenbrock + */ +public class HashCollection<K, V> extends HashCollectionPlus<K, V, Object> { + + private static IPlusProvider<Object> provider = new IPlusProvider<Object>() { + public Object newObject() { + return null; + } + }; + + /******************************************************************************************************************** + * Constructors + *******************************************************************************************************************/ + + /** + * @see HashCollectionPlus#HashCollectionPlus(boolean, Class, int, float, IPlusProvider) + */ + @SuppressWarnings("unchecked") + public HashCollection(boolean isSynchronized, Class<? extends Collection> collectionType, int initialCapacity, float loadFactor) { + super(isSynchronized, collectionType, initialCapacity, loadFactor, provider); + } + + /** + * @see HashCollectionPlus#HashCollectionPlus(boolean, Class, int, IPlusProvider) + */ + @SuppressWarnings("unchecked") + public HashCollection(boolean isSynchronized, Class<? extends Collection> collectionType, int initialCapacity) { + super(isSynchronized, collectionType, initialCapacity, provider); + } + + /** + * @see HashCollectionPlus#HashCollectionPlus(boolean, Class, IPlusProvider) + */ + @SuppressWarnings("unchecked") + public HashCollection(boolean isSynchronized, Class<? extends Collection> collectionType) { + super(isSynchronized, collectionType, provider); + } + + /** + * Creates an unsynchronized HashCollection using a default Collection type + * + * @see HashCollection#HashCollection(boolean, Class, int, float) + * @see HashCollectionPlus#DEFAULT_COLLECTION_TYPE + */ + public HashCollection(int initialCapacity, float loadFactor) { + this(false, DEFAULT_COLLECTION_TYPE, initialCapacity, loadFactor); + } + + /** + * Creates an unsynchronized HashCollection using a default Collection type + * + * @see HashCollection#HashCollection(boolean, Class, int) + * @see HashCollectionPlus#DEFAULT_COLLECTION_TYPE + */ + public HashCollection(int initialCapacity) { + this(false, DEFAULT_COLLECTION_TYPE, initialCapacity); + } + + /** + * Creates an unsynchronized HashCollection using a default Collection type + * + * @see HashCollection#HashCollection(boolean, Class) + * @see HashCollectionPlus#DEFAULT_COLLECTION_TYPE + */ + public HashCollection() { + this(false, DEFAULT_COLLECTION_TYPE); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollectionPlus.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollectionPlus.java new file mode 100644 index 00000000000..3c1ff649808 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollectionPlus.java @@ -0,0 +1,306 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * A Map of keys to multiple values. Collections of values are stored in the Map. The type of Collection can be + * specified at construction, if desired. All Collections returned by methods are backed by the HashCollection, so + * changes to the HashCollection are reflected in the Collection, and vice-versa. However, modifications to the + * Collection outside of this class are generally discouraged because removal of the last item would then not guarantee + * removal of the key. The mapping also contains a "plus" object. This object can store additional information about the + * key. At construction a class of type IPlusProvider must be provided. This provider will generate instances of this + * "plus" object whenever a new key is added to the Map. When all of the items in the Collection are removed, the entire + * key is removed from the table - therefore, the "plus" object is only available as long as the Collection for a given + * key is not empty. + * + * @author David Diepenbrock + */ +public class HashCollectionPlus<K, V, O> { + + private boolean isSynchronized; + @SuppressWarnings("unchecked") + private Class<? extends Collection> collectionType; + private IPlusProvider<O> plusProvider; + + private Map<K, ObjectPair<Collection<V>, O>> map; + @SuppressWarnings("unchecked") + public static final Class<? extends Collection> DEFAULT_COLLECTION_TYPE = ArrayList.class; + + /******************************************************************************************************************** + * Constructors + *******************************************************************************************************************/ + + /** + * @param isSynchronized - If true, the Map & Collection will both be synchronized using the + * Collections.synchronizedMap & Collections.synchronizedCollection. otherwise, this class will not be + * synchronzied and therefore not threadsafe. + * @param collectionType The type of collection to use to as the values within the HashMap. + * @param initialCapacity + * @param plusProvider + * @see HashMap#HashMap(int, float) + */ + @SuppressWarnings("unchecked") + public HashCollectionPlus(boolean isSynchronized, Class<? extends Collection> collectionType, int initialCapacity, float loadFactor, IPlusProvider<O> plusProvider) { + + if (isSynchronized) + map = Collections.synchronizedMap(new HashMap<K, ObjectPair<Collection<V>, O>>(initialCapacity, loadFactor)); + else + map = new HashMap<K, ObjectPair<Collection<V>, O>>(initialCapacity, loadFactor); + + this.isSynchronized = isSynchronized; + this.collectionType = collectionType; + this.plusProvider = plusProvider; + } + + /** + * @param isSynchronized - If true, the Map & Collection will both be synchronized using the + * Collections.synchronizedMap & Collections.synchronizedCollection. otherwise, this class will not be + * synchronzied and therefore not threadsafe. + * @param collectionType - The type of collection to use to as the values within the HashMap. + * @param initialCapacity + * @param plusProvider + * @see HashMap#HashMap(int) + */ + @SuppressWarnings("unchecked") + public HashCollectionPlus(boolean isSynchronized, Class<? extends Collection> collectionType, int initialCapacity, IPlusProvider<O> plusProvider) { + if (isSynchronized) + map = Collections.synchronizedMap(new HashMap<K, ObjectPair<Collection<V>, O>>(initialCapacity)); + else + map = new HashMap<K, ObjectPair<Collection<V>, O>>(initialCapacity); + + this.isSynchronized = isSynchronized; + this.collectionType = collectionType; + this.plusProvider = plusProvider; + } + + /** + * @param isSynchronized - If true, the Map & Collection will both be synchronized using the + * Collections.synchronizedMap & Collections.synchronizedCollection. otherwise, this class will not be + * synchronzied and therefore not threadsafe. + * @param collectionType - The type of collection to use to as the values within the HashMap. + * @param plusProvider + * @see HashMap#HashMap() + */ + @SuppressWarnings("unchecked") + public HashCollectionPlus(boolean isSynchronized, Class<? extends Collection> collectionType, IPlusProvider<O> plusProvider) { + if (isSynchronized) + map = Collections.synchronizedMap(new HashMap<K, ObjectPair<Collection<V>, O>>()); + else + map = new HashMap<K, ObjectPair<Collection<V>, O>>(); + + this.isSynchronized = isSynchronized; + this.collectionType = collectionType; + this.plusProvider = plusProvider; + } + + /** + * Creates an unsynchronized HashCollectionPlus using a default Collection type (ArrayList) + * + * @see HashMap#HashMap(int, float) + */ + public HashCollectionPlus(int initialCapacity, float loadFactor, IPlusProvider<O> plusProvider) { + this(false, DEFAULT_COLLECTION_TYPE, initialCapacity, loadFactor, plusProvider); + } + + /** + * Creates an unsynchronized HashCollectionPlus using a default Collection type (ArrayList) + * + * @see HashMap#HashMap(int) + */ + public HashCollectionPlus(int initialCapacity, IPlusProvider<O> plusProvider) { + this(false, DEFAULT_COLLECTION_TYPE, initialCapacity, plusProvider); + } + + /** + * Creates an unsynchronized HashCollectionPlus using a default Collection type (ArrayList) + * + * @see HashMap#HashMap() + */ + public HashCollectionPlus(IPlusProvider<O> plusProvider) { + this(false, DEFAULT_COLLECTION_TYPE, plusProvider); + } + + /******************************************************************************************************************** + * Methods + *******************************************************************************************************************/ + + /** + * Adds the value to the collection specified by the key. If there is not a collection for the given key, a new + * collection is created and added to the hash. + * + * @param key The key whose collection we will add value to. + * @param value The value to be added. + * @return the collection containing value and all other items associated with the key. + */ + @SuppressWarnings("unchecked") + public Collection<V> put(K key, V value) { + ObjectPair<Collection<V>, O> objectPair = map.get(key); + if (objectPair == null) { + try { + Collection<V> items; + if (isSynchronized) + items = Collections.synchronizedCollection(collectionType.newInstance()); + else + items = collectionType.newInstance(); + + objectPair = new ObjectPair(items, plusProvider.newObject()); + map.put(key, objectPair); + } catch (InstantiationException ex) { + ex.printStackTrace(); + return null; + } catch (IllegalAccessException ex) { + ex.printStackTrace(); + return null; + } + } + objectPair.object1.add(value); + return objectPair.object1; + } + + /** + * Adds all of the items in the Collection values to the collection for the specified key. + * + * @param key The key to add the values to + * @param values The values to be added + * @return The collection for the key, containing all values. + */ + public Collection<V> put(K key, Collection<V> values) { + Collection<V> items = null; + + for (V value : values) { + if (items == null) + items = this.put(key, value); + else + items.add(value); + } + return items; + } + + /** + * @param key The key whose collection we will remove value from. + * @param value The value to be removed + * @return true iff the value was removed from the collection for key. + */ + public boolean removeValue(K key, V value) { + ObjectPair<Collection<V>, O> objectPair = map.get(key); + + if (objectPair != null) { + Collection<V> items = objectPair.object1; + if (items != null) { + if (items.remove(value)) { + if (items.isEmpty()) map.remove(key); + return true; + } + } + } + return false; + } + + public Collection<V> removeValues(K key) { + return map.remove(key).object1; + } + + /** + * Returns the Collection of items for this key, or null if the key does not exist. + * + * @param key + * @return Return value collection reference + */ + public Collection<V> getValues(K key) { + ObjectPair<Collection<V>, O> objectPair = map.get(key); + if (objectPair != null) return map.get(key).object1; + return null; + } + + /** + * Returns the Collection all items + * + * @param key + * @return Return value collection reference + */ + public List<V> getValues() { + List<V> values = new ArrayList<V>(); + for (ObjectPair<Collection<V>, O> objectPair : map.values()) { + if (objectPair != null) { + values.addAll(objectPair.object1); + } + } + return values; + } + + /** + * Returns the "plus" object associated with the key, or null if the key does not exist. + * + * @param key + * @return Return object reference + */ + public O getPlusObject(K key) { + ObjectPair<Collection<V>, O> objectPair = map.get(key); + if (objectPair != null) return map.get(key).object2; + return null; + } + + public Set<K> keySet() { + return map.keySet(); + } + + public void clear() { + map.clear(); + } + + public boolean containsKey(K key) { + return map.containsKey(key); + } + + public boolean isEmpty() { + return map.isEmpty(); + } + + /** + * The total number of key-value combinations + */ + public int size() { + int size = 0; + Set<K> keySet = keySet(); + + synchronized (map) { + for (K key : keySet) { + size += getValues(key).size(); + } + } + return size; + } + + /** + * @param value + * @return whether the map contains this value + */ + public boolean containsValue(Object value) { + for (ObjectPair<Collection<V>, O> objectPair : map.values()) { + if (objectPair != null) { + for (V tempValue : objectPair.object1) { + if (value.equals(tempValue)) { + return true; + } + } + } + } + return false; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollectionPlusMap.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollectionPlusMap.java new file mode 100644 index 00000000000..71c511d2360 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollectionPlusMap.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * A HashCollectionPlus which maintains a map as the "plus" object. + * + * @see HashCollectionPlus + * @author David Diepenbrock + */ +public class HashCollectionPlusMap<K, V, P, S> extends HashCollectionPlus<K, V, Map<P, S>> { + + /** + * Creates using a synchronized map for the "plus" object regardless of the isSynchronized flag, which is passed on + * to the HashCollectionPlus super object. + * + * @see HashCollectionPlus#HashCollectionPlus(boolean, Class, IPlusProvider) + */ + public HashCollectionPlusMap(boolean isSynchronized, Class<? extends Collection<?>> collectionType) { + super(isSynchronized, collectionType, new IPlusProvider<Map<P, S>>() { + public Map<P, S> newObject() { + return Collections.synchronizedMap(new HashMap<P, S>()); + } + }); + } + + /** + * Returns the value from the "plus" map associated with the two keys provided + * + * @param key The key to the hashCollection + * @param mapKey The key to the "plus" map + * @return The associated value, or null if either key had no associated entry. + */ + public S getMapValue(K key, P mapKey) { + S value = null; + Map<P, S> theMap = this.getPlusObject(key); + if (theMap != null) { + value = theMap.get(mapKey); + } + return value; + } + + /** + * Sets the value from the "plus" map associated with the two keys provided + * + * @param key The key to the hashCollection + * @param mapKey The key to the "plus" map + * @param value The value to set into the "plus" map for the mapKey + * @return true if the value was successfully set + */ + public boolean setMapValue(K key, P mapKey, S value) { + Map<P, S> theMap = this.getPlusObject(key); + if (theMap != null) { + theMap.put(mapKey, value); + return true; + } + return false; + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/IInputListener.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/IInputListener.java new file mode 100644 index 00000000000..4a742b0ef83 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/IInputListener.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +import java.util.Collection; + +/** + * @author Roberto E. Escobar + */ +public interface IInputListener<T> { + + void addNode(T node); + + void addNodes(Collection<T> nodes); + + void removeNode(T node); + + void removeAll(); + + void nodeChanged(T inNode); + + void inputChanged(); +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/IPlusProvider.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/IPlusProvider.java new file mode 100644 index 00000000000..c6813ea66f6 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/IPlusProvider.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +/** + * This object is designed for use with the HashCollectionPlus in order to provide new objects of a particular type. + * + * @author David Diepenbrock + */ +public interface IPlusProvider<O> { + + /** + * @return a new object of type O. + */ + public O newObject(); + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/IPropertyStore.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/IPropertyStore.java new file mode 100644 index 00000000000..f766cc17abf --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/IPropertyStore.java @@ -0,0 +1,172 @@ +/*
+ * Created on Feb 21, 2008
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.framework.jdk.core.type;
+
+import java.io.IOException;
+import java.util.Set;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface IPropertyStore {
+
+ /**
+ * Returns the value of the given key .
+ *
+ * @param key the key
+ * @return the value, or <code>null</code> if none
+ */
+ public String get(String key);
+
+ /**
+ * Returns the value, an array of strings, of the given key.
+ *
+ * @param key the key
+ * @return the array of string, or <code>null</code> if none
+ */
+ public String[] getArray(String key);
+
+ /**
+ * Convert the value of the given key to a boolean and return it.
+ *
+ * @param key the key
+ * @return the boolean value, or <code>false</code> if none
+ */
+ public boolean getBoolean(String key);
+
+ /**
+ * Convert the value of the given key to a double and return it.
+ *
+ * @param key the key
+ * @return the value converted to double, or throws <code>NumberFormatException</code> if none
+ * @exception NumberFormatException if the string value does not contain a parsable number.
+ * @see java.lang.Double#valueOf(java.lang.String)
+ */
+ public double getDouble(String key) throws NumberFormatException;
+
+ /**
+ * Convert the value of the given key to a float and return it.
+ *
+ * @param key the key
+ * @return the value converted to float, or throws <code>NumberFormatException</code> if none
+ * @exception NumberFormatException if the string value does not contain a parsable number.
+ * @see java.lang.Float#valueOf(java.lang.String)
+ */
+ public float getFloat(String key) throws NumberFormatException;
+
+ /**
+ * Convert the value of the given key to a int and return it.
+ *
+ * @param key the key
+ * @return the value converted to int, or throws <code>NumberFormatException</code> if none
+ * @exception NumberFormatException if the string value does not contain a parsable number.
+ * @see java.lang.Integer#valueOf(java.lang.String)
+ */
+ public int getInt(String key) throws NumberFormatException;
+
+ /**
+ * Convert the value of the given key to a long and return it.
+ *
+ * @param key the key
+ * @return the value converted to long, or throws <code>NumberFormatException</code> if none
+ * @exception NumberFormatException if the string value does not contain a parsable number.
+ * @see java.lang.Long#valueOf(java.lang.String)
+ */
+ public long getLong(String key) throws NumberFormatException;
+
+ /**
+ * Adds the pair <code>key/value</code>.
+ *
+ * @param key the key.
+ * @param value the value to be associated with the <code>key</code>
+ */
+ public void put(String key, String[] value);
+
+ /**
+ * Converts the double <code>value</code> to a string and adds the pair <code>key/value</code>.
+ *
+ * @param key the key.
+ * @param value the value to be associated with the <code>key</code>
+ */
+ public void put(String key, double value);
+
+ /**
+ * Converts the float <code>value</code> to a string and adds the pair <code>key/value</code>.
+ *
+ * @param key the key.
+ * @param value the value to be associated with the <code>key</code>
+ */
+ public void put(String key, float value);
+
+ /**
+ * Converts the integer <code>value</code> to a string and adds the pair <code>key/value</code>.
+ *
+ * @param key the key.
+ * @param value the value to be associated with the <code>key</code>
+ */
+ public void put(String key, int value);
+
+ /**
+ * Converts the long <code>value</code> to a string and adds the pair <code>key/value</code>.
+ *
+ * @param key the key.
+ * @param value the value to be associated with the <code>key</code>
+ */
+ public void put(String key, long value);
+
+ /**
+ * Adds the pair <code>key/value</code>.
+ *
+ * @param key the key.
+ * @param value the value to be associated with the <code>key</code>
+ */
+ public void put(String key, String value);
+
+ /**
+ * Converts the boolean <code>value</code> to a string and adds the pair <code>key/value</code>.
+ *
+ * @param key the key.
+ * @param value the value to be associated with the <code>key</code>
+ */
+ public void put(String key, boolean value);
+
+ /**
+ * Returns the property store's id
+ *
+ * @return The Property Store's id
+ */
+ public String getId();
+
+ /**
+ * Save a property store to a file.
+ *
+ * @param fileName the name of the file the property store values are written to.
+ * @throws IOException
+ */
+ public void save(String fileName) throws Exception;
+
+ /**
+ * Load a property store from a file and fill the receiver with its content.
+ *
+ * @param fileName the name of the file the property store values are read from.
+ * @throws IOException
+ */
+ public void load(String fileName) throws Exception;
+
+ /**
+ * Get keys referencing primitive type items
+ *
+ * @return primitive type item keys
+ */
+ public Set<String> keySet();
+
+ /**
+ * Get keys referencing arrayItems
+ *
+ * @return array item keys
+ */
+ public Set<String> arrayKeySet();
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/IVariantData.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/IVariantData.java new file mode 100644 index 00000000000..84cda2ca355 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/IVariantData.java @@ -0,0 +1,61 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.osee.framework.jdk.core.type;
+
+import java.io.InputStream;
+import java.util.Date;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface IVariantData {
+
+ public String get(String key);
+
+ public boolean isEmpty(String key);
+
+ public String[] getArray(String key);
+
+ public boolean getBoolean(String key);
+
+ public double getDouble(String key) throws NumberFormatException;
+
+ public float getFloat(String key) throws NumberFormatException;
+
+ public int getInt(String key) throws NumberFormatException;
+
+ public long getLong(String key) throws NumberFormatException;
+
+ public Date getDate(String key) throws IllegalArgumentException;
+
+ public String getStreamAsString(String key) throws Exception;
+
+ public InputStream getStream(String key) throws IllegalArgumentException;
+
+ public void put(String key, String[] value);
+
+ public void put(String key, double value);
+
+ public void put(String key, float value);
+
+ public void put(String key, int value);
+
+ public void put(String key, long value);
+
+ public void put(String key, String value);
+
+ public void put(String key, boolean value);
+
+ public void put(String key, Date date);
+
+ public void put(String key, byte[] bytes);
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/InputManager.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/InputManager.java new file mode 100644 index 00000000000..cc4b69d27f8 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/InputManager.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +/** + * @author Roberto E. Escobar + */ +public class InputManager<T> implements IInputListener<T> { + + private List<T> inputList; + private Set<IInputListener<T>> changeListeners; + + public InputManager() { + super(); + inputList = Collections.synchronizedList(new ArrayList<T>()); + changeListeners = Collections.synchronizedSet(new HashSet<IInputListener<T>>()); + } + + public List<T> getInputList() { + return inputList; + } + + public void addNode(T inNode) { + synchronized (inputList) { + inputList.add(inputList.size(), inNode); + } + synchronized (changeListeners) { + Iterator<IInputListener<T>> iterator = changeListeners.iterator(); + while (iterator.hasNext()) + (iterator.next()).addNode(inNode); + } + } + + public void addNodes(Collection<T> inNode) { + synchronized (inputList) { + this.inputList.addAll(inNode); + } + synchronized (changeListeners) { + Iterator<IInputListener<T>> iterator = changeListeners.iterator(); + while (iterator.hasNext()) + (iterator.next()).addNodes(inNode); + } + } + + public void removeNode(T inNode) { + synchronized (inputList) { + this.inputList.remove(inNode); + } + synchronized (changeListeners) { + Iterator<IInputListener<T>> iterator = changeListeners.iterator(); + while (iterator.hasNext()) + (iterator.next()).removeNode(inNode); + } + } + + public void nodeChanged(T inNode) { + synchronized (changeListeners) { + Iterator<IInputListener<T>> iterator = changeListeners.iterator(); + while (iterator.hasNext()) + (iterator.next()).nodeChanged(inNode); + } + } + + public void inputChanged() { + synchronized (changeListeners) { + Iterator<IInputListener<T>> iterator = changeListeners.iterator(); + while (iterator.hasNext()) + (iterator.next()).inputChanged(); + } + } + + public void removeAll() { + synchronized (inputList) { + this.inputList.clear(); + } + synchronized (changeListeners) { + Iterator<IInputListener<T>> iterator = changeListeners.iterator(); + while (iterator.hasNext()) { + (iterator.next()).removeAll(); + } + } + } + + public void addInputListener(IInputListener<T> listener) { + synchronized (changeListeners) { + changeListeners.add(listener); + } + + for (T node : inputList) { + listener.addNode(node); + } + } + + public void removeInputListener(IInputListener<T> listener) { + synchronized (changeListeners) { + changeListeners.remove(listener); + } + } + + public String toString() { + synchronized (inputList) { + String toReturn = ""; + for (int i = 0; i < inputList.size(); i++) { + T node = (T) inputList.get(i); + toReturn += node.toString(); + } + return toReturn + "\n\n"; + } + } + + public void dispose() { + synchronized (inputList) { + inputList.clear(); + } + synchronized (changeListeners) { + changeListeners.clear(); + } + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/MutableBoolean.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/MutableBoolean.java new file mode 100644 index 00000000000..39d6c064b75 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/MutableBoolean.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +/** + * This class implements a boolean that can be passed around and modified through a group of methods. + * + * @author Chris Austin + */ +public class MutableBoolean { + private boolean value; + + public MutableBoolean(boolean value) { + this.value = value; + } + + public boolean getValue() { + return value; + } + + public void setValue(boolean value) { + this.value = value; + } + + public String toString() { + return Boolean.toString(value); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/MutableDouble.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/MutableDouble.java new file mode 100644 index 00000000000..8cce695a5bc --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/MutableDouble.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +/** + * This class implements an double that can be passed around and modified through a group of methods. It also allows the + * double value to be retrieved then post incremented automatically. This is a nice functionality where a common counter + * needs to be used within calling methods, but it is not convenient to return the latest index via the return value. + * + * @author Donald G. Dunne + */ +public class MutableDouble { + private double value; + + public MutableDouble(double value) { + this.value = value; + } + + public double getValue() { + return value; + } + + public double getValueAndInc(double byAmmount) { + return value += byAmmount; + } + + public void setValue(double value) { + this.value = value; + } + + public String toString() { + return Double.toString(value); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/MutableInteger.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/MutableInteger.java new file mode 100644 index 00000000000..eb43eafac04 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/MutableInteger.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +/** + * This class implements an integer that can be passed around and modified through a group of methods. It also allows + * the integer value to be retrieved then post incremented automatically. This is a nice functionality where a common + * counter needs to be used within calling methods, but it is not convenient to return the latest index via the return + * value. + * + * @author Robert A. Fisher + */ +public class MutableInteger { + private int value; + + public MutableInteger(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + public int getValueAndInc() { + return value++; + } + + public int getValueAndInc(int byAmt) { + return value += byAmt; + } + + public void setValue(int value) { + this.value = value; + } + + public String toString() { + return Integer.toString(value); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/ObjectPair.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/ObjectPair.java new file mode 100644 index 00000000000..05baddd93ed --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/ObjectPair.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +/** + * @author Ryan D. Brooks + */ +public class ObjectPair<O, T> { + public O object1; + public T object2; + + public ObjectPair(O object1, T object2) { + this.object1 = object1; + this.object2 = object2; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof CompositeKey) { + final ObjectPair<O, T> other = (ObjectPair<O, T>) obj; + boolean result = true; + if (other.object1 != null && object1 != null) { + result &= other.object1.equals(object1); + } else { + result &= other.object1 == null && object1 == null; + } + if (other.object2 != null && object2 != null) { + result &= other.object2.equals(object2); + } else { + result &= other.object2 == null && object2 == null; + } + return result; + } + return false; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 37; + int result = 17; + if (object1 != null) { + result = prime * result + object1.hashCode(); + } else { + result = prime * result; + } + if (object2 != null) { + result = prime * result + object2.hashCode(); + } else { + result = prime * result; + } + return result; + } + + @Override + public String toString() { + return "<" + object1 + ", " + object2 + ">"; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/ObjectTriplet.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/ObjectTriplet.java new file mode 100644 index 00000000000..9857c25d90d --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/ObjectTriplet.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +public class ObjectTriplet<T, U, V> { + public final T object1; + public final U object2; + public final V object3; + + public ObjectTriplet(T object1, U object2, V object3) { + this.object1 = object1; + this.object2 = object2; + this.object3 = object3; + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/Pair.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/Pair.java new file mode 100644 index 00000000000..e346ff01c6a --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/Pair.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +import java.io.Serializable; + +/** + * @author Roberto E. Escobar + */ +public class Pair<T, K> implements Serializable { + private static final long serialVersionUID = 1764353834209869140L; + private T key; + private K value; + + public Pair(T key, K value) { + this.key = key; + this.value = value; + } + + public T getKey() { + return key; + } + + public K getValue() { + return value; + } + + public void setKey(T key) { + this.key = key; + } + + public void setValue(K value) { + this.value = value; + } + + public String toString() { + return String.format("[%s, %s]", key.toString(), value.toString()); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/PropertyStore.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/PropertyStore.java new file mode 100644 index 00000000000..2f64bad7848 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/PropertyStore.java @@ -0,0 +1,188 @@ +/*
+ * Created on Feb 21, 2008
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.framework.jdk.core.type;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Serializable;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import javax.xml.parsers.ParserConfigurationException;
+import org.eclipse.osee.framework.jdk.core.util.Collections;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class PropertyStore implements IPropertyStore, Serializable {
+ private static final long serialVersionUID = 9076969425223251739L;
+
+ private final String EXCEPTION_MESSAGE = "No setting found for key: [%s]";
+
+ private String storeId;
+ private Properties storageData;
+ private Properties storageArrays;
+
+ public PropertyStore(String storeId) {
+ this.storeId = storeId;
+ this.storageData = new Properties();
+ this.storageArrays = new Properties();
+ }
+
+ public PropertyStore(Reader properties) throws IOException, SAXException, ParserConfigurationException {
+ this((String) null);
+ PropertyStoreWriter writer = new PropertyStoreWriter();
+ writer.load(this, properties);
+ }
+
+ public PropertyStore(Properties properties) {
+ this.storageData = properties;
+ this.storeId = Integer.toString(properties.hashCode());
+ }
+
+ public String get(String key) {
+ return (String) storageData.get(key);
+ }
+
+ public String[] getArray(String key) {
+ return (String[]) storageArrays.get(key);
+ }
+
+ public boolean getBoolean(String key) {
+ return Boolean.valueOf((String) storageData.get(key)).booleanValue();
+ }
+
+ public double getDouble(String key) throws NumberFormatException {
+ String setting = (String) storageData.get(key);
+ if (setting == null) {
+ throw new NumberFormatException(String.format(EXCEPTION_MESSAGE, key));
+ }
+
+ return new Double(setting).doubleValue();
+ }
+
+ public float getFloat(String key) throws NumberFormatException {
+ String setting = (String) storageData.get(key);
+ if (setting == null) {
+ throw new NumberFormatException(String.format(EXCEPTION_MESSAGE, key));
+ }
+
+ return new Float(setting).floatValue();
+ }
+
+ public int getInt(String key) throws NumberFormatException {
+ String setting = (String) storageData.get(key);
+ if (setting == null) {
+ throw new NumberFormatException(String.format(EXCEPTION_MESSAGE, key));
+ }
+
+ return new Integer(setting).intValue();
+ }
+
+ public long getLong(String key) throws NumberFormatException {
+ String setting = (String) storageData.get(key);
+ if (setting == null) {
+ throw new NumberFormatException(String.format(EXCEPTION_MESSAGE, key));
+ }
+
+ return new Long(setting).longValue();
+ }
+
+ public void put(String key, String[] value) {
+ if (value == null) {
+ value = new String[0];
+ }
+ storageArrays.put(key, value);
+ }
+
+ public void put(String key, double value) {
+ put(key, String.valueOf(value));
+ }
+
+ public void put(String key, float value) {
+ put(key, String.valueOf(value));
+ }
+
+ public void put(String key, int value) {
+ put(key, String.valueOf(value));
+ }
+
+ public void put(String key, long value) {
+ put(key, String.valueOf(value));
+ }
+
+ public void put(String key, String value) {
+ if (value == null) {
+ value = "";
+ }
+ storageData.put(key, value);
+ }
+
+ public void put(String key, boolean value) {
+ put(key, String.valueOf(value));
+ }
+
+ public String getId() {
+ return storeId;
+ }
+
+ protected void setId(String name) {
+ this.storeId = name;
+ }
+
+ protected Properties getItems() {
+ return storageData;
+ }
+
+ protected Properties getArrays() {
+ return storageArrays;
+ }
+
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append(storageData.toString().replaceAll(",", ",\n"));
+ return builder.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.ote.core.framework.data.IPropertyStore#load(java.lang.String)
+ */
+ public void load(String fileName) throws Exception {
+ InputStream inputStream = new FileInputStream(fileName);
+ PropertyStoreWriter storeWriter = new PropertyStoreWriter();
+ storeWriter.load(this, inputStream);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.ote.core.framework.data.IPropertyStore#save(java.lang.String)
+ */
+ public void save(String fileName) throws Exception {
+ OutputStream outputStream = new FileOutputStream(fileName);
+ PropertyStoreWriter storeWriter = new PropertyStoreWriter();
+ storeWriter.save(this, outputStream);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.jdk.core.type.IPropertyStore#arrayKeySet()
+ */
+ public Set<String> arrayKeySet() {
+ List<String> items = Collections.castAll(this.storageArrays.keySet());
+ return Collections.toSet(items);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.jdk.core.type.IPropertyStore#keySet()
+ */
+ public Set<String> keySet() {
+ List<String> items = Collections.castAll(this.storageData.keySet());
+ return Collections.toSet(items);
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/PropertyStoreWriter.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/PropertyStoreWriter.java new file mode 100644 index 00000000000..efa2c57fba2 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/PropertyStoreWriter.java @@ -0,0 +1,271 @@ +/*
+ * Created on Feb 27, 2008
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.framework.jdk.core.type;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class PropertyStoreWriter {
+ private static final String TAG_SECTION = "store";
+ private static final String TAG_NAME = "id";
+ private static final String TAG_KEY = "key";
+ private static final String TAG_VALUE = "value";
+ private static final String TAG_LIST = "list";
+ private static final String TAG_ITEM = "item";
+
+ public void load(PropertyStore store, Reader reader) throws IOException, SAXException, ParserConfigurationException {
+ Document document = null;
+ try {
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ document = parser.parse(new InputSource(reader));
+
+ //Strip out any comments first
+ Node root = document.getFirstChild();
+ while (root.getNodeType() == Node.COMMENT_NODE) {
+ document.removeChild(root);
+ root = document.getFirstChild();
+ }
+ load(store, document, (Element) root);
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ }
+
+ public void load(PropertyStore store, InputStream inputStream) throws IOException, SAXException, ParserConfigurationException {
+ load(store, new BufferedReader(new InputStreamReader(inputStream, "utf-8")));
+ }
+
+ public void save(PropertyStore store, OutputStream stream) throws IOException {
+ XMLWriter writer = new XMLWriter(stream);
+ internalSave(store, writer);
+ }
+
+ public void save(PropertyStore store, Writer writer) throws IOException {
+ XMLWriter internalWriter = new XMLWriter(writer);
+ internalSave(store, internalWriter);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void load(PropertyStore store, Document document, Element root) {
+ store.setId(root.getAttribute(TAG_NAME));
+ NodeList l = root.getElementsByTagName(TAG_ITEM);
+ for (int i = 0; i < l.getLength(); i++) {
+ Node n = l.item(i);
+ if (root == n.getParentNode()) {
+ String key = ((Element) l.item(i)).getAttribute(TAG_KEY);
+ String value = ((Element) l.item(i)).getAttribute(TAG_VALUE);
+ store.put(key, value);
+ }
+ }
+ l = root.getElementsByTagName(TAG_LIST);
+ for (int i = 0; i < l.getLength(); i++) {
+ Node n = l.item(i);
+ if (root == n.getParentNode()) {
+ Element child = (Element) l.item(i);
+ String key = child.getAttribute(TAG_KEY);
+ NodeList list = child.getElementsByTagName(TAG_ITEM);
+ List valueList = new ArrayList();
+ for (int j = 0; j < list.getLength(); j++) {
+ Element node = (Element) list.item(j);
+ if (child == node.getParentNode()) {
+ valueList.add(node.getAttribute(TAG_VALUE));
+ }
+ }
+ String[] value = new String[valueList.size()];
+ valueList.toArray(value);
+ store.put(key, value);
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void internalSave(PropertyStore store, XMLWriter out) {
+ HashMap attributes = new HashMap(2);
+ String name = store.getId();
+ attributes.put(TAG_NAME, name == null ? "" : name); //$NON-NLS-1$
+ out.startTag(TAG_SECTION, attributes);
+ attributes.clear();
+ Properties items = store.getItems();
+ for (Iterator i = items.keySet().iterator(); i.hasNext();) {
+ String key = (String) i.next();
+ attributes.put(TAG_KEY, key == null ? "" : key); //$NON-NLS-1$
+ String string = (String) items.get(key);
+ attributes.put(TAG_VALUE, string == null ? "" : string); //$NON-NLS-1$
+ out.printTag(TAG_ITEM, attributes, true);
+ }
+
+ attributes.clear();
+ Properties arrayItems = store.getArrays();
+ for (Iterator i = arrayItems.keySet().iterator(); i.hasNext();) {
+ String key = (String) i.next();
+ attributes.put(TAG_KEY, key == null ? "" : key); //$NON-NLS-1$
+ out.startTag(TAG_LIST, attributes);
+ String[] value = (String[]) arrayItems.get(key);
+ attributes.clear();
+ if (value != null) {
+ for (int index = 0; index < value.length; index++) {
+ String string = value[index];
+ attributes.put(TAG_VALUE, string == null ? "" : string); //$NON-NLS-1$
+ out.printTag(TAG_ITEM, attributes, true);
+ }
+ }
+ out.endTag(TAG_LIST);
+ attributes.clear();
+ }
+ out.endTag(TAG_SECTION);
+ out.close();
+ }
+
+ private static class XMLWriter extends PrintWriter {
+ /** current number of tabs to use for ident */
+ protected int tab;
+
+ /** the xml header */
+ protected static final String XML_VERSION = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; //$NON-NLS-1$
+
+ public XMLWriter(Writer writer) {
+ super(writer);
+ tab = 0;
+ println(XML_VERSION);
+ }
+
+ public XMLWriter(OutputStream output) throws UnsupportedEncodingException {
+ this(new OutputStreamWriter(output, "UTF8")); //$NON-NLS-1$
+ }
+
+ /**
+ * write the intended end tag
+ *
+ * @param name the name of the tag to end
+ */
+ public void endTag(String name) {
+ tab--;
+ printTag("/" + name, null, false); //$NON-NLS-1$
+ }
+
+ private void printTabulation() {
+ for (int i = 0; i < tab; i++) {
+ super.print('\t');
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void printTag(String name, HashMap parameters, boolean close) {
+ printTag(name, parameters, true, true, close);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void printTag(String name, HashMap parameters, boolean shouldTab, boolean newLine, boolean close) {
+ StringBuffer sb = new StringBuffer();
+ sb.append('<');
+ sb.append(name);
+ if (parameters != null) {
+ for (Enumeration e = Collections.enumeration(parameters.keySet()); e.hasMoreElements();) {
+ sb.append(" "); //$NON-NLS-1$
+ String key = (String) e.nextElement();
+ sb.append(key);
+ sb.append("=\""); //$NON-NLS-1$
+ sb.append(getEscaped(String.valueOf(parameters.get(key))));
+ sb.append("\""); //$NON-NLS-1$
+ }
+ }
+ if (close) {
+ sb.append('/');
+ }
+ sb.append('>');
+ if (shouldTab) {
+ printTabulation();
+ }
+ if (newLine) {
+ println(sb.toString());
+ } else {
+ print(sb.toString());
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void startTag(String name, HashMap parameters) {
+ startTag(name, parameters, true);
+ tab++;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void startTag(String name, HashMap parameters, boolean newLine) {
+ printTag(name, parameters, true, newLine, false);
+ }
+
+ private static void appendEscapedChar(StringBuffer buffer, char c) {
+ String replacement = getReplacement(c);
+ if (replacement != null) {
+ buffer.append('&');
+ buffer.append(replacement);
+ buffer.append(';');
+ } else {
+ buffer.append(c);
+ }
+ }
+
+ private static String getEscaped(String s) {
+ StringBuffer result = new StringBuffer(s.length() + 10);
+ for (int i = 0; i < s.length(); ++i) {
+ appendEscapedChar(result, s.charAt(i));
+ }
+ return result.toString();
+ }
+
+ private static String getReplacement(char c) {
+ // Encode special XML characters into the equivalent character references.
+ // The first five are defined by default for all XML documents.
+ // The next three (#xD, #xA, #x9) are encoded to avoid them
+ // being converted to spaces on deserialization
+ switch (c) {
+ case '<':
+ return "lt"; //$NON-NLS-1$
+ case '>':
+ return "gt"; //$NON-NLS-1$
+ case '"':
+ return "quot"; //$NON-NLS-1$
+ case '\'':
+ return "apos"; //$NON-NLS-1$
+ case '&':
+ return "amp"; //$NON-NLS-1$
+ case '\r':
+ return "#x0D"; //$NON-NLS-1$
+ case '\n':
+ return "#x0A"; //$NON-NLS-1$
+ case '\u0009':
+ return "#x09"; //$NON-NLS-1$
+ }
+ return null;
+ }
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/SimpleEnum.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/SimpleEnum.java new file mode 100644 index 00000000000..7d3a4740c70 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/SimpleEnum.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +/** + * @author Donald G. Dunne + */ +public abstract class SimpleEnum { + + public final transient int value; + public final String name; + + protected SimpleEnum(int value, String name) { + this.value = value; + this.name = name; + } + + public final String toString() { + return name; + } + + public final boolean equals(Object obj) { + return super.equals(obj); + } + + public final int hashCode() { + return value; + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/TreeObject.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/TreeObject.java new file mode 100644 index 00000000000..a489fbaa80c --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/TreeObject.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +/** + * @author Roberto E. Escobar + */ +public class TreeObject { + private String name; + private TreeParent parent; + private boolean isCurrent; + private boolean isChecked; + + public TreeObject(String name) { + this.name = name; + } + + public TreeObject() { + this(""); + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setParent(TreeParent parent) { + this.parent = parent; + } + + public TreeParent getParent() { + return parent; + } + + public String toString() { + return getName(); + } + + public boolean isCurrent() { + return isCurrent; + } + + public void setCurrent(boolean isCurrent) { + this.isCurrent = isCurrent; + } + + public boolean isChecked() { + return isChecked; + } + + public void setChecked(boolean isChecked) { + this.isChecked = isChecked; + } + + public Object getAdapter(Class<?> adapter) { + return null; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/TreeParent.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/TreeParent.java new file mode 100644 index 00000000000..e6c82a4446f --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/TreeParent.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.type; + +import java.util.ArrayList; + +/** + * @author Roberto E. Escobar + */ +public class TreeParent extends TreeObject { + private ArrayList<TreeObject> children; + + public TreeParent(String name) { + super(name); + children = new ArrayList<TreeObject>(); + } + + public TreeParent() { + this(""); + } + + public void addChild(TreeObject child) { + children.add(child); + child.setParent(this); + } + + public void removeChild(TreeObject child) { + children.remove(child); + child.setParent(null); + } + + public TreeObject[] getChildren() { + return (TreeObject[]) children.toArray(new TreeObject[children.size()]); + } + + public boolean hasChildren() { + return children.size() > 0; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/VariantData.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/VariantData.java new file mode 100644 index 00000000000..61eb769cb5d --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/VariantData.java @@ -0,0 +1,185 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.osee.framework.jdk.core.type;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class VariantData implements IVariantData {
+ private static final long serialVersionUID = 9076969425223251739L;
+
+ private final String EXCEPTION_MESSAGE = "No setting found for key: [%s]";
+ private final String CONVERSION_EXCEPTION_MESSAGE = "Unable to convert [%s] from [%s] to [%s]";
+
+ private final Properties storageData;
+ private final Properties storageArrays;
+ private final Map<String, byte[]> byteArrayData;
+
+ public VariantData() {
+ this.byteArrayData = new HashMap<String, byte[]>();
+ this.storageData = new Properties();
+ this.storageArrays = new Properties();
+ }
+
+ public String get(String key) {
+ return (String) storageData.get(key);
+ }
+
+ public boolean isEmpty(String key) {
+ if (get(key) == null) return true;
+ return get(key).equals("");
+ }
+
+ public String[] getArray(String key) {
+ return (String[]) storageArrays.get(key);
+ }
+
+ public boolean getBoolean(String key) {
+ return Boolean.valueOf((String) storageData.get(key)).booleanValue();
+ }
+
+ public double getDouble(String key) throws NumberFormatException {
+ String setting = (String) storageData.get(key);
+ if (setting == null) {
+ throw new NumberFormatException(String.format(EXCEPTION_MESSAGE, key));
+ }
+
+ return new Double(setting).doubleValue();
+ }
+
+ public float getFloat(String key) throws NumberFormatException {
+ String setting = (String) storageData.get(key);
+ if (setting == null) {
+ throw new NumberFormatException(String.format(EXCEPTION_MESSAGE, key));
+ }
+
+ return new Float(setting).floatValue();
+ }
+
+ public int getInt(String key) throws NumberFormatException {
+ String setting = (String) storageData.get(key);
+ if (setting == null) {
+ throw new NumberFormatException(String.format(EXCEPTION_MESSAGE, key));
+ }
+
+ return new Integer(setting).intValue();
+ }
+
+ public long getLong(String key) throws NumberFormatException {
+ String setting = (String) storageData.get(key);
+ if (setting == null) {
+ throw new NumberFormatException(String.format(EXCEPTION_MESSAGE, key));
+ }
+ return new Long(setting).longValue();
+ }
+
+ public Date getDate(String key) throws IllegalArgumentException {
+ String setting = (String) storageData.get(key);
+ if (setting == null) {
+ throw new IllegalArgumentException(String.format(EXCEPTION_MESSAGE, key));
+ }
+ return new Date(new Long(setting).longValue());
+ }
+
+ public String getStreamAsString(String key) throws Exception {
+ String toReturn;
+ InputStream inputStream = getStream(key);
+ try {
+ toReturn = Lib.inputStreamToString(inputStream);
+ } catch (IOException ex) {
+ throw new IOException(String.format(CONVERSION_EXCEPTION_MESSAGE, key, "byte[]", "String"));
+ }
+ return toReturn;
+ }
+
+ public InputStream getStream(String key) throws IllegalArgumentException {
+ byte[] bytes = byteArrayData.get(key);
+ if (bytes == null) {
+ throw new IllegalArgumentException(String.format(EXCEPTION_MESSAGE, key));
+ }
+ return new ByteArrayInputStream(bytes);
+ }
+
+ public void put(String key, String[] value) {
+ if (value == null) {
+ value = new String[0];
+ }
+ storageArrays.put(key, value);
+ }
+
+ public void put(String key, double value) {
+ put(key, String.valueOf(value));
+ }
+
+ public void put(String key, float value) {
+ put(key, String.valueOf(value));
+ }
+
+ public void put(String key, int value) {
+ put(key, String.valueOf(value));
+ }
+
+ public void put(String key, long value) {
+ put(key, String.valueOf(value));
+ }
+
+ public void put(String key, boolean value) {
+ put(key, String.valueOf(value));
+ }
+
+ public void put(String key, Date date) {
+ if (date != null) {
+ put(key, date.getTime());
+ }
+ }
+
+ public void put(String key, String value) {
+ if (value == null) {
+ value = "";
+ }
+ storageData.put(key, value);
+ }
+
+ public void put(String key, byte[] bytes) {
+ if (bytes == null) {
+ bytes = new byte[0];
+ }
+ byteArrayData.put(key, bytes);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append(storageData.toString().replaceAll(",", ",\n"));
+ builder.append(storageArrays.toString().replaceAll(",", ",\n"));
+ for (String key : byteArrayData.keySet()) {
+ builder.append(key);
+ builder.append("=");
+ try {
+ builder.append(getStreamAsString(key));
+ } catch (Exception ex) {
+ builder.append("!!Error!!");
+ }
+ builder.append(",\n");
+ }
+ return builder.toString();
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/AFile.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/AFile.java new file mode 100644 index 00000000000..01a6c3c8bb4 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/AFile.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +import java.io.File; +import java.io.IOException; + +/** + * @author Donald G. Dunne + */ +public class AFile { + + public static String justFilename(String filename) { + File file = new File(filename); + return file.getName(); + } + + public static String justPath(String filename) { + File file = new File(filename); + filename = filename.replaceAll(file.getName(), ""); + return filename; + } + + /** + * Use the Lib method directly - the original implementation of this method was not memory efficient and suppressed + * exceptions + * + * @param stream + * @return + */ + public static String readFile(String filename) { + return readFile(new File(filename)); + } + + /** + * Use the Lib method directly - the original implementation of this method was not memory efficient and suppressed + * exceptions + * + * @param stream + * @return + */ + public static String readFile(File file) { + try { + return Lib.fileToString(file); + } catch (IOException ex) { + ex.printStackTrace(); + return null; + } + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/AHTML.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/AHTML.java new file mode 100644 index 00000000000..bf763fa5e87 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/AHTML.java @@ -0,0 +1,469 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ + +package org.eclipse.osee.framework.jdk.core.util; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.net.URL; +import java.net.URLConnection; +import java.util.Collection; +import java.util.List; + +/** + * @author Michael A. Winston + */ +public class AHTML { + private static final String HTTP_CHARSET_ENCODING = + "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">"; + private static final String begin = "<table "; + public final static String LABEL_FONT = "<font color=\"black\" face=\"Arial\" size=\"-1\">"; + + public static String getHyperlink(String url, String name) { + return String.format("<a href=\"%s\">%s</a>", url, name); + } + + public static String textToHtml(String text) { + if (text == null) { + return ""; + } + text = text.replaceAll("&", "&"); + text = text.replaceAll(">", ">"); + text = text.replaceAll("<", "<"); + text = text.replaceAll("\"", """); + text = text.replaceAll("\\n", "<br/>"); + text = text.replaceAll("\t", " "); + text = text.replaceAll("[\\x0B\\f\\r]+", ""); + return text; + } + + public static String htmlToText(String html) { + if (html == null) { + return ""; + } + html = html.replaceAll("&", "&"); + html = html.replaceAll(">", ">"); + html = html.replaceAll("<", "<"); + html = html.replaceAll(""", "\""); + html = html.replaceAll(" ", " "); + return html; + } + + public static String getUrlPageHtml(String urlStr, InetSocketAddress addr) { + StringBuffer buffer = new StringBuffer(); + try { + URL url = new URL(urlStr); + URLConnection connection = url.openConnection(new Proxy(Proxy.Type.HTTP, addr)); + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String line = null; + while ((line = rd.readLine()) != null) { + buffer.append(line); + } + rd.close(); + return buffer.toString(); + } catch (Exception ex) { + ex.printStackTrace(); + return simplePage("Exception opening url " + ex.getLocalizedMessage()); + } + } + + public static String titledPage(String title, String text) { + return simplePage("<head><title>" + title + "</title></head>" + text); + } + + public static String pageEncoding(String html) { + return HTTP_CHARSET_ENCODING + html; + } + + public static String simplePage(String text) { + return pageEncoding("<html>" + text + "</html>"); + } + + public static String simplePageNoPageEncoding(String text) { + return "<html>" + text + "</html>"; + } + + public static String getLabelStr(String labelFont, String str) { + return labelFont + "<b>" + textToHtml(str) + "</b></font>"; + } + + public static String getLabelValueStr(String labelFont, String label, String value) { + return getLabelStr(labelFont, label) + value; + } + + public static String getLabelValueStr(String label, String value) { + return getLabelStr(LABEL_FONT, label + ":") + " " + value; + } + + public static String color(String color, String str) { + return "<font color=\"" + color + "\">" + str + "</font>"; + } + + public static String boldColor(String color, String str) { + return "<font color=\"" + color + "\"><b>" + textToHtml(str) + "</b></font>"; + } + + public static String bold(String str) { + return "<b>" + textToHtml(str) + "</b>"; + } + + public static String boldColorTags(String color, String str) { + return "<font color=\"" + color + "\"><b>" + str + "</b></font>"; + } + + public static String imageBlock(String description, String filename) { + String filenames[] = new String[1]; + filenames[0] = filename; + return imageBlock(description, filenames); + } + + public static String imageBlock(String description, String filenames[]) { + String str = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>"; + if (!description.equals("")) { + str += description; + str += AHTML.newline(); + } + for (int i = 0; i < filenames.length; i++) { + str += "<IMG SRC=\"" + filenames[i] + "\"><br>"; + } + str += "</td></tr></table>"; + return str; + } + + public static String urlBlock(String description, String urls[]) { + String str = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"; + if (!description.equals("")) { + str += description; + str += AHTML.newline(); + } + for (int i = 0; i < urls.length; i++) { + str += "<A HREF=\"" + urls[i] + "\">" + urls[i] + "</A><br>"; + } + str += "</td></tr></table>"; + return str; + } + + public static String heading(int heading, String str, String id) { + return "<h" + heading + (id != null && !id.equals("") ? " id=\"" + id + "\"" : "") + ">" + textToHtml(str) + "</h" + heading + ">"; + } + + public static String heading(int heading, String str) { + return heading(heading, str, null); + } + + public static String padSpace(int num, String str) { + String out = ""; + for (int i = 0; i < num; i++) { + out += " "; + } + out += str; + return out; + } + + public static String addSpace(int num) { + String out = ""; + for (int i = 0; i < num; i++) { + out += " "; + } + return out; + } + + public static String para(String str) { + return "<p>" + textToHtml(str) + "</p>"; + } + + public static String italics(String str) { + return "<i>" + textToHtml(str) + "</i>"; + } + + public static String pre(String str) { + return "<pre>" + str + "</pre>"; + } + + public static String newline() { + return newline(1); + } + + public static String newline(int num) { + String str = ""; + for (int i = 0; i < num; i++) { + str += "<br>"; + } + return str + ""; + } + + public static String name(int num) { + return nameTarget("" + num); + } + + /** + * Create target for hyperlink to jump to + * + * @param str + * @return Return name target string + */ + public static String nameTarget(String str) { + if (str == null) { + return ""; + } + return "<A NAME=\"" + str + "\">"; + } + + /** + * Create <a href> hyperlink to nameTarget + * + * @param num + * @param text + * @return Return name link string + */ + public static String nameLink(int num, String text) { + return nameLink("" + num, text); + } + + /** + * Create <a href> hyperlink to nameTarget + * + * @param name + * @param text + * @return Return name link string + */ + public static String nameLink(String name, String text) { + return "<A HREF=\"#" + name + "\">" + text + "</A>"; + } + + /** + * Create <a href> hyperlink to nameTarget using name as hyperlink tag and display text + * + * @param name + * @return Return name link string + */ + public static String nameLink(String name) { + return "<A HREF=\"#" + name + "\">" + name + "</A>"; + } + + public static String simpleTable(String str) { + return simpleTable(str, 100); + } + + /** + * Create a table with one row/colum containing str + * + * @param str + * @param width + * @return return simple table string + */ + public static String simpleTable(String str, int width) { + return new String( + "<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" width=\"" + width + "%\">" + "<tr><td>" + str + "</td></tr>" + "</table>"); + } + + /** + * Create a table with one row/colum containing str + * + * @param str + * @param width + * @param bgcolor + * @return Return border table string + */ + public static String borderTable(String str, int width, String bgcolor, String caption) { + return startBorderTable(width, bgcolor, caption) + str + endBorderTable(); + } + + public static String startBorderTable(int width, String bgcolor, String caption) { + String capStr = ""; + if (!caption.equals("")) capStr = "<caption ALIGN=top>" + caption + "</caption>"; + return "<table border=\"1\" align=\"center\" bgcolor=\"" + bgcolor + "\" cellpadding=\"3\" cellspacing=\"0\" width=\"" + width + "%\">" + capStr + "<tr><td>"; + } + + public static String endBorderTable() { + return "</td></tr></table>"; + } + + /** + * Create a table with one row multi column containing str[] + * + * @param str = array of strings for columns + * @return Return multi-column table string + */ + public static String multiColumnTable(String[] str) { + return multiColumnTable(str, 85); + } + + /** + * Create a table with one row multi column containing str[] + * + * @param str - array of strings for columns + * @param width - percent (1..100) of screen for table + * @return Return multi-column table string + */ + public static String multiColumnTable(String[] str, int width) { + String s = "<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" width=\"" + width + "%\"><tr>"; + for (int i = 0; i < str.length; i++) { + s += "<td>" + str[i] + "</td>"; + } + s += "</tr></table>"; + return s; + } + + public static String beginMultiColumnTable(int width) { + return beginMultiColumnTable(width, 0); + } + + public static String beginMultiColumnTable(int width, int border) { + return beginMultiColumnTable(width, border, null); + } + + public static String beginMultiColumnTable(int width, int border, Integer color) { + return "<table border=\"" + border + "\" " + (color != null ? "color=\"" + color + "\"" : "") + " cellpadding=\"3\" cellspacing=\"0\" width=\"" + width + "%\">"; + } + + public static String endMultiColumnTable() { + return "</table>"; + } + + public static String addRowMultiColumnTable(String... str) { + return addRowMultiColumnTable(str, null, null); + } + + public static String addRowMultiColumnTable(String[] str, String[] colOptions) { + return addRowMultiColumnTable(str, colOptions, null); + } + + public static String addRowMultiColumnTable(String[] str, String[] colOptions, String backgroundColor) { + String s = "<tr>"; + if (backgroundColor != null) s = "<tr bgcolor=\"" + backgroundColor + "\">"; + String show = ""; + for (int i = 0; i < str.length; i++) { + show = str[i]; + if (show == null || show.equals("")) show = AHTML.addSpace(1); + String colOptionStr = ""; + if (colOptions != null) colOptionStr = colOptions[i]; + s += "<td" + ((colOptionStr != null && !colOptionStr.equals("")) ? colOptionStr : "") + ">" + show + "</td>"; + } + s += "</tr>"; + return s; + } + + public static String addRowSpanMultiColumnTable(String str, int span) { + return "<tr><td colspan=" + span + ">" + str + "</td></tr>"; + } + + public static class CellItem { + String text; + private final String fgColor; + private final String bgColor; + + public CellItem(String text) { + this(text, null, null); + } + + public CellItem(String text, String fgColor, String bgColor) { + this.text = text; + this.fgColor = fgColor; + this.bgColor = bgColor; + } + } + + public static String addRowMultiColumnTable(Collection<CellItem> items) { + String s = "<tr>"; + for (CellItem item : items) { + if (item.text == null || item.text.equals("")) item.text = "."; + if (item.fgColor != null && item.bgColor != null) + s += "<td bgcolor=\"" + item.bgColor + "\">" + AHTML.color(item.fgColor, item.text) + "</td>"; + else if (item.bgColor != null) + s += "<td bgcolor=\"" + item.bgColor + "\">" + item.text + "</td>"; + else if (item.fgColor != null) + s += "<td>" + AHTML.color(item.fgColor, item.text) + "</td>"; + else + s += "<td>" + item.text + "</td>"; + } + s += "</tr>"; + return s; + } + + public static String addHeaderRowMultiColumnTable(String[] str) { + return addHeaderRowMultiColumnTable(str, null); + } + + public static String addHeaderRowMultiColumnTable(String[] str, Integer width[]) { + String s = "<tr>"; + String widthStr = ""; + for (int i = 0; i < str.length; i++) { + if (width != null) widthStr = " width =\"" + width[i] + "\""; + s += "<th" + widthStr + ">" + str[i] + "</th>"; + } + s += "</tr>"; + return s; + } + + public static String addSimpleTableRow(String str) { + String s = "<tr><td>" + str + "</td></tr>"; + return s; + } + + public static String beginSimpleTable() { + return new String("<table border=\"0\" cellpadding=\"10\" cellspacing=\"0\" width=\"100%\">"); + } + + public static String beginSimpleTable(int border, int width) { + return new String("<table border=\"" + border + "\" cellpadding=\"10\" cellspacing=\"0\" width=\"+width+%\">"); + } + + public static String endSimpleTable() { + return new String("</table>"); + } + + public static String createTable(List<String> datas, String[] headers, int numColumns, int cellPadding, int border) { + StringBuilder table = new StringBuilder(begin); + + if (datas == null) { + throw new IllegalArgumentException("The data can not be null"); + } + if (datas.size() % numColumns != 0) { + throw new IllegalArgumentException( + "The table could not be created becuase the data does not match the column size"); + } + if (border > 0) { + table.append("border=\"" + border + "\""); + } + if (cellPadding > 0) { + table.append("cellpadding=\"" + cellPadding + "\""); + } + table.append(">"); + + if (headers != null && headers.length == numColumns) { + table.append("<tr>"); + for (String header : headers) { + table.append("<th>" + header + "</th>"); + } + table.append("</tr>"); + } + + int colIndex = 0; + for (String data : datas) { + + if (colIndex == 0) { + table.append("<tr>"); + } + table.append("<td>" + data + "</td>"); + colIndex++; + + if (colIndex == numColumns) { + table.append("</tr>"); + colIndex = 0; + } + } + return table.toString(); + } + +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/AXml.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/AXml.java new file mode 100644 index 00000000000..fca42216f93 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/AXml.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +import java.util.Vector; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author Donald G. Dunne + */ +public class AXml { + + public static String getRootTag(String xmlStr) { + Matcher m; + m = Pattern.compile("^[\r\n \t]*<.*?>[\r\n \t]*<(.*?)>", Pattern.MULTILINE | Pattern.DOTALL).matcher(xmlStr); + if (m.find()) { + return m.group(1); + } + return ""; + } + + /** + * Returns <elementName>data</elementName> NOTE: data is not sent through AXml.textToXml + * + * @param elementName + * @param data + * @return String <elementName>data</elementName> + */ + public static String addTagData(String elementName, String data) { + return addTagData(elementName, data, false); + } + + public static String addTagData(String elementName, String data, boolean newLine) { + String str = "<" + elementName + ">" + data + "</" + elementName + ">"; + if (newLine) + return str + "\n"; + else + return str; + } + + /** + * Parse <xmlRoot name="this.is.name" value="this.is.value"> and return name, value + * + * @param xmlRoot xml tag name + * @param xmlStr string containing xml + * @return String[]{name, value} + */ + public static String[] getNameValue(String xmlRoot, String xmlStr) { + String[] strs = new String[] {"", ""}; + Matcher m; + m = + Pattern.compile("<" + xmlRoot + " name=\"(.*?)\" value=\"(.*?)\" />", Pattern.MULTILINE | Pattern.DOTALL).matcher( + xmlStr); + if (m.find()) { + strs[0] = m.group(1); + strs[1] = m.group(2); + } + return strs; + } + + public static String getNameValueXml(String xmlRoot, String name, String value) { + return String.format("<%s name=\"%s\" value=\"%s\"/>", xmlRoot, name, value); + } + + public static String[] getTagDataArray(String xmlStr, String xmlRoot) { + Vector<String> v = new Vector<String>(); + Matcher m; + m = + Pattern.compile("<" + xmlRoot + ">(.*?)</" + xmlRoot + ">", Pattern.MULTILINE | Pattern.DOTALL).matcher( + xmlStr); + while (m.find()) { + v.add(xmlToText(m.group(1))); + } + return v.toArray(new String[v.size()]); + } + + /** + * Returns data between <xmlRoot> and </xmlRoot> from xmlStr + * + * @param xmlStr + * @param xmlRoot + * @return Return tag string + */ + public static String getTagData(String xmlStr, String xmlRoot) { + String tags[] = getTagDataArray(xmlStr, xmlRoot); + if (tags.length > 0) { + return tags[0]; + } + return ""; + } + + public static int getTagIntData(String xmlStr, String xmlRoot) { + String tags[] = getTagDataArray(xmlStr, xmlRoot); + if (tags.length > 0) { + String intStr = tags[0]; + return (new Integer(intStr)).intValue(); + } + return 0; + } + + public static Boolean getTagBooleanData(String xmlStr, String xmlRoot) { + String tags[] = getTagDataArray(xmlStr, xmlRoot); + if (tags.length > 0) { + String intStr = tags[0]; + return (intStr.equals("true") ? true : false); + } + return false; + } + + /** + * Given text strings containing xml reserved characters, replace with valid xml representation characters > => & gt; + * < => & lt; & => & amp; ' => & apos; " => & quot; + * + * @param text text to be converted to valid XML representation characters + * @return String valid xml string + */ + public static String textToXml(String text) { + if (text == null || text.equals("")) return ""; + String str = new String(text); + str = str.replaceAll("&", "&"); + str = str.replaceAll(">", ">"); + str = str.replaceAll("<", "<"); + str = str.replaceAll("'", "'"); + str = str.replaceAll("\"", """); + return str; + } + + /** + * Given xml strings containing xml reserved characters, replace with displayable characters > <= & gt; < <= & lt; & + * <= & amp; ' <= & apos; " <= & quot; + * + * @param xml + * @return displayable string + */ + public static String xmlToText(String xml) { + if (xml == null || xml.equals("")) return ""; + String str = new String(xml); + str = str.replaceAll(">", ">"); + str = str.replaceAll("<", "<"); + str = str.replaceAll("'", "'"); + str = str.replaceAll(""", "\""); + str = str.replaceAll("&", "&"); + return str; + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/ByteUtil.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/ByteUtil.java new file mode 100644 index 00000000000..60fed31feb1 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/ByteUtil.java @@ -0,0 +1,197 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +import java.io.PrintStream; +import java.nio.ByteBuffer; + +/** + * @author Ryan D. Brooks + * @author Andrew M. Finkbeiner + */ +public class ByteUtil { + + public static void printBinary(byte[] data, int bytesPerGroup, int groupPerLine, PrintStream out) { + int groups = 0; + for (int i = 0; i < data.length; i++) { + out.print(ByteUtil.toBinaryString(data[i])); + if ((i + 1) % bytesPerGroup == 0) { + out.print(" "); + groups++; + if ((groups) % groupPerLine == 0) { + out.println(); + } + } + } + } + + public static void printHex(byte[] data, int bytesPerGroup, int groupPerLine, PrintStream out) { + int groups = 0; + for (int i = 0; i < data.length; i++) { + out.print(ByteUtil.toHexString(data[i])); + if ((i + 1) % bytesPerGroup == 0) { + out.print(" "); + groups++; + if ((groups) % groupPerLine == 0) { + out.println(); + } + } + } + } + + public static void printHex(byte[] data, int bytesPerGroup, int groupPerLine, StringBuilder strBuilder) { + int groups = 0; + for (int i = 0; i < data.length; i++) { + strBuilder.append(ByteUtil.toHexString(data[i])); + if ((i + 1) % bytesPerGroup == 0) { + strBuilder.append(" "); + groups++; + } + } + } + + public static void printHex(byte[] data, int bytesPerGroup, int groupPerLine, boolean isSpaced, StringBuilder strBuilder) { + int groups = 0; + for (int i = 0; i < data.length; i++) { + strBuilder.append(ByteUtil.toHexString(data[i])); + if ((i + 1) % bytesPerGroup == 0 && isSpaced) { + strBuilder.append(" "); + groups++; + } + } + } + + /** + * NOTE the SDK supplies a Integer.toBinaryString but it is not formatted to a standard number of chars so it was not + * a good option. + * + * @param b + * @return String + */ + public static String toBinaryString(byte b) { + StringBuffer sb = new StringBuffer(); + sb.append(((b >> 7) & 0x01)); + sb.append(((b >> 6) & 0x01)); + sb.append(((b >> 5) & 0x01)); + sb.append(((b >> 4) & 0x01)); + sb.append(((b >> 3) & 0x01)); + sb.append(((b >> 2) & 0x01)); + sb.append(((b >> 1) & 0x01)); + sb.append((b & 0x01)); + return sb.toString(); + } + + public static byte[] toBytes(long n) { + byte[] bytes = new byte[8]; + toBytes(bytes, 0, n); + return bytes; + } + + public static void toBytes(byte[] bytes, int startPos, long n) { + for (int i = startPos + 7; i >= startPos; i--) { + bytes[i] = (byte) (n); + n >>>= 8; + } + } + + public static void toBytes(byte[] bytes, int startPos, int n) { + for (int i = startPos + 3; i >= startPos; i--) { + bytes[i] = (byte) (n); + n >>>= 8; + } + } + + public static String toHexString(byte b) { + String temp = Integer.toHexString(b); + if (temp.length() >= 2) + return temp.substring(temp.length() - 2).toUpperCase(); + else + return "0" + temp.substring(0).toUpperCase(); + } + + /** + * Build a long from first 8 bytes of the array. + * + * @param b The byte[] to convert. + * @return A long. + */ + public static long toLong(byte[] b) { + if (b.length != 8) { + throw new IllegalArgumentException(); + } + + return ((((long) b[7]) & 0xFF) + ((((long) b[6]) & 0xFF) << 8) + ((((long) b[5]) & 0xFF) << 16) + ((((long) b[4]) & 0xFF) << 24) + ((((long) b[3]) & 0xFF) << 32) + ((((long) b[2]) & 0xFF) << 40) + ((((long) b[1]) & 0xFF) << 48) + ((((long) b[0]) & 0xFF) << 56)); + } + + /** + * + */ + public ByteUtil() { + super(); + } + + /** + * writes message data to a buffer in hex format + * + * @param data + * @param offset + */ + public static void printByteDump(StringBuilder strBuilder, byte[] data, int offset, int length, int columnNum) { + printByteDump(strBuilder, data, offset, length, columnNum, true); + } + + /** + * writes message data to a buffer in hex format + * + * @param data + * @param offset + */ + public static void printByteDump(StringBuilder strBuilder, byte[] data, int offset, int length, int columnNum, boolean hex) { + int columnCount = 0; + final int endIndex = offset + length; + for (int i = offset; i < endIndex; i++) { + if (columnCount == columnNum) { + strBuilder.append('\n'); + columnCount = 0; + } + if (hex) { + strBuilder.append(String.format("%02x ", data[i])); + } else { + + strBuilder.append(data[i]).append(' '); + } + columnCount++; + } + strBuilder.append('\n'); + } + + public static void printByteDump(StringBuilder strBuilder, ByteBuffer data, int offset, int length, int columnNum) { + int currentPosition = data.position(); + // data.position(offset); + int columnCount = 0; + final int endIndex = offset + length; + for (int i = offset; i < endIndex; i++) { + if (columnCount == columnNum) { + strBuilder.append('\n'); + columnCount = 0; + } + strBuilder.append(String.format("%02x ", data.get(i))); + columnCount++; + } + strBuilder.append('\n'); + + data.position(currentPosition); + } + + public static void main(String[] args) { + System.out.println(ByteUtil.toHexString((byte) 128)); + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/ChecksumUtil.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/ChecksumUtil.java new file mode 100644 index 00000000000..3eb8e5c6046 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/ChecksumUtil.java @@ -0,0 +1,51 @@ +/*
+ * Created on May 22, 2008
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.framework.jdk.core.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+public class ChecksumUtil {
+
+ public static final String MD5 = "MD5";
+ public static final String SHA = "SHA";
+
+ private static final byte[] HEX_CHAR_TABLE =
+ {(byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7', (byte) '8',
+ (byte) '9', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f'};
+
+ private ChecksumUtil() {
+ }
+
+ private static String getHexString(byte[] rawData) throws UnsupportedEncodingException {
+ byte[] hex = new byte[2 * rawData.length];
+ int index = 0;
+
+ for (byte b : rawData) {
+ int v = b & 0xFF;
+ hex[index++] = HEX_CHAR_TABLE[v >>> 4];
+ hex[index++] = HEX_CHAR_TABLE[v & 0xF];
+ }
+ return new String(hex, "ASCII");
+ }
+
+ public static String createChecksumAsString(InputStream inputStream, String algorithm) throws Exception {
+ return getHexString(createChecksum(inputStream, algorithm));
+ }
+
+ public static byte[] createChecksum(InputStream inputStream, String algorithm) throws IOException, NoSuchAlgorithmException {
+ MessageDigest checksum = MessageDigest.getInstance(algorithm);
+ byte[] buffer = new byte[1024];
+ int numRead = -1;
+ while ((numRead = inputStream.read(buffer)) != -1) {
+ checksum.update(buffer, 0, numRead);
+ }
+ return checksum.digest();
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/CmdLineArgs.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/CmdLineArgs.java new file mode 100644 index 00000000000..3b73e2ffaf0 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/CmdLineArgs.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +import java.util.HashMap; + +public class CmdLineArgs { + + private HashMap<String, String> cmdArgs; + + public CmdLineArgs(String[] args) { + cmdArgs = new HashMap<String, String>(); + + for (int i = 0; i < args.length; i++) { + if (args[i].matches("-\\w.*")) { + if ((i + 1 < args.length) && (!args[i + 1].matches("-\\D.*"))) { + cmdArgs.put(args[i], args[i + 1]); + i++; + } else { + cmdArgs.put(args[i], null); + } + } else { + cmdArgs.put(args[i], null); + } + } + } + + public String get(String key) { + return cmdArgs.get(key); + } + + public HashMap<String, String> getArgs() { + return cmdArgs; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Collections.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Collections.java new file mode 100644 index 00000000000..d6236800106 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Collections.java @@ -0,0 +1,266 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +/** + * @author David Diepenbrock + */ +public class Collections { + + public static Collection<String> fromString(String string, String seperator) { + return Arrays.asList(string.split(seperator)); + } + + /** + * An flexible alternative for converting a Collection to a String. + * + * @param c The Collection to convert to a String + * @param start The String to place at the beginning of the returned String + * @param separator The String to place in between elements of the Collection c. + * @param end The String to place at the end of the returned String + * @return A String which starts with 'start', followed by the elements in the Collection c separated by 'separator', + * ending with 'end'. + */ + @SuppressWarnings("unchecked") + public static String toString(Collection c, String start, String separator, String end) { + Iterator i = c.iterator(); + StringBuilder myString = new StringBuilder(); + + if (start != null) myString.append(start); + + boolean first = true; + while (i.hasNext()) { + if (!first) myString.append(separator); + myString.append(i.next().toString()); + first = false; + } + + if (end != null) myString.append(end); + + return myString.toString(); + } + + public static String toString(String separator, Object... objects) { + Collection<Object> objectsCol = new ArrayList<Object>(objects.length); + for (Object obj : objects) + objectsCol.add(obj); + return toString(objectsCol, null, separator, null); + } + + @SuppressWarnings("unchecked") + public static String toString(String separator, Collection c) { + return toString(c, null, separator, null); + } + + /** + * The resultant set is those elements in superSet which are not in the subSet + * + * @param superSet + * @param subList + * @return Return complement list reference + */ + public static <T> List<T> setComplement(Collection<T> superSet, Collection<T> subList) { + ArrayList<T> complement = new ArrayList<T>(superSet.size()); + for (T obj : superSet) { + if (!subList.contains(obj)) { + complement.add(obj); + } + } + return complement; + } + + /** + * @param listA + * @param listB + * @return The intersection of two sets A and B is the set of elements common to A and B + */ + public static <T> ArrayList<T> setIntersection(Collection<T> listA, Collection<T> listB) { + ArrayList<T> intersection = new ArrayList<T>(listA.size()); + + for (T obj : listA) { + if (listB.contains(obj)) { + intersection.add(obj); + } + } + return intersection; + } + + /** + * Returns the unique union of the given lists + * + * @param <T> + * @param lists + * @return Set + */ + public static <T> Set<T> setUnion(Collection<T>... lists) { + Set<T> union = new HashSet<T>(lists[0].size() * 2); + + for (int x = 0; x < lists.length; x++) { + union.addAll(lists[x]); + } + return union; + } + + /** + * Return true if same objects exist in listA and listB + * + * @param <T> + * @param listA + * @param listB + * @return boolean + */ + public static <T> boolean isEqual(Collection<T> listA, Collection<T> listB) { + if (listA.size() != listB.size()) return false; + if (listA.size() != setIntersection(listA, listB).size()) return false; + return true; + } + + @SuppressWarnings("unchecked") + public static Set toSet(Collection collection) { + Set set = null; + if (collection instanceof Set) { + set = (Set) collection; + } else { + set = new LinkedHashSet(); + set.addAll(collection); + } + return set; + } + + /** + * Convert an aggregate list of objects into a List + * + * @param <T> + * @param objects + * @return list + */ + public static <T> List<T> getAggregate(T... objects) { + List<T> objs = new ArrayList<T>(); + if (objects != null) { + for (T obj : objects) { + objs.add(obj); + } + } + return objs; + } + + public static List<Object> getAggregateTree(List<Object> items, int maxPerList) { + if (items == null) throw new IllegalArgumentException("items can not be null"); + if (maxPerList < 2) throw new IllegalArgumentException("maxPerList can not be less than 2"); + + if (items.size() > maxPerList) { + return (recursiveAggregateTree(items, maxPerList)); + } else { + return new ArrayList<Object>(items); + } + } + + private static ArrayList<Object> recursiveAggregateTree(List<Object> items, int maxPerList) { + if (items.size() > maxPerList) { + ArrayList<Object> aggregateList = new ArrayList<Object>(maxPerList); + ArrayList<Object> childList = null; + + for (Object item : items) { + if (childList == null || childList.size() == maxPerList) { + childList = new ArrayList<Object>(maxPerList); + aggregateList.add(childList); + } + childList.add(item); + } + childList.trimToSize(); + + aggregateList = recursiveAggregateTree(aggregateList, maxPerList); + + aggregateList.trimToSize(); + + return aggregateList; + } else { + // This is a safe blind cast since only subsequent calls of this method will end up here + // and this method always uses ArrayList<Object> + return (ArrayList<Object>) items; + } + } + + public static enum CastOption { + MATCHING, ALL + }; + + /** + * Cast objects to clazz + * + * @param <A> + * @param objects + * @param clazz + * @param castOption if ALL, cast all and throw exception if cast fails; if MATCHING, only cast those of type clazz + * @return + */ + private static <A extends Object> List<A> cast(Class<A> clazz, Collection<? extends Object> objects, CastOption castOption) { + List<A> results = new ArrayList<A>(objects.size()); + for (Object object : objects) + if ((castOption == CastOption.ALL) || ((castOption == CastOption.MATCHING) && (object.getClass().isAssignableFrom(clazz)))) { + results.add((A) object); + } + return results; + } + + /** + * Cast objects to clazz + * + * @param <A> + * @param objects + * @return List + */ + public static <A> List<A> castAll(Collection<?> objects) { + List<A> results = new ArrayList<A>(objects.size()); + for (Object object : objects) { + results.add((A) object); + } + return results; + } + + /** + * Unchecked cast objects to clazz; CastClassException will occur when object sent in does not match clazz<br> + * <br> + * Use when all objects are expected to be of type class and exception is desired if not + * + * @param <A> + * @param objects + * @param clazz + * @return List + */ + public static <A extends Object> List<A> castAll(Class<A> clazz, Collection<? extends Object> objects) { + return cast(clazz, objects, CastOption.ALL); + } + + /** + * Cast objects matching class, ignore rest; no ClassCastException will occur<br> + * <br> + * Use when objects may contain classes that are not desired + * + * @param <A> + * @param objects + * @param clazz + * @return List + */ + public static <A extends Object> List<A> castMatching(Class<A> clazz, Collection<? extends Object> objects) { + return cast(clazz, objects, CastOption.MATCHING); + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/EnhancedProperties.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/EnhancedProperties.java new file mode 100644 index 00000000000..576bc3489f0 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/EnhancedProperties.java @@ -0,0 +1,91 @@ +/*
+ * Created on Jul 2, 2008
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.framework.jdk.core.util;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+/**
+ * @author b1529404
+ */
+public class EnhancedProperties implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4105281128024379352L;
+
+ private final HashMap<String, Serializable> map;
+
+ public EnhancedProperties() {
+ map = new HashMap<String, Serializable>();
+ }
+
+ public EnhancedProperties(int initialCapacity) {
+ map = new HashMap<String, Serializable>(initialCapacity);
+ }
+
+ public EnhancedProperties(EnhancedProperties props) {
+ this();
+ addAll(props);
+ }
+
+ public void setProperty(String key, Serializable value) {
+ map.put(key, value);
+ }
+
+ public Serializable getProperty(String key) {
+ return map.get(key);
+ }
+
+ public Serializable getProperty(String key, Serializable defaultValue) {
+ Serializable value = map.get(key);
+ return value == null ? defaultValue : value;
+ }
+
+ public Set<Map.Entry<String, Serializable>> entrySet() {
+ return map.entrySet();
+ }
+
+ public void addAll(EnhancedProperties otherProps) {
+ this.map.putAll(otherProps.map);
+ }
+
+ public void addAll(Map<String, Serializable> otherMap) {
+ this.map.putAll(otherMap);
+ }
+
+ public void clear() {
+ map.clear();
+ }
+
+ public Collection<String> differences(EnhancedProperties otherProps) {
+ LinkedList<String> differences = new LinkedList<String>();
+ for (Entry<String, Serializable> entry : map.entrySet()) {
+ Serializable value = otherProps.getProperty(entry.getKey());
+ if (value == null) {
+ if (entry.getValue() != null) {
+ differences.add(entry.getKey());
+ }
+ } else {
+ if (!value.equals(entry.getValue())) {
+ differences.add(entry.getKey());
+ }
+ }
+ }
+ map.clear();
+ map.putAll(otherProps.map);
+ return differences;
+ }
+
+ public Map<String, Serializable> asMap() {
+ return map;
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/EnumBase.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/EnumBase.java new file mode 100644 index 00000000000..b2efab52a0e --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/EnumBase.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +import javax.print.attribute.EnumSyntax; + +/** + * @author Ryan D. Brooks + * @author Andrew M. Finkbeiner + */ +public abstract class EnumBase extends EnumSyntax { + //TODO We need to possibly refactor getEnum and rework the structure of the enums??? + + protected abstract String[] getStringTable(); + + protected abstract EnumSyntax[] getEnumValueTable(); + + protected EnumBase(int value) { + + super(value); + } + + protected static EnumBase getEnum(String str, String[] stringTable, EnumBase[] enumValueTable) { + + for (int i = 0; i < stringTable.length; i++) { + if (stringTable[i].toUpperCase().equals(str.toUpperCase())) return enumValueTable[i]; + } + + throw new IllegalArgumentException("Not a valid enumeration name: " + str); + // TODO - We might want to come back and make this more efficient later!!! + // This was a binary search, but was changed because it was forcing the tables to have to be + // in the correct binary search order to work. + + } + + protected static EnumBase getEnum(int value, EnumBase[] enumValueTable) { + + return enumValueTable[value - enumValueTable[0].getValue()]; + } + + protected int getOffset() { + + return getEnumValueTable()[0].getValue(); + } + + public String getName() { + + return getStringTable()[getValue() - getOffset()]; + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Enums.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Enums.java new file mode 100644 index 00000000000..341aeeeb36e --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Enums.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +/** + * @author Donald G. Dunne + */ +public class Enums { + + public static String getCommaDeliminatedString(Enum<?>[] enums) { + StringBuffer sb = new StringBuffer(); + for (Enum<?> e : enums) + sb.append(e.name() + ","); + return sb.toString().replaceFirst(",$", ""); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/GUID.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/GUID.java new file mode 100644 index 00000000000..e3ef714b8a1 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/GUID.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +import java.io.Serializable; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import sun.misc.CharacterEncoder; + +/** + * @author Ryan D. Brooks + * @author Robert A. Fisher + */ +public class GUID implements Serializable { + private final long time; + private final int hash; + private final int rand; + private final String guidString; + private static final long serialVersionUID = -3849714490764637010L; + + private static final ThreadLocal<byte[]> threadLocalBytes = new ThreadLocal<byte[]>() { + protected synchronized byte[] initialValue() { + return new byte[16]; + } + }; + + private static final ThreadLocal<CharacterEncoder> threadLocalEncoder = new ThreadLocal<CharacterEncoder>() { + protected synchronized CharacterEncoder initialValue() { + return new sun.misc.BASE64Encoder(); + } + }; + + public static boolean isValid(String guid) { + if (guid.length() != 22) { + return false; + } + Matcher m = Pattern.compile("^[0-9A-Za-z\\+_]+$").matcher(guid); + if (!m.find()) { + return false; + } + return true; + } + + public GUID() { + this(GUIDType.ARTIFACT); + } + + public GUID(GUIDType type) { + this.time = System.currentTimeMillis(); + this.hash = Thread.currentThread().hashCode(); + this.rand = (int) (Math.random() * Integer.MAX_VALUE); + + this.guidString = toGuidString(time, hash, rand, type); + } + + public static String generateGuidStr() { + return generateGuidStr(GUIDType.ARTIFACT); + } + + public static String generateGuidStr(GUIDType type) { + long time = System.currentTimeMillis(); + int hash = Thread.currentThread().hashCode(); + int rand = (int) (Math.random() * Integer.MAX_VALUE); + return toGuidString(time, hash, rand, type); + } + + private static String toGuidString(long time, int hash, int rand, GUIDType type) { + byte[] rawBytes = (byte[]) threadLocalBytes.get(); + ByteUtil.toBytes(rawBytes, 0, time); + ByteUtil.toBytes(rawBytes, 8, hash); + ByteUtil.toBytes(rawBytes, 12, rand); + + CharacterEncoder base64Encoder = (CharacterEncoder) threadLocalEncoder.get(); + /* + * 64 = 2^6 64^22 > 2^128 (2^6)^22 > 2^128 2^132 > 2^128 thus a 22 digit base64 number is + * needed to represent a 16 byte number + */ + return type + base64Encoder.encode(rawBytes).replace('/', '_').substring(1, 22); + } + + public boolean equals(Object other) { + + if (other instanceof GUID) { + return this.time == ((GUID) other).time && this.hash == ((GUID) other).hash && this.rand == ((GUID) other).rand; + } + + return false; + } + + public int hashCode() { + int result = 17; + result = result + (int) (time ^ (time >>> 32)); + result = 37 * result + hash; + result = 37 * result + rand; + return result; + } + + public String toString() { + return guidString; + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/GUIDTest.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/GUIDTest.java new file mode 100644 index 00000000000..4ebf6c763cd --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/GUIDTest.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +public class GUIDTest { + + /** + * @param args + */ + public static void main(String[] args) { + + while (true) { + String g = GUID.generateGuidStr(); + if (g.substring(1, 2).matches("^[A-Za-z]{2}$")) { + System.err.println("ERROR " + g); + } else + System.out.println("g *" + g + "*"); + } + + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/GUIDType.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/GUIDType.java new file mode 100644 index 00000000000..5951d2ef84e --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/GUIDType.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +/** + * @author Robert A. Fisher + */ +public enum GUIDType { + ARTIFACT("A"), ARTIFACT_VERSION("B"); + + private final String prefixChar; + + private GUIDType(String prefixChar) { + this.prefixChar = prefixChar; + } + + public String toString() { + return prefixChar; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/HttpProcessor.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/HttpProcessor.java new file mode 100644 index 00000000000..9cc3b2c6d45 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/HttpProcessor.java @@ -0,0 +1,227 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URI;
+import java.net.URL;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class HttpProcessor {
+ private static final int CONNECTION_TIMEOUT = 1000 * 60 * 2;
+ private static final String CONTENT_LENGTH = "Content-Length";
+ private static final String CONTENT_TYPE = "Content-Type";
+ private static final String CONTENT_ENCODING = "Content-Encoding";
+
+ private HttpProcessor() {
+ }
+
+ private static HttpURLConnection setupConnection(URL url) throws IOException {
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setConnectTimeout(CONNECTION_TIMEOUT);
+ connection.setReadTimeout(0);
+ return connection;
+ }
+
+ public static URI save(URL url, InputStream inputStream, String contentType, String encoding) throws Exception {
+ String locator = put(url, inputStream, contentType, encoding);
+ return new URI(locator);
+ }
+
+ public static String put(URL url, InputStream inputStream, String contentType, String encoding) throws Exception {
+ String response = null;
+ HttpUploader uploader = new HttpUploader(url.toString(), inputStream, contentType, encoding);
+ boolean wasSuccessful = uploader.execute();
+ if (wasSuccessful) {
+ response = uploader.getUploadResponse();
+ if (response == null) {
+ throw new Exception(String.format("Error uploading resource [%s]", url));
+ }
+ } else {
+ throw new Exception(String.format("Error uploading resource [%s]", url));
+ }
+ return response;
+ }
+
+ public static AcquireResult post(URL url, InputStream inputStream, String contentType, String encoding, OutputStream outputStream) throws IOException {
+ AcquireResult result = new AcquireResult();
+ int code = -1;
+ HttpURLConnection connection = null;
+ InputStream httpInputStream = null;
+ try {
+ connection = setupConnection(url);
+ connection.setRequestProperty(CONTENT_LENGTH, Integer.toString(inputStream.available()));
+ connection.setRequestProperty(CONTENT_TYPE, contentType);
+ connection.setRequestProperty(CONTENT_ENCODING, encoding);
+ connection.setRequestMethod("POST");
+ connection.setAllowUserInteraction(true);
+ connection.setDoOutput(true);
+ connection.setDoInput(true);
+ connection.connect();
+ Lib.inputStreamToOutputStream(inputStream, connection.getOutputStream());
+ code = connection.getResponseCode();
+ if (code == HttpURLConnection.HTTP_ACCEPTED) {
+ httpInputStream = (InputStream) connection.getContent();
+ result.setContentType(connection.getContentType());
+ result.setEncoding(connection.getContentEncoding());
+ Lib.inputStreamToOutputStream(httpInputStream, outputStream);
+ } else {
+ throw new IOException(String.format("Error during POST [%s] - status code: [%s]", url, code));
+ }
+ } catch (IOException ex) {
+ throw new IOException(String.format("Error during POST [%s] - status code: [%s]", url, code), ex);
+ } finally {
+ result.setCode(code);
+ if (httpInputStream != null) {
+ httpInputStream.close();
+ }
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ return result;
+ }
+
+ public static String post(URL url) throws Exception {
+ String response = null;
+ int code = -1;
+ InputStream inputStream = null;
+ HttpURLConnection connection = null;
+ try {
+ connection = setupConnection(url);
+ connection.setRequestMethod("POST");
+ connection.connect();
+ // Wait for response
+ code = connection.getResponseCode();
+ if (code == HttpURLConnection.HTTP_ACCEPTED) {
+ inputStream = (InputStream) connection.getContent();
+ response = Lib.inputStreamToString(inputStream);
+ } else {
+ throw new Exception(String.format("Error during POST [%s] - status code: [%s]", url, code));
+ }
+ } catch (Exception ex) {
+ throw new Exception(String.format("Error during POST [%s] - status code: [%s]", url, code), ex);
+ } finally {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ return response;
+ }
+
+ public static AcquireResult acquire(URL url, OutputStream outputStream) throws Exception {
+ AcquireResult result = new AcquireResult();
+ int code = -1;
+ InputStream inputStream = null;
+ HttpURLConnection connection = null;
+ try {
+ connection = setupConnection(url);
+ connection.connect();
+ // Wait for response
+ code = connection.getResponseCode();
+ if (code == HttpURLConnection.HTTP_OK) {
+ inputStream = (InputStream) connection.getContent();
+ result.setContentType(connection.getContentType());
+ result.setEncoding(connection.getContentEncoding());
+ Lib.inputStreamToOutputStream(inputStream, outputStream);
+ }
+
+ } catch (Exception ex) {
+ throw new Exception(String.format("Error acquiring resource: [%s] - status code: [%s]", url, code), ex);
+ } finally {
+ result.setCode(code);
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ return result;
+ }
+
+ public static String delete(URL url) throws Exception {
+ String response = null;
+ int code = -1;
+ InputStream inputStream = null;
+ HttpURLConnection connection = null;
+ try {
+ connection = setupConnection(url);
+ connection.setRequestMethod("DELETE");
+ connection.connect();
+ // Wait for response
+ code = connection.getResponseCode();
+ if (code == HttpURLConnection.HTTP_ACCEPTED) {
+ inputStream = (InputStream) connection.getContent();
+ response = Lib.inputStreamToString(inputStream);
+ }
+ } catch (Exception ex) {
+ throw new Exception(String.format("Error deleting resource: [%s] - status code: [%s]", url, code), ex);
+ } finally {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ return response;
+ }
+
+ public static final class AcquireResult {
+ private int code;
+ private String encoding;
+ private String contentType;
+
+ private AcquireResult() {
+ super();
+ this.code = -1;
+ this.encoding = "";
+ this.contentType = "";
+ }
+
+ public boolean wasSuccessful() {
+ return code == HttpURLConnection.HTTP_OK;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ private void setCode(int code) {
+ this.code = code;
+ }
+
+ public String getEncoding() {
+ return encoding;
+ }
+
+ private void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ private void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/HttpUploader.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/HttpUploader.java new file mode 100644 index 00000000000..342aaeeff98 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/HttpUploader.java @@ -0,0 +1,131 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class HttpUploader {
+ private static final int CONNECTION_TIMEOUT = 120000;
+ private static final int CONNECTION_READ_TIMEOUT = 1000 * 60 * 10;
+ private static final String CONTENT_LENGTH = "Content-Length";
+ private static final String CONTENT_TYPE = "Content-Type";
+ private static final String CONTENT_ENCODING = "Content-Encoding";
+
+ private String urlRequest;
+ private InputStream inputStream;
+ private String dataType;
+ private String encoding;
+ private String remoteLocation;
+ private String lastUploaded;
+ private String uploadResponse;
+
+ public HttpUploader(String urlRequest, InputStream inputStream, String dataType, String encoding) {
+ this.urlRequest = urlRequest;
+ this.inputStream = inputStream;
+ this.dataType = dataType;
+ this.encoding = encoding;
+ this.remoteLocation = "";
+ this.lastUploaded = "";
+ this.uploadResponse = "";
+ }
+
+ private HttpURLConnection setupConnection() throws IOException {
+ URL url = new URL(urlRequest);
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestProperty(CONTENT_LENGTH, Integer.toString(inputStream.available()));
+ connection.setRequestProperty(CONTENT_TYPE, dataType);
+ connection.setRequestProperty(CONTENT_ENCODING, encoding);
+ connection.setRequestMethod("PUT");
+ connection.setAllowUserInteraction(true);
+ connection.setDoOutput(true);
+ connection.setDoInput(true);
+ connection.setReadTimeout(CONNECTION_READ_TIMEOUT);
+ connection.setConnectTimeout(CONNECTION_TIMEOUT);
+ return connection;
+ }
+
+ public String getUploadResponse() {
+ return uploadResponse;
+ }
+
+ public boolean execute() throws Exception {
+ HttpURLConnection connection = null;
+ boolean toReturn = false;
+ try {
+ connection = setupConnection();
+ connection.connect();
+
+ inputStreamToOutputStream(inputStream, connection.getOutputStream());
+ toReturn = handleResponse(connection);
+ } catch (Exception ex) {
+ throw new Exception(String.format("Error uploading to server: [%s]", urlRequest), ex);
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ return toReturn;
+ }
+
+ public String getDateUploaded() {
+ return lastUploaded;
+ }
+
+ public String getRemoteLocation() {
+ return remoteLocation;
+ }
+
+ private boolean handleResponse(HttpURLConnection connection) throws Exception {
+ InputStream inputStream = null;
+ boolean toReturn = false;
+ try {
+ int responseCode = HttpURLConnection.HTTP_CLIENT_TIMEOUT;
+ responseCode = connection.getResponseCode();
+ if (responseCode == HttpURLConnection.HTTP_CREATED) {
+ lastUploaded = connection.getHeaderField("Last-Modified");
+ remoteLocation = connection.getHeaderField("Content-Location");
+
+ inputStream = (InputStream) connection.getContent();
+ this.uploadResponse = Lib.inputStreamToString(inputStream);
+
+ toReturn = true;
+ }
+ if (responseCode != HttpURLConnection.HTTP_CREATED) {
+ toReturn = false;
+ }
+ } finally {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ }
+ return toReturn;
+ }
+
+ private void inputStreamToOutputStream(InputStream inputStream, OutputStream outputStream) throws IOException {
+ byte[] buf = new byte[8092];
+ int count = -1;
+ int tracker = 0;
+ while ((count = inputStream.read(buf)) != -1) {
+ outputStream.write(buf, 0, count);
+ tracker += count;
+ }
+ inputStream.close();
+ outputStream.flush();
+ outputStream.close();
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/IAbbreviated.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/IAbbreviated.java new file mode 100644 index 00000000000..9d4c307746c --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/IAbbreviated.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +/** + * An interface describing items that can provide an abbreviation name. + * + * @author Robert A. Fisher + */ +public interface IAbbreviated { + public String getAbbreviation(); +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/IConsoleInputListener.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/IConsoleInputListener.java new file mode 100644 index 00000000000..072171025ed --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/IConsoleInputListener.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +public interface IConsoleInputListener { + void lineRead(String line); +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/JarCreator.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/JarCreator.java new file mode 100644 index 00000000000..337813ad4b7 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/JarCreator.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.jar.Attributes; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; +import java.util.jar.Manifest; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author Ryan D. Brooks + * @author Andrew M. Finkbeiner + */ +public class JarCreator { + private JarOutputStream out; + private byte[] buffer; + + /** + * @throws IOException + * @throws FileNotFoundException + */ + public JarCreator(File path, String title, String version) throws FileNotFoundException, IOException { + super(); + Manifest manifest = new Manifest(); + Attributes attributes = manifest.getMainAttributes(); + attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0"); + attributes.putValue("Implementation-Title", title); + attributes.putValue("Implementation-Version", version); + out = new JarOutputStream(new FileOutputStream(path), manifest); + buffer = new byte[20480]; + } + + private void addFile(File file, String pathInJar) throws IOException { + + out.putNextEntry(new JarEntry(pathInJar.replace('\\', '/'))); + + // Read the file and write it to the jar. + FileInputStream in = new FileInputStream(file); + int bytesRead; + while ((bytesRead = in.read(buffer)) != -1) { + out.write(buffer, 0, bytesRead); + } + in.close(); + } + + /** + * @param path + * @param rootPathPos + * @throws IOException + */ + private void addRelativeToPosition(File path, int rootPathPos, FileFilter filenameFilter) throws IOException { + if (path.isDirectory()) { + File[] files = path.listFiles(filenameFilter); + for (int i = 0; i < files.length; i++) { + addRelativeToPosition(files[i], rootPathPos, filenameFilter); + } + } else { + addFile(path, path.getAbsolutePath().substring(rootPathPos)); + } + } + + /** + * just an entry point into the recursive addRelativeTo so the (unchanging) rootPathPos can be computed once + */ + private void addDirectoryContents(File directory, FileFilter filenameFilter) throws IOException { + if (directory.isDirectory()) { + int rootPathPos = directory.getPath().length() + 1; + addRelativeToPosition(directory, rootPathPos, filenameFilter); + } else { + throw new IllegalArgumentException("Must be a directory: " + directory); + } + } + + public void addFileRelativeTo(File path, String relativeTo) throws IOException { + addRelativeToPosition(path, relativeTo.length() + 1, null); + } + + public void addDirectoryContents(File directory) throws IOException { + addDirectoryContents(directory, (FilenameAndDirectoryFilter) null); + } + + public void addDirectoryContents(File directory, String fileNamePattern) throws IOException { + addDirectoryContents(directory, new FilenameAndDirectoryFilter(fileNamePattern)); + } + + public void close() throws IOException { + out.close(); + } + + private class FilenameAndDirectoryFilter implements FileFilter { + private Matcher matcher; + + public FilenameAndDirectoryFilter(String pattern) { + this.matcher = Pattern.compile(pattern).matcher(""); + } + + public boolean accept(File pathname) { + if (pathname.isDirectory()) { + return true; + } + matcher.reset(pathname.getName()); + return matcher.matches(); + } + + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Lib.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Lib.java new file mode 100644 index 00000000000..96db72e0dec --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Lib.java @@ -0,0 +1,1586 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.util;
+
+import java.awt.Image;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.security.CodeSource;
+import java.security.ProtectionDomain;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+import javax.swing.ImageIcon;
+import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet;
+import org.eclipse.osee.framework.jdk.core.util.io.IOInputThread;
+import org.eclipse.osee.framework.jdk.core.util.io.IOOutputThread;
+import org.eclipse.osee.framework.jdk.core.util.io.InputBufferThread;
+import org.eclipse.osee.framework.jdk.core.util.io.MatchFilter;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public final class Lib {
+ public final static Runtime runtime = Runtime.getRuntime();
+
+ public final static String jarPath = getJarPath(Lib.class);
+
+ public final static String basePath = getBasePath();
+
+ public final static String lineSeparator = System.getProperty("line.separator");
+
+ public static String toFirstCharUpperCase(String str) {
+ if (str == null) {
+ return null;
+ }
+ char[] chars = str.toCharArray();
+ chars[0] = Character.toUpperCase(str.charAt(0));
+ return new String(chars);
+ }
+
+ public static int numOccurances(String str, String regex) {
+ int x = 0;
+ Matcher m = Pattern.compile(regex).matcher(str);
+ while (m.find())
+ x++;
+ return x;
+ }
+
+ public static String exceptionToString(Throwable ex) {
+ StringBuilder sb = new StringBuilder();
+ exceptionToString(ex, sb);
+ return sb.toString();
+ }
+
+ public static boolean validateEmail(String toValidate) {
+ Pattern pattern =
+ Pattern.compile("^[a-z0-9\\._-]" + "+@([a-z0-9][a-z0-9-]*" + "[a-z0-9]\\.)+" + "([a-z]+\\.)?([a-z]+)$",
+ Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(toValidate);
+ return matcher.find();
+ }
+
+ private static void exceptionToString(Throwable ex, StringBuilder sb) {
+ if (ex == null) {
+ sb.append("Exception == null; can't display stack");
+ return;
+ }
+ sb.append(ex.getMessage() + "\n");
+ StackTraceElement st[] = ex.getStackTrace();
+ for (int i = 0; i < st.length; i++) {
+ StackTraceElement ste = st[i];
+ sb.append(" at " + ste.toString() + "\n");
+ }
+ Throwable cause = ex.getCause();
+ if (cause != null) {
+ sb.append(" caused by ");
+ exceptionToString(cause, sb);
+ }
+ }
+
+ public static String changeExtension(String str, String newExt) {
+ int pos = str.lastIndexOf('.');
+ if (pos == -1) { // was -1 before + 1
+ return str + "." + newExt;
+ }
+ return str.substring(0, pos + 1) + newExt;
+ }
+
+ /**
+ * this version of changeExtension will work even if the extension we want to replace contains a .
+ *
+ * @param str
+ * @param oldExt
+ * @param newExt
+ * @return String
+ */
+ public static String changeExtension(String str, String oldExt, String newExt) {
+ int pos = str.lastIndexOf(oldExt);
+ if (pos == -1) {
+ return str + "." + newExt;
+ }
+ return str.substring(0, pos) + newExt;
+ }
+
+ /**
+ * Move an object one before the previous object
+ *
+ * @param list
+ * @param obj
+ * @return true if successful
+ */
+ public static boolean moveBack(ArrayList<Object> list, Object obj) {
+ if (list.contains(obj)) {
+ int index = list.indexOf(obj);
+ if (index > 0) {
+ list.remove(index);
+ list.add(index - 1, obj);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Move an object one after the next object
+ *
+ * @param obj
+ * @return true if successful
+ */
+ public static boolean moveForward(ArrayList<Object> list, Object obj) {
+ int size = list.size();
+ if (list.contains(obj)) {
+ int index = list.indexOf(obj);
+ if (index < (size - 1)) {
+ list.remove(index);
+ list.add(index + 1, obj);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static void copyDirectory(File source, File destination) throws IOException {
+ File[] files = source.listFiles();
+
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory()) {
+ File dir = new File(destination, files[i].getName());
+ dir.mkdir();
+ copyDirectory(files[i], dir);
+ } else { // else is a file
+ copyFile(files[i], destination);
+ }
+ }
+ }
+
+ public static String exceptionToString(Exception ex) {
+ StringWriter stringWriter = new StringWriter();
+ PrintWriter printWriter = new PrintWriter(stringWriter);
+ ex.printStackTrace(printWriter);
+ return stringWriter.toString();
+ }
+
+ public static void copyFile(File source, File destination) throws IOException {
+ FileInputStream in = new FileInputStream(source);
+ FileOutputStream out = null;
+
+ if (destination.isDirectory()) {
+ out = new FileOutputStream(new File(destination, source.getName()));
+ } else {
+ destination.delete(); // to work around some file permission
+ // problems
+ out = new FileOutputStream(destination);
+ }
+
+ byte[] bytes = new byte[(int) source.length()];
+ in.read(bytes);
+ out.write(bytes);
+
+ in.close();
+ out.close();
+ }
+
+ public static void copyFiles(File source, File destination) throws IOException {
+ copyFiles(source, null, destination);
+ }
+
+ public static void copyFiles(File source, FilenameFilter filter, File destination) throws IOException {
+ File[] files = source.listFiles(filter);
+ if (!source.exists()) {
+ throw new IllegalArgumentException("the directory " + source + " does not exist.");
+ }
+
+ if (files != null) {
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isFile()) {
+ copyFile(files[i], destination);
+ }
+ }
+ }
+ }
+
+ public static Image createImage(String path) {
+ return createImageIcon(path).getImage();
+ }
+
+ public static ImageIcon createImageIcon(Class<?> clasaRef, String path) {
+ URL imgURL = clasaRef.getResource(path);
+ if (imgURL != null) {
+ return new ImageIcon(imgURL);
+ } else {
+ System.err.println("Couldn't find the resource: " + path);
+ return null;
+ }
+ }
+
+ /** Returns an ImageIcon, or null if the path was invalid. */
+ public static ImageIcon createImageIcon(String path) {
+ return createImageIcon(Lib.class, path);
+ }
+
+ public static void deleteDir(File directory) {
+ File[] files = directory.listFiles();
+ if (files == null) {
+ return;
+ }
+
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory()) {
+ deleteDir(files[i]);
+ } else { // else is a file
+ files[i].delete();
+ }
+ }
+ directory.delete();
+ }
+
+ public static void deleteContents(File directory) {
+ deleteContents(directory, null);
+ }
+
+ public static void deleteContents(File directory, FilenameFilter filter) {
+ File[] files = directory.listFiles(filter);
+
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory()) {
+ deleteContents(files[i]);
+ }
+ files[i].delete();
+ }
+ }
+
+ /**
+ * Delete the current file and all empty parents. The method will stop deleting empty parents once it reaches the
+ * stopAt parent.
+ *
+ * @param stopAt path of the parent file to stop deleting at
+ * @param file to delete
+ * @return status <b>true</b> if successful
+ */
+ public static boolean deleteFileAndEmptyParents(String stopAt, File file) {
+ boolean result = true;
+ if (file != null) {
+ if (file.isDirectory() != false) {
+ if (file.list().length == 0) {
+ result &= file.delete();
+ }
+ } else {
+ result &= file.delete();
+ }
+ }
+ File parent = file.getParentFile();
+ if (parent != null && parent.getAbsolutePath().equals(stopAt) != true) {
+ result &= deleteFileAndEmptyParents(stopAt, parent);
+ }
+ return result;
+ }
+
+ /**
+ * Deletes all files from directory
+ *
+ * @param directory
+ */
+ public static void emptyDirectory(File directory) {
+ File[] children = directory.listFiles();
+ if (children != null) {
+ for (File child : children) {
+ if (child.isDirectory()) {
+ emptyDirectory(child);
+ } else { // else is a file
+ child.delete();
+ }
+ }
+ }
+ }
+
+ public static void inputStreamToOutputStream(InputStream inputStream, OutputStream outputStream) throws IOException {
+ byte[] buf = new byte[10000];
+ int count = -1;
+ while ((count = inputStream.read(buf)) != -1) {
+ outputStream.write(buf, 0, count);
+ }
+ }
+
+ public static String inputStreamToString(InputStream in) throws IOException {
+ return inputStreamToChangeSet(in).toString();
+ }
+
+ public static ChangeSet inputStreamToChangeSet(InputStream in) throws IOException {
+ InputStreamReader reader = new InputStreamReader(in, "UTF-8");
+ ChangeSet set = new ChangeSet();
+
+ char[] chars = new char[8000];
+ int readCount = 0;
+ while ((readCount = reader.read(chars)) != -1) {
+ set.insertBefore(0, chars, 0, readCount, true);
+ }
+ return set;
+ }
+
+ public static byte[] inputStreamToBytes(InputStream in) throws IOException {
+ byte[] bytes = new byte[2024];
+ ByteArrayOutputStream out = new ByteArrayOutputStream(2024);
+
+ int numBytesRead;
+ while ((numBytesRead = in.read(bytes)) != -1) {
+ out.write(bytes, 0, numBytesRead);
+ }
+ return out.toByteArray();
+ }
+
+ public static void inputStreamToFile(InputStream inputStream, File outFile) throws IOException {
+ byte[] bytes = new byte[2024];
+ FileOutputStream out = new FileOutputStream(outFile);
+
+ int numBytesRead;
+ while ((numBytesRead = inputStream.read(bytes)) != -1) {
+ out.write(bytes, 0, numBytesRead);
+ }
+ out.close();
+ }
+
+ public static CharBuffer inputStreamToCharBuffer(InputStream in) throws IOException {
+ return CharBuffer.wrap(inputStreamToChangeSet(in).toCharArray());
+ }
+
+ public static java.io.InputStream stringToInputStream(String value) throws Exception {
+ if (value == null) return null;
+ value = value.trim();
+ java.io.InputStream in = null;
+ in = new java.io.ByteArrayInputStream(value.getBytes("UTF-8"));
+ return in;
+ }
+
+ public static InputStream byteBufferToInputStream(final ByteBuffer byteBuffer) {
+ return new InputStream() {
+ @Override
+ public synchronized int read() throws IOException {
+ if (!byteBuffer.hasRemaining()) {
+ return -1;
+ }
+ return byteBuffer.get();
+ }
+
+ @Override
+ public synchronized int read(byte[] bytes, int off, int len) throws IOException {
+ len = Math.min(len, byteBuffer.remaining());
+ if (off != len) {
+ byteBuffer.get(bytes, off, len);
+ } else {
+ len = -1;
+ }
+ return len;
+ }
+
+ /* (non-Javadoc)
+ * @see java.io.InputStream#reset()
+ */
+ @Override
+ public synchronized void reset() throws IOException {
+ byteBuffer.rewind();
+ }
+
+ };
+ }
+
+ public static OutputStream byteBufferToOutputStream(final ByteBuffer byteBuffer) {
+ return new OutputStream() {
+ @Override
+ public synchronized void write(int b) throws IOException {
+ byteBuffer.put((byte) b);
+ }
+
+ @Override
+ public synchronized void write(byte[] bytes, int off, int len) throws IOException {
+ byteBuffer.put(bytes, off, len);
+ }
+ };
+ }
+
+ public static final Pattern numberListPattern = Pattern.compile("\\d+");
+
+ public static List<Integer> stringToIntegerList(String numberList) {
+ ArrayList<Integer> ints = new ArrayList<Integer>();
+ Matcher transactionIdMatcher = numberListPattern.matcher(numberList);
+ while (transactionIdMatcher.find()) {
+ ints.add(Integer.parseInt(transactionIdMatcher.group()));
+ }
+ return ints;
+ }
+
+ public static String fileToString(File file) throws IOException {
+ StringBuffer buffer = new StringBuffer();
+ Reader inStream = new InputStreamReader(new FileInputStream(file), "UTF-8");
+ Reader in = new BufferedReader(inStream);
+ int ch;
+ while ((ch = in.read()) > -1) {
+ buffer.append((char) ch);
+ }
+ in.close();
+ return buffer.toString();
+ }
+
+ public static byte[] fileToBytes(File file) throws IOException {
+ InputStream inputStream = new FileInputStream(file);
+ try {
+ byte[] bytes = new byte[(int) file.length()];
+ inputStream.read(bytes);
+ return bytes;
+ } finally {
+ inputStream.close();
+ }
+ }
+
+ /**
+ * usage: char[] buf = new char[5500000]; for (Iterator iter = files.iterator(); iter.hasNext(); ) { // for each file
+ * File file = (File)iter.next(); buf = Lib.fileToChars(file, buf);
+ *
+ * @param file
+ * @param buf
+ * @return char[]
+ * @throws IOException
+ */
+ public static char[] fileToChars(File file, char[] buf) throws IOException {
+ FileReader in = new FileReader(file);
+ int size = (int) file.length();
+
+ if (buf == null) {
+ buf = new char[size];
+ } else if (size > buf.length) {
+ buf = null;
+ System.gc(); // since the currently allocated buf might already
+ // be quite large
+ buf = new char[size];
+ }
+
+ in.read(buf);
+ in.close();
+ return buf;
+ }
+
+ public static CharBuffer fileToCharBuffer(File file) throws IOException {
+ FileReader in = new FileReader(file);
+ char[] chars = new char[(int) file.length()];
+ in.read(chars);
+ in.close();
+ return CharBuffer.wrap(chars);
+ }
+
+ public static String fillString(char c, int n) {
+ char[] chars = new char[n];
+ for (int i = 0; i < n; chars[i++] = c) {
+ // must leave empty block here so the following line won't become
+ // part of the loop
+ }
+ return new String(chars);
+ }
+
+ /**
+ * Get file extension from the file path
+ *
+ * @param filepath
+ * @return file extension
+ */
+ public static String getExtension(String filepath) {
+ filepath = filepath.trim();
+ String separatorRegEx = File.separator;
+ if (Lib.isWindows()) {
+ separatorRegEx = "\\\\";
+ }
+ String[] pathsArray = filepath.split(separatorRegEx);
+
+ String fileName = pathsArray[0];
+ if (pathsArray.length > 0) {
+ fileName = pathsArray[pathsArray.length - 1];
+ }
+
+ int index = fileName.lastIndexOf('.');
+ if (index >= 0 && index + 1 < fileName.length()) {
+ return fileName.substring(index + 1);
+ } else {
+ return "";
+ }
+ }
+
+ public static int handleProcess(Process proc) {
+ return handleProcess(proc, new PrintWriter(System.out, true));
+ }
+
+ public static int handleProcess(Process proc, Writer output, String errName, String outName) {
+ return handleProcess(proc, output, errName, outName, true);
+ }
+
+ public static int handleProcess(Process proc, Writer output, String errName, String outName, boolean verbose) {
+ try {
+ IOOutputThread errThread =
+ new IOOutputThread(output, new BufferedReader(new InputStreamReader(proc.getErrorStream())), verbose);
+ IOOutputThread outThread =
+ new IOOutputThread(output, new BufferedReader(new InputStreamReader(proc.getInputStream())), verbose);
+
+ errThread.setName(errName);
+ outThread.setName(outName);
+ errThread.start();
+ outThread.start();
+ proc.waitFor();
+ int exitCode = proc.exitValue();
+ if (exitCode != 0) {
+ output.write("Process exit code is: " + exitCode + "\n");
+ }
+ int count = 0;
+ while (errThread.isAlive() || outThread.isAlive()) {
+ if (count > 10) break;
+ synchronized (Thread.currentThread()) {
+ Thread.currentThread().wait(500);
+ }
+ count++;
+ }
+ output.flush();
+ return exitCode;
+ } catch (IOException ex) {
+ System.err.println(ex);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ return Integer.MIN_VALUE;
+ }
+
+ public static int handleProcess(Process proc, Writer output) {
+ return handleProcess(proc, output, "err", "out");
+ }
+
+ public static int handleProcess(Process proc, Writer output, boolean verbose) {
+ return handleProcess(proc, output, "err", "out", verbose);
+ }
+
+ /**
+ * Sets up an error, input, and output stream for the given process. The error stream gives all information coming
+ * FROM the process through it's err stream. The "outThread" will be what come from the FROM the process through it's
+ * normal output stream. The "inThread" is the stream for issuing commands TO the process.
+ *
+ * @param proc The process whose streams we are setting up
+ * @param output Where all info coming FROM the minicom is sent
+ * @param input Where all data going TO the minicom is sent
+ * @return An array of threads in the following order:<br>
+ * --index 0 = Err Stream<br>
+ * --index 1 = output stream<br>
+ * --index 2 = input stream<br>
+ */
+ public static Thread[] handleMinicomProcess(Process proc, Writer output, Reader input) {
+ IOOutputThread errThread =
+ new IOOutputThread(output, new BufferedReader(new InputStreamReader(proc.getErrorStream())));
+
+ InputBufferThread outThread = new InputBufferThread(proc.getInputStream());
+
+ errThread.setName("err");
+ outThread.setName("out");
+ errThread.start();
+ outThread.start();
+
+ if (input != null) {
+ IOInputThread inThread =
+ new IOInputThread(input, new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())));
+ inThread.setName("in");
+ inThread.start();
+ return new Thread[] {errThread, outThread, inThread};
+ }
+ return new Thread[] {errThread, outThread};
+ }
+
+ public static Thread[] handleProcessNoWait(Process proc, Writer output) {
+ return handleProcessNoWait(proc, output, output, null);
+ }
+
+ public static Thread[] handleProcessNoWait(Process proc, Writer output, boolean verbose) {
+ return handleProcessNoWait(proc, output, output, null, "err", "out", verbose);
+ }
+
+ public static Thread[] handleProcessNoWait(Process proc, Writer output, Writer errorWriter, Reader reader) {
+ return handleProcessNoWait(proc, output, errorWriter, reader, "err", "out", true);
+ }
+
+ public static Thread[] handleProcessNoWait(Process proc, Writer outputWriter, Writer errorWriter, Reader reader, String errName, String outName) {
+ return handleProcessNoWait(proc, outputWriter, errorWriter, reader, errName, outName, true);
+ }
+
+ public static Thread[] handleProcessNoWait(Process proc, Writer outputWriter, Writer errorWriter, Reader reader, String errName, String outName, boolean verbose) {
+ IOOutputThread errThread =
+ new IOOutputThread(errorWriter, new BufferedReader(new InputStreamReader(proc.getErrorStream())), verbose);
+ IOOutputThread outThread =
+ new IOOutputThread(outputWriter, new BufferedReader(new InputStreamReader(proc.getInputStream())), verbose);
+ errThread.setName(errName);
+ outThread.setName(outName);
+ errThread.start();
+ outThread.start();
+ if (reader != null) {
+ IOInputThread inThread =
+ new IOInputThread(reader, new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())));
+ inThread.setName("in");
+ inThread.start();
+ return new Thread[] {errThread, outThread, inThread};
+ }
+ return new Thread[] {errThread, outThread};
+ }
+
+ public static void makeDirClean(File directory) {
+ if (directory.exists()) {
+ Lib.deleteContents(directory);
+ } else {
+ directory.mkdir();
+ }
+ }
+
+ public static void moveFiles(File source, File destination) {
+ moveFiles(source, null, destination);
+ }
+
+ public static void moveFiles(File source, FilenameFilter filter, File destination) {
+ File[] files = source.listFiles(filter);
+
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isFile()) {
+ files[i].renameTo(new File(destination, files[i].getName()));
+ }
+ }
+ }
+
+ public static String padLeading(String str, char c, int n) {
+ char[] chars = new char[n];
+ int pos = Math.min(n, str.length());
+ str.getChars(0, pos, chars, n - pos);
+ for (int i = 0; i < n - pos; chars[i++] = c) {
+ // must leave empty block here so the following line won't become
+ // part of the loop
+ }
+ return new String(chars);
+ }
+
+ public static String padTrailing(String str, char c, int n) {
+ char[] chars = new char[n];
+ int pos = Math.min(n, str.length());
+ str.getChars(0, pos, chars, 0);
+ for (int i = pos; i < n; chars[i++] = c) {
+ // must leave empty block here so the following line won't become
+ // part of the loop
+ }
+ return new String(chars);
+ }
+
+ public static int printAndExec(String[] callAndArgs) {
+ return printAndExec(callAndArgs, null, new BufferedWriter(new PrintWriter(System.out, true)));
+ }
+
+ public static int printAndExec(String[] callAndArgs, File dir) {
+ return printAndExec(callAndArgs, dir, new PrintWriter(System.out, true));
+ }
+
+ public static int printAndExec(String[] callAndArgs, File dir, Writer output) {
+ try {
+ for (int j = 0; j < callAndArgs.length; j++) {
+ output.write(callAndArgs[j] + " ");
+ }
+ output.write("\n");
+ output.flush();
+
+ return Lib.handleProcess(runtime.exec(callAndArgs, null, dir), output);
+ } catch (IOException ex) {
+ System.err.println("error: " + ex);
+ return -1;
+ }
+ }
+
+ public static ArrayList<String> readListFromDir(File directory, FilenameFilter filter, boolean keepExtension) {
+ ArrayList<String> list = new ArrayList<String>(400);
+
+ if (directory == null) {
+ System.out.println("Invalid path: " + directory);
+ return list;
+ }
+
+ File[] files = directory.listFiles(filter);
+ if (files == null) {
+ System.out.println("Invalid path: " + directory);
+ return list;
+ }
+ if (files.length > 0) {
+ Arrays.sort(files);
+ }
+
+ if (keepExtension) {
+ for (int i = 0; i < files.length; i++) {
+ list.add(files[i].getName());
+ }
+ } else {
+ for (int i = 0; i < files.length; i++) {
+ list.add(Lib.removeExtension(files[i].getName()));
+ }
+ }
+
+ return list;
+ }
+
+ public static ArrayList<String> readListFromDir(String directory, FilenameFilter filter) {
+ return readListFromDir(new File(directory), filter, false);
+ }
+
+ public static ArrayList<String> readListFromFile(File file, boolean keepExtension) throws IOException {
+ BufferedReader in = new BufferedReader(new FileReader(file));
+ ArrayList<String> list = new ArrayList<String>(120);
+
+ String line = null;
+
+ if (keepExtension) {
+ while ((line = in.readLine()) != null) {
+ list.add(line);
+ }
+ } else {
+ while ((line = in.readLine()) != null) {
+ list.add(Lib.removeExtension(line));
+ }
+ }
+ in.close();
+ return list;
+ }
+
+ public static ArrayList<String> readListFromFile(String file) throws IOException {
+ return readListFromFile(new File(file), true);
+ }
+
+ public static boolean isLink(File file) {
+ if (!file.exists()) {
+ return true;
+ }
+ try {
+ return !file.getAbsolutePath().equals(file.getCanonicalPath());
+ } catch (IOException ex) {
+ return true;
+ }
+ }
+
+ public static List<File> recursivelyListFilesAndDirectories(ArrayList<File> fileList, File rootPath, Pattern filePathP, boolean includeDirectories) {
+ LinkedList<File> dirList = new LinkedList<File>();
+ dirList.add(rootPath);
+
+ Matcher fileNameM = null;
+ if (filePathP != null) {
+ fileNameM = filePathP.matcher("");
+ }
+
+ while (!dirList.isEmpty()) {
+ File parent = dirList.removeFirst();
+ if (parent == null) {
+ System.out.println("Invalid path.");
+ continue;
+ }
+
+ if (parent.getName().startsWith(".Rational")) {
+ continue;
+ }
+
+ File[] files = parent.listFiles();
+ if (files == null) {
+ System.out.println("Invalid path: " + parent);
+ continue;
+ }
+
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory()) {
+ dirList.add(files[i]);
+ if (includeDirectories) {
+ fileList.add(files[i]);
+ }
+ } else { // else is a file
+ if (fileNameM == null) {
+ fileList.add(files[i]);
+ } else {
+ fileNameM.reset(files[i].getPath());
+ if (fileNameM.matches()) {
+ fileList.add(files[i]);
+ }
+ }
+ }
+ }
+ }
+ return fileList;
+ }
+
+ /**
+ * Returns an array list of File objects
+ *
+ * @param fileList
+ * @param rootPath
+ * @param fileNameP
+ * @return List
+ */
+ public static List<File> recursivelyListFiles(ArrayList<File> fileList, File rootPath, Pattern filePathP) {
+ return recursivelyListFilesAndDirectories(fileList, rootPath, filePathP, false);
+ }
+
+ public static List<File> recursivelyListFiles(File rootPath, Pattern fileNameP) {
+ return recursivelyListFiles(new ArrayList<File>(400), rootPath, fileNameP);
+ }
+
+ /**
+ * Assumptions: block comments are not nested and comment blocks have an ending Note: may be fooled by string
+ * literals that contains the block comment indicators
+ *
+ * @param charBuf
+ * @return CharBuffer
+ */
+ public static CharBuffer stripBlockComments(CharBuffer charBuf) {
+ char[] chars = charBuf.array();
+ int i = 0;
+ int k = 0;
+
+ try {
+ while (i < chars.length) {
+ if (chars[i] == '/' && chars[i + 1] == '*') {
+ i += 2;
+ while (!(chars[i++] == '*' && chars[i] == '/')) {
+ // must leave empty block here so the following line
+ // won't become part of the loop
+ }
+ i++;
+ } else {
+ chars[k++] = chars[i++];
+ }
+ }
+ charBuf.limit(k);
+ return charBuf;
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ throw new IllegalArgumentException("Incorrectly formatted comments.");
+ }
+ }
+
+ /**
+ * Remove the file extension from the file path
+ *
+ * @param filepath
+ * @return modified file path
+ */
+ public static String removeExtension(String filepath) {
+ String ext = getExtension(filepath);
+ if (ext != null && ext.length() > 0) {
+ filepath = filepath.substring(0, filepath.length() - (ext.length() + 1));
+ }
+ return filepath;
+ }
+
+ /**
+ * Determine if file is a compressed file
+ *
+ * @param file to check
+ * @return <b>true</b> if the files is a compressed file
+ */
+ public static boolean isCompressed(File file) {
+ boolean toReturn = false;
+ String ext = getExtension(file.getAbsolutePath());
+ if (ext.equals("zip")) {
+ toReturn = true;
+ }
+ return toReturn;
+ }
+
+ // replaces the first capturing group of the match in fileToModify with
+ // replaceSeq and write this back to fileToModify
+ public static boolean updateFile(File fileToModify, Pattern pattern, CharSequence replaceSeq) throws IOException {
+ CharBuffer modifyBuf = Lib.fileToCharBuffer(fileToModify);
+
+ Matcher matcher = pattern.matcher(modifyBuf);
+ if (!matcher.find()) {
+ System.out.println(fileToModify.getPath() + " does not contain the pattern: " + pattern.pattern());
+ return false;
+ }
+ CharBuffer topSection = (CharBuffer) modifyBuf.subSequence(0, matcher.start(1)); // everything
+ // before the
+ // pattern
+ CharBuffer bottomSection = null;
+ int bottomLen = 0;
+ if (matcher.end(1) != modifyBuf.length()) {
+ bottomSection = (CharBuffer) modifyBuf.subSequence(matcher.end(1), modifyBuf.length());
+ bottomLen = bottomSection.length();
+ }
+
+ CharBuffer outBuf = CharBuffer.allocate(topSection.length() + replaceSeq.length() + bottomLen);
+ outBuf.put(topSection);
+ if (replaceSeq instanceof String) {
+ outBuf.put((String) replaceSeq);
+ } else if (replaceSeq instanceof CharBuffer) {
+ outBuf.put((CharBuffer) replaceSeq);
+ } else {
+ outBuf.put(replaceSeq.toString());
+ }
+ if (bottomSection != null) {
+ outBuf.put(bottomSection);
+ }
+ Lib.writeCharBufferToFile(outBuf, fileToModify);
+
+ return true;
+ }
+
+ public static boolean updateFile(File fileToModify, Pattern pattern, File original) throws IOException {
+ return updateFile(fileToModify, pattern, fileToCharBuffer(original));
+ }
+
+ public static void writeCharBufferToFile(CharBuffer charBuf, File outFile) throws IOException {
+ writeCharsToFile(charBuf.array(), outFile);
+ }
+
+ public static void writeCharsToFile(char[] chars, File outFile) throws IOException {
+ FileWriter out = new FileWriter(outFile);
+ out.write(chars, 0, chars.length);
+ out.close();
+ }
+
+ public static void writeStringToFile(String str, File outFile) throws IOException {
+ OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8");
+ char[] chars = str.toCharArray();
+ out.write(chars, 0, chars.length);
+ out.close();
+ }
+
+ public static String getBasePath() {
+ return Lib.getBasePath(Lib.class);
+ }
+
+ public static String getDateTimeString() {
+ return new SimpleDateFormat("yyyy-MM-dd_hh-mm").format(new Date());
+ }
+
+ public static String getJarPath(Class<Lib> base) {
+ // the leading '/' tells getResource not to append the package name
+ // (instead the leading / is just stripped off)
+ String className = "/" + base.getName().replace('.', '/') + ".class";
+ String path = base.getResource(className).getPath();
+
+ int pos = path.lastIndexOf("!");
+ if (pos == -1) { // class is not in a jar file
+ return null;
+ } else { // class is in a jar file
+ String jarpath = path.substring("file:".length(), pos);
+ return jarpath.replaceAll("%20", " ");
+ }
+ }
+
+ /**
+ * @param base
+ * @return The path which was used to load the class file. If the file was loaded from a .jar, then the full path to
+ * the jar. If the file was loaded from a .class, then the path up to the root of the package.
+ */
+ public static String getClassLoadPath(Class<?> base) {
+ /*
+ * Using the getProtectionDomain() method seems to be yield more consistent results than
+ * getResource(className).getPath(); particularly when being run with the Eclipse class
+ * loader. It was found that the Eclipse class loader did not always return the full path when
+ * asked for the resource.
+ */
+
+ ProtectionDomain pd = base.getProtectionDomain();
+ CodeSource cs = pd.getCodeSource();
+ URL csLoc = cs.getLocation();
+ String path = csLoc.getPath();
+ path = path.replaceAll("%20", " ");
+ return path;
+ }
+
+ public static String getBasePath(Class<?> base) {
+ String path = getClassLoadPath(base);
+ path = path.replaceAll("%20", " ");
+
+ if (path.endsWith(".jar")) {
+ int end = path.lastIndexOf('/');
+ path = path.substring(0, end);
+ }
+ return path;
+
+ }
+
+ public static URL resolveToUrl(String path) {
+ URL url = null;
+ System.out.println("resolveToUrl: " + path);
+ if (path != null && !path.equals("")) {
+ if (path.indexOf("://") == -1) { // if not a full URL yet
+ if (!path.startsWith("/")) { // if not absolute then prepend
+ // base path
+ try {
+ path = new File(Lib.basePath + "/" + path).getCanonicalPath();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ path = "file://" + path;
+ }
+ try {
+ url = new URL(path);
+ } catch (MalformedURLException ex) {
+ ex.printStackTrace();
+ }
+ }
+ return url;
+ }
+
+ public static String escapeForRegex(String text) {
+ char[] chars = text.toCharArray();
+ StringBuffer strB = new StringBuffer(chars.length + 5);
+
+ for (int i = 0; i < chars.length; i++) {
+ switch (chars[i]) {
+ case '\\':
+ case '[':
+ case ']':
+ case '.':
+ case '{':
+ case '}':
+ case '^':
+ case '$':
+ case '?':
+ case '*':
+ case '+':
+ case '|':
+ strB.append('\\');
+ }
+ strB.append(chars[i]);
+ }
+ return strB.toString();
+ }
+
+ public static String determineGroup() {
+ try {
+ Process proc =
+ Runtime.getRuntime().exec(
+ new String[] {"/usr/bin/bash", "-c", "touch whichGroup; ls -g whichGroup; rm whichGroup"}, null,
+ new File("/tmp"));
+ BufferedReader inOutput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+ String line = inOutput.readLine();
+ return line.substring(15, line.indexOf(' ', 16)); // 15 based on
+ // format of
+ // line printed
+ // by ls
+ } catch (IOException ex) {
+ System.out.println(ex);
+ return "no group";
+ }
+ }
+
+ /**
+ * Returns a list of the arguments in the source String passed. It assumes that the first character is a '(' and
+ * matches till it finds the matching ')'.
+ *
+ * @param source
+ * @return String[]
+ */
+ public static String[] getArguments(String source) {
+ ArrayList<String> theResults = new ArrayList<String>();
+ try {
+ if (source.charAt(0) != '(') {
+ System.err.println("In getArguments, first char must be \'(\'.");
+ return null;
+ }
+
+ int currentArg = 1;
+ int startPos = 1;
+ int parens = 0;
+ boolean foundValidChar = false;
+
+ for (int i = 1; i < source.length(); i++) {
+ char theChar = source.charAt(i);
+
+ if (theChar == '(')
+ parens++;
+ else if (theChar == ')') {
+ parens--;
+ if (parens < 0) {
+ theResults.add(source.substring(startPos, i));
+ break;
+ }
+ } else if (theChar == ',' && parens == 0) {
+ theResults.add(source.substring(startPos, i));
+ startPos = i + 1;
+ currentArg++;
+ foundValidChar = false;
+ } else if (!foundValidChar) {
+ if (Character.isWhitespace(theChar))
+ startPos++;
+ else
+ foundValidChar = true;
+ }
+ }
+
+ String[] theTrueResults = new String[theResults.size()];
+ theResults.toArray(theTrueResults);
+
+ if (theTrueResults.length != currentArg) System.err.println("In getArguments, number of argument mismatch.");
+
+ return theTrueResults;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public static int getArgsLength(String source) {
+ try {
+ if (source.charAt(0) != '(') {
+ System.err.println("In getArguments, first char must be \'(\'.");
+ return -1;
+ }
+ int parens = 0;
+
+ for (int i = 1; i < source.length(); i++) {
+ char theChar = source.charAt(i);
+
+ if (theChar == '(')
+ parens++;
+ else if (theChar == ')') {
+ parens--;
+ if (parens < 0) {
+ return i - 1;
+ }
+ }
+ }
+
+ System.err.println("In getArguments, problem occurred.");
+ return -1;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return -1;
+ }
+ }
+
+ /**
+ * Returns a list of Strings representing each comma separated string in the string passed. It ignores commas inside
+ * () or {}.
+ *
+ * @param source
+ * @return String[]
+ */
+ public static String[] getCommaSeparatedItems(String source) {
+ ArrayList<String> theResults = new ArrayList<String>();
+ int startPos = 0;
+ int parensCount = 0;
+
+ for (int i = 0; i < source.length(); i++) {
+ char theChar = source.charAt(i);
+
+ if (theChar == '(' || theChar == '{')
+ parensCount++;
+ else if (theChar == ')' || theChar == '}')
+ parensCount--;
+ else if (parensCount == 0 && theChar == ',') {
+ theResults.add(source.substring(startPos, i).trim());
+ startPos = i + 1;
+ }
+ }
+ theResults.add(source.substring(startPos).trim());
+ String[] results = new String[theResults.size()];
+ theResults.toArray(results);
+ return results;
+ }
+
+ public static String getCommaString(Collection<String> strs) {
+ StringBuffer sb = new StringBuffer();
+ for (String str : strs)
+ sb.append(str + ", ");
+ return sb.toString().replaceFirst(", ", "");
+ }
+
+ public static String getCommaString(String[] strs) {
+ StringBuffer sb = new StringBuffer();
+ for (String str : strs)
+ sb.append(str + ", ");
+ return sb.toString().replaceFirst(", ", "");
+ }
+
+ /**
+ * Finds the index of the closing bracket for a function.
+ *
+ * @param start -the index of the character AFTER the opening bracket for the function
+ * @param seq -sequence containing the local function
+ * @return -the index of the matching bracket to the opening bracket of this function
+ */
+ public static int findTheEnd(int start, CharSequence seq) {
+ int stack = 1;
+ char[] array = seq.subSequence(start, seq.length()).toString().toCharArray();
+ int i;
+ // print( "checking: " + seq.subSequence(start,
+ // seq.length()).toString());
+ for (i = 0; i < array.length; i++) {
+ // System.out.print( array[i]);
+ if (array[i] == '/' && array[i + 1] == '*') {
+
+ while (array[i] != '*' || array[i + 1] != '/') {
+ i++;
+ }
+ }
+ if (array[i] == '"') {
+ i++;
+ while (array[i] != '"' || array[i - 1] == '\\') {
+ i++;
+ }
+ }
+ if (array[i] == '{') {
+ stack++;
+
+ } else if (array[i] == '}') {
+ stack--;
+
+ }
+ if (stack == 0) {
+ return start + i - 1;
+ }
+ }
+ return start + i - 1;
+
+ }
+
+ public static final URL getUrlFromString(String path) throws MalformedURLException {
+ if (!path.matches("(file:/|file://|http://|C:).*")) {
+ return new URL("file://" + path);
+ }
+ return new URL(path);
+ }
+
+ public static final URL[] getUrlFromString(String[] path) throws MalformedURLException {
+ URL[] urls = new URL[path.length];
+ for (int i = 0; i < urls.length; i++) {
+ urls[i] = getUrlFromString(path[i]);
+ }
+ return urls;
+ }
+
+ public static final String convertToJavaClassName(String name) {
+ ChangeSet changeSet = new ChangeSet(name);
+ Matcher matcher = Pattern.compile("_([a-zA-Z])").matcher(changeSet.toString());
+
+ changeSet.replace(0, 1, Character.toUpperCase(name.charAt(0)));
+ while (matcher.find())
+ changeSet.replace(matcher.start(), matcher.end(), Character.toUpperCase(matcher.group(1).charAt(0)));
+
+ return changeSet.applyChangesToSelf().toString();
+ }
+
+ /**
+ * This method takes in any name separated by underscores and converts it into a java standard variable name.
+ *
+ * @param name
+ * @return java variable name
+ */
+ public static final String convertToJavaVariableName(String name) {
+ name = name.toLowerCase();
+ StringBuffer sb = new StringBuffer();
+ char[] chars = name.toCharArray();
+ for (int i = 0; i < chars.length; i++) {
+ if (chars[i] == '_') {
+ if (chars.length > i + 1 && chars[i + 1] != '_') {
+ sb.append(Character.toUpperCase(chars[i + 1]));
+ i++;
+ }
+ } else
+ sb.append(chars[i]);
+ }
+ return sb.toString();
+ }
+
+ public static URL getJarFileURL(File directory, String title, String version) throws IOException {
+ if (!directory.isDirectory()) {
+ throw new IllegalArgumentException(directory.getPath() + " is not a valid directory.");
+ }
+ File[] jars = directory.listFiles(new MatchFilter(".*\\.jar"));
+ for (int i = 0; i < jars.length; i++) {
+ JarFile jar = new JarFile(jars[i]);
+ Attributes attributes = jar.getManifest().getMainAttributes();
+ String jarTitle = attributes.getValue("Implementation-Title");
+ String jarVersion = attributes.getValue("Implementation-Version");
+ if (jarTitle != null && jarVersion != null && jarTitle.equals(title) && jarVersion.equals(version)) {
+ return jars[i].toURI().toURL();
+ }
+ }
+ throw new IllegalArgumentException("The specified version: " + version + " for " + title + " was not found.");
+ }
+
+ public static URL[] getClasspath() throws MalformedURLException {
+ String[] strPaths = System.getProperty("java.class.path").split(System.getProperty("path.separator"));
+ URL[] urlPaths = new URL[strPaths.length];
+ for (int i = 0; i < strPaths.length; i++) {
+ urlPaths[i] = new File(strPaths[i]).toURI().toURL();
+ }
+ return urlPaths;
+ }
+
+ public static String getJarFileVersion(String jarFilePath) throws IOException {
+ Manifest manifest;
+ File jarFile = new File(jarFilePath);
+ if (!jarFile.isFile()) {// maybe it's an http connection
+ try {
+ URL u = new URL(jarFilePath);
+ URLConnection uc = u.openConnection();
+ JarInputStream jis = new JarInputStream(uc.getInputStream());
+ manifest = jis.getManifest();
+ } catch (Exception ex) {
+ throw new IllegalArgumentException(jarFilePath + " is not a valid file or URL.");
+ }
+ } else {
+ manifest = new JarFile(jarFile).getManifest();
+ }
+ return manifest.getMainAttributes().getValue("Implementation-Version");
+ }
+
+ public static String getElapseString(long startTime) {
+ return String.valueOf((System.currentTimeMillis() - startTime) / 1000.0) + " secs";
+ }
+
+ /**
+ * Determine is OS is windows
+ *
+ * @return <b>true</b> if OS is windows
+ */
+ public static boolean isWindows() {
+ return System.getProperty("os.name").indexOf("indows") != -1;
+ }
+
+ public static void writeBytesToFile(byte[] data, File file) throws IOException {
+ OutputStream os = new FileOutputStream(file);
+ try {
+ os.write(data);
+ } finally {
+ os.close();
+ }
+ }
+
+ public static void extractJarEntry(File jarFile, File destination, String entry) throws IOException {
+ if (!destination.getParentFile().exists()) {
+ destination.getParentFile().mkdirs();
+ }
+ int BUFFER = 2048;
+ try {
+ JarFile jarfile = new JarFile(jarFile.getAbsolutePath());
+ JarEntry jarEntry = jarfile.getJarEntry(entry);
+ BufferedInputStream is = new BufferedInputStream(jarfile.getInputStream(jarEntry));
+ int count;
+ long total = 0;
+ byte data[] = new byte[BUFFER];
+ FileOutputStream fos = new FileOutputStream(destination);
+ BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
+ while ((count = is.read(data, 0, BUFFER)) != -1) {
+ dest.write(data, 0, count);
+ total += BUFFER;
+ }
+ dest.flush();
+ dest.close();
+ is.close();
+ } catch (Exception ex) {
+ String information =
+ "JarFile: " + (jarFile != null ? jarFile.getAbsolutePath() : "NULL") + "\n" + "Entry: " + (entry != null ? entry.toString() : "NULL") + "\n" + "Destination: " + (destination != null ? destination.getAbsoluteFile().toString() : "NULL") + "\n";
+ throw new IOException(information + ex.getMessage());
+ }
+ }
+
+ public static byte[] compressStream(InputStream in, String name) throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ZipOutputStream out = null;
+ try {
+ out = new ZipOutputStream(bos);
+ // Add ZIP entry to output stream.
+ out.putNextEntry(new ZipEntry(name));
+ byte[] buf = new byte[1024];
+ int count = -1;
+ while ((count = in.read(buf)) > 0) {
+ out.write(buf, 0, count);
+ }
+ } finally {
+ if (out != null) {
+ out.closeEntry();
+ out.close();
+ }
+ }
+ return bos.toByteArray();
+ }
+
+ public static byte[] compressFile(File file) throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ZipOutputStream outputStream = new ZipOutputStream(bos);
+ compressFile(null, file, outputStream);
+ outputStream.closeEntry();
+ outputStream.close();
+ return bos.toByteArray();
+ }
+
+ private static void compressFile(String basePath, File file, ZipOutputStream outputStream) throws IOException {
+ FileInputStream inputStream = null;
+ try {
+ byte[] buffer = new byte[4096];
+ int count = -1;
+ inputStream = new FileInputStream(file);
+ String entryName = file.getPath();
+ if (Strings.isValid(basePath) && entryName.startsWith(basePath)) {
+ if (basePath.endsWith(File.separator) != true) {
+ basePath = basePath + File.separator;
+ }
+ entryName = entryName.replace(basePath, "");
+ }
+ ZipEntry entry = new ZipEntry(entryName);
+ outputStream.putNextEntry(entry);
+ while ((count = inputStream.read(buffer)) != -1) {
+ outputStream.write(buffer, 0, count);
+ }
+ } finally {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ }
+ }
+
+ private static void compressDirectory(String basePath, File source, ZipOutputStream outputStream, boolean includeSubDirectories) throws IOException {
+ File[] children = source.listFiles();
+ for (File file : children) {
+ if (file.isDirectory() != true) {
+ compressFile(basePath, file, outputStream);
+ } else {
+ if (includeSubDirectories) {
+ compressDirectory(basePath, file, outputStream, includeSubDirectories);
+ }
+ }
+ }
+ }
+
+ public static void compressDirectory(File directory, String zipTarget, boolean includeSubDirectories) throws IOException, IllegalArgumentException {
+ if (directory.isDirectory() != true) {
+ throw new IllegalArgumentException(String.format("Error source is not a directory: [%s]", directory));
+ }
+ if (Strings.isValid(zipTarget) != true) {
+ throw new IllegalArgumentException("Error target zip filename is invalid");
+ }
+ ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipTarget));
+ compressDirectory(directory.getPath(), directory, out, includeSubDirectories);
+ out.close();
+ }
+
+ public static void decompressStream(InputStream inputStream, File targetDirectory) throws IOException {
+ ZipInputStream zipInputStream = null;
+ try {
+ zipInputStream = new ZipInputStream(inputStream);
+ if (!targetDirectory.exists()) {
+ targetDirectory.mkdirs();
+ }
+ ZipEntry entry = null;
+ while ((entry = zipInputStream.getNextEntry()) != null) {
+ String zipEntryName = entry.getName();
+
+ OutputStream outputStream = null;
+ try {
+ File target = new File(targetDirectory, zipEntryName);
+ if (target != null && !entry.isDirectory()) {
+ File parent = target.getParentFile();
+ if (parent != null && !parent.exists()) {
+ parent.mkdirs();
+ }
+ outputStream = new BufferedOutputStream(new FileOutputStream(target));
+ inputStreamToOutputStream(zipInputStream, outputStream);
+ }
+ } finally {
+ if (outputStream != null) {
+ outputStream.close();
+ }
+ }
+ }
+ } finally {
+ if (zipInputStream != null) {
+ zipInputStream.close();
+ }
+ }
+ }
+
+ public static byte[] decompressBytes(InputStream inputStream) throws IOException {
+ ByteArrayOutputStream out = null;
+ // Open the ZIP file
+ ZipInputStream in = new ZipInputStream(inputStream);
+
+ // Get the first entry
+ in.getNextEntry();
+
+ // Open the output file
+ out = new ByteArrayOutputStream();
+
+ // Transfer bytes from the ZIP file to the output file
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+
+ // Close the streams
+ out.close();
+ in.close();
+ return out.toByteArray();
+ }
+
+ public static void chmod777(File file) {
+ if (file == null || !file.exists()) return;
+ try {
+ String command = "chmod 777 " + file.getAbsolutePath();
+ Runtime r = Runtime.getRuntime();
+ Process p = r.exec(command);
+
+ Lib.handleProcess(p);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
+ }
+
+ public static String getSortedJavaArrayInitializer(String[] strings) {
+ Arrays.sort(strings);
+ StringBuilder strB = new StringBuilder();
+ strB.append("new String[] {\"");
+ for (String element : strings) {
+ strB.append(element);
+ strB.append("\", \"");
+ }
+ strB.replace(strB.length() - 3, strB.length(), "};");
+ return strB.toString();
+ }
+}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Network.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Network.java new file mode 100644 index 00000000000..9f6485404aa --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Network.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class Network { + + public static InetAddress getValidIP() throws UnknownHostException { + InetAddress[] addrs; + // Cannot just grab the localhost address because the user might have more than one NIC. + addrs = getLocalNetworkAdapters(); + + for (int j = 0; j < addrs.length; j++) { + if (!addrs[j].getHostAddress().matches("192.*")) { + return addrs[j]; + } + } + return addrs[0]; + } + + public static InetAddress[] getLocalNetworkAdapters() throws UnknownHostException { + return InetAddress.getAllByName(InetAddress.getLocalHost().getHostName()); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Objects.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Objects.java new file mode 100644 index 00000000000..0fc6e834c72 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Objects.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +/** + * Utility class for methods useful to all Object's + * + * @author Robert A. Fisher + */ +public final class Objects { + + /** + * Produces a hash code that uses all of the supplied values. This method is guaranteed to return the same value + * given the same input. + * + * @param PRIME_1 + * @param PRIME_2 + * @param data + */ + public static int hashCode(int PRIME_1, int PRIME_2, Object... data) { + int result = PRIME_1; + + for (Object val : data) { + result = PRIME_2 * result + val.hashCode(); + } + + return result; + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/OseeProperties.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/OseeProperties.java new file mode 100644 index 00000000000..dbcac75b2b0 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/OseeProperties.java @@ -0,0 +1,160 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.util;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.logging.Level;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class OseeProperties {
+ private static final String OSEE_LOG_DEFAULT = "osee.log.default";
+ private static final String OSEE_JINI_SERVICE_GROUPS = "osee.jini.lookup.groups";
+ private static final String OSEE_JINI_FORCED_REGGIE_SEARCH = "osee.jini.forced.reggie.search";
+ private static final String OSEE_PORT_SCAN_START_PORT = "osee.port.scanner.start.port";
+
+ // These need to only be used by the server but for now remain here until OSEE clients stop accessing the database directly
+ public static final String OSEE_DB_CONNECTION_ID = "osee.db.connection.id";
+ protected static final String OSEE_APPLICATION_SERVER_DATA = "osee.application.server.data";
+ private static final String OSGI_PORT_PROPERTY = "org.osgi.service.http.port";
+
+ protected OseeProperties() {
+ }
+
+ public static int getOseePortScannerStartPort() {
+ int toReturn = 18000;
+ String startPort = System.getProperty(OSEE_PORT_SCAN_START_PORT, "18000");
+ try {
+ toReturn = Integer.parseInt(startPort);
+ } catch (Exception ex) {
+ toReturn = 18000;
+ }
+ return toReturn;
+ }
+
+ /**
+ * Get the default OSEE logging level. The default level is WARNING.
+ *
+ * @return default logging level
+ */
+ public static Level getOseeLogDefault() {
+ Level toReturn = Level.WARNING;
+ String level = System.getProperty(OSEE_LOG_DEFAULT, "WARNING");
+ try {
+ toReturn = Level.parse(level);
+ } catch (Exception ex) {
+ toReturn = Level.WARNING;
+ }
+ return toReturn;
+ }
+
+ /**
+ * Get location for OSEE application server binary data
+ *
+ * @return OSEE application server binary data path
+ */
+ public static String getOseeApplicationServerData() {
+ String toReturn = System.getProperty(OSEE_APPLICATION_SERVER_DATA);
+ if (toReturn == null) {
+ String userHome = System.getProperty("user.home");
+ if (Strings.isValid(userHome)) {
+ toReturn = userHome;
+ }
+ }
+ return toReturn;
+ }
+
+ /**
+ * Retrieve the application server port
+ *
+ * @return the application server port
+ */
+ public static int getOseeApplicationServerPort() {
+ return Integer.valueOf(System.getProperty(OSGI_PORT_PROPERTY, "-1"));
+ }
+
+ /**
+ * OSEE database information id to use for default database connections.
+ *
+ * @return the default database information id to use for database connections.
+ */
+ public static String getOseeDbConnectionId() {
+ return System.getProperty(OSEE_DB_CONNECTION_ID);
+ }
+
+ /**
+ * Retrieves the JINI Groups this system is a part of.
+ *
+ * @return JINI service groups
+ */
+ public static String getOseeJiniServiceGroups() {
+ return System.getProperty(OSEE_JINI_SERVICE_GROUPS);
+ }
+
+ /**
+ * Sets the JINI Groups this system is a part of.
+ *
+ * @param JINI service groups
+ */
+ public static void setOseeJiniServiceGroups(String toStore) {
+ System.setProperty(OSEE_JINI_SERVICE_GROUPS, toStore);
+ }
+
+ /**
+ * @return whether forced reggie search is enabled
+ */
+ public static boolean isOseeJiniForcedReggieSearchEnabled() {
+ return Boolean.valueOf(System.getProperty(OSEE_JINI_FORCED_REGGIE_SEARCH));
+ }
+
+ private void toStringHelper(List<String> list, Class<?> clazz) {
+ Field[] fields = clazz.getDeclaredFields();
+ for (Field field : fields) {
+ int mod = field.getModifiers();
+ if (Modifier.isStatic(mod) && Modifier.isFinal(mod)) {
+ boolean wasModified = false;
+ try {
+ if (!field.isAccessible()) {
+ field.setAccessible(true);
+ wasModified = true;
+ }
+ Object object = field.get(this);
+ if (object instanceof String) {
+ String value = (String) object;
+ list.add(String.format("%s: %s", value, System.getProperty(value)));
+ }
+ } catch (Exception ex) {
+ // DO NOTHING
+ } finally {
+ if (wasModified) {
+ field.setAccessible(false);
+ }
+ }
+ }
+ }
+ Class<?> superClazz = clazz.getSuperclass();
+ if (superClazz != null) {
+ toStringHelper(list, superClazz);
+ }
+ }
+
+ public String toString() {
+ List<String> list = new ArrayList<String>();
+ toStringHelper(list, getClass());
+ Collections.sort(list);
+ return StringFormat.listToValueSeparatedString(list, "\n");
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Readers.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Readers.java new file mode 100644 index 00000000000..0a3ebcf8181 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Readers.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +import java.io.IOException; +import java.io.Reader; +import java.util.Arrays; + +/** + * @author Robert A. Fisher + */ +public final class Readers { + + /** + * Forward a reader until just after the balanced close of the given xml element name. It is assumed that the + * balanced open end of the element was just read off of the reader. + * + * @param reader The reader to pull the data from + * @param appendable If supplied, all data read from the reader is appended to the appendable + * @param elementName The name of the element, including the namespace if applicable + * @throws IllegalArgumentException If reader is null + * @throws IllegalArgumentException If elementName is null + * @throws IllegalStateException If the balanced closing tag is not found before the reader is emptied + * @throws IOException + */ + public static final void xmlForward(Reader reader, Appendable appendable, CharSequence elementName) throws IOException { + if (reader == null) throw new IllegalArgumentException("reader can not be null"); + if (elementName == null) throw new IllegalArgumentException("elementName can not be null"); + + final String CLOSE_TAG = "</" + elementName + ">"; + final String EMPTY_TAG = "<" + elementName + "/>"; + final String OPEN_TAG = "<" + elementName + ">"; + final String OPEN_TAG_WITH_ATTR = "<" + elementName + " "; + final CharSequence[] TAGS = new CharSequence[] {CLOSE_TAG, EMPTY_TAG, OPEN_TAG, OPEN_TAG_WITH_ATTR}; + + int elementDepthCount = 1; + StringBuilder read = null; + if (appendable != null) { + read = new StringBuilder(); + } + + CharSequence stopTag; + + while (elementDepthCount > 0) { + if ((stopTag = forward(reader, appendable, TAGS)) == null) { + throw new IllegalStateException("end of reader met when expecting an end of a tag"); + } + + if (stopTag == CLOSE_TAG) { + elementDepthCount--; + } else if (stopTag == OPEN_TAG) { + elementDepthCount++; + } else if (stopTag == OPEN_TAG_WITH_ATTR) { + if (forward(reader, (Appendable) read, ">") == null) { + throw new IllegalStateException("end of reader met when expecting >"); + } + + if (!read.toString().endsWith("/>")) { + elementDepthCount++; + } + + if (appendable != null) { + appendable.append(read); + read.setLength(0); + } + } else if (stopTag == EMPTY_TAG) { + // no effect on the stack count + } else { + throw new IllegalStateException("unexpected element returned"); + } + } + } + + /** + * Forward a reader to just after the specified CharSequence. + * + * @return The sequence that was found which stopped the forwarding. A null is returned if no sequence was found + * @throws IOException + * @throws IllegalArgumentException if any parameter is null + * @throws IllegalArgumentException if any of the sequences elements are length zero + */ + public static final CharSequence forward(Reader reader, CharSequence... sequences) throws IOException { + return forward(reader, null, sequences); + } + + /** + * Forward a reader to just after the specified CharSequence. If an appendable is supplied then all characters + * consumed from the reader will be appended to the appendable. + * + * @return The sequence that was found which stopped the forwarding. A null is returned if no sequence was found + * @throws IOException + * @throws IllegalArgumentException if reader is null + * @throws IllegalArgumentException if sequences is null + * @throws IllegalArgumentException if any of the sequences elements are length zero + */ + public static final CharSequence forward(Reader reader, Appendable appendable, CharSequence... sequences) throws IOException { + if (reader == null) throw new IllegalArgumentException("reader can not be null"); + if (sequences == null) throw new IllegalArgumentException("sequences can not be null"); + if (sequences.length == 0) throw new IllegalArgumentException("must provide at least one sequence"); + + // Precalculate all of the lengths and check for unacceptable data + int[] lengths = new int[sequences.length]; + for (int x = 0; x < sequences.length; x++) { + if (sequences[x] == null) { + throw new IllegalArgumentException("character sequence can not be null"); + } + + lengths[x] = sequences[x].length(); + + if (lengths[x] == 0) { + throw new IllegalArgumentException("character sequence can not have length zero"); + } + } + + int[] seqIndex = new int[sequences.length]; + Arrays.fill(seqIndex, 0); + + char[] buffer = new char[1]; + + while (reader.read(buffer) != -1) { + if (appendable != null) { + appendable.append(buffer[0]); + } + + for (int x = 0; x < sequences.length; x++) { + // Check if the last value read is inline with the next valid character for the sequence + if (sequences[x].charAt(seqIndex[x]) == buffer[0]) { + seqIndex[x]++; + // Check if the whole sequence has been detected in the stream + if (seqIndex[x] == lengths[x]) { + return sequences[x]; + } + } else { + seqIndex[x] = 0; + } + } + } + + return null; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/RegExpressLib.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/RegExpressLib.java new file mode 100644 index 00000000000..d313e0f8ae6 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/RegExpressLib.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +import java.util.regex.Pattern; + +/** + * @author Andy Jury + */ + +public class RegExpressLib { + + public static final Pattern findRegExpressNotInComment(String str) { + + String notInComment = "(?:/\\*.*?\\*/)"; + + return Pattern.compile(notInComment + "|" + str, Pattern.DOTALL); + } + + public static final Pattern findRegExpressNotInQuotes(String str) { + + String notInQuotes = "(?:\".*?[^\\\\]\")"; + + return Pattern.compile(notInQuotes + "|" + str); + } + + public static final Pattern findCMathFunctionNotInQuotes(String str) { + + return findRegExpressNotInQuotes("[^.\\w](" + str + "\\s*?)\\(.*?"); + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Sets.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Sets.java new file mode 100644 index 00000000000..dab3f7048c5 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Sets.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +import java.util.HashSet; +import java.util.Set; + +/** + * Utility methods for <code>Set</code>'s. + * + * @author Robert A. Fisher + */ +public class Sets { + + /** + * Compute the intersection of two sets, and return the resulting set. + * + * @throws IllegalArgumentException if either argument is null. + */ + public static <A extends Object> Set<A> intersect(Set<A> set1, Set<A> set2) { + if (set1 == null) throw new IllegalArgumentException("set1 can not be null."); + if (set2 == null) throw new IllegalArgumentException("set2 can not be null."); + + Set<A> intersection = new HashSet<A>(); + + // Pick the smaller of the two sets as this will be the largest + // possible intersection. + boolean set1Larger = set1.size() > set2.size(); + Set<A> baseSet = set1Larger ? set2 : set1; + Set<A> otherSet = set1Larger ? set1 : set2; + + for (A item : baseSet) + if (otherSet.contains(item)) intersection.add(item); + + return intersection; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/SingletonApplicationInstance.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/SingletonApplicationInstance.java new file mode 100644 index 00000000000..22f6568fe77 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/SingletonApplicationInstance.java @@ -0,0 +1,44 @@ +package org.eclipse.osee.framework.jdk.core.util;
+
+import java.net.BindException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.nio.channels.DatagramChannel;
+
+public class SingletonApplicationInstance {
+
+ private static DatagramChannel lockChannel;
+
+ public static void verifySingleton(int port) throws Exception {
+ if (findOther(port)) {
+ System.out.println("found another instance");
+ } else {
+ System.out.println("no other instance found");
+ }
+ }
+
+
+ private static boolean findOther(int port) throws Exception {
+ InetAddress host = InetAddress.getLocalHost();
+ try {
+ DatagramChannel channel = DatagramChannel.open();
+ channel.configureBlocking(true);
+ InetSocketAddress address = new InetSocketAddress(host, port);
+ channel.socket().bind(address);
+ lockChannel = channel;
+ return false;
+ } catch (BindException e) {
+ return true;
+ }
+ }
+
+ public static void main(String[] args) {
+ try {
+ verifySingleton(32900);
+ System.in.read();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/StringDataSource.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/StringDataSource.java new file mode 100644 index 00000000000..4085c0e4c45 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/StringDataSource.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import javax.activation.DataSource; + +public class StringDataSource implements DataSource { + + private String data; + private String name; + + /** + * @param data + * @param name + */ + public StringDataSource(String data, String name) { + super(); + this.data = data; + this.name = name; + } + + public String getContentType() { + return "text/plain"; + } + + public InputStream getInputStream() throws IOException { + return new ByteArrayInputStream(data.getBytes()); + } + + public String getName() { + return name; + } + + public OutputStream getOutputStream() throws IOException { + throw new UnsupportedOperationException(); + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/StringFormat.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/StringFormat.java new file mode 100644 index 00000000000..8a2c9c3b78f --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/StringFormat.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +import java.util.List; + +public class StringFormat { + + public static String separateWith(String[] items, String separateWith) { + StringBuilder string = new StringBuilder(); + boolean first = true; + for (String item : items) { + if (first) + first = false; + else + string.append(separateWith); + string.append(item); + } + + return string.toString(); + } + + public static String commaSeparate(String[] items) { + return separateWith(items, ","); + } + + public static String listToCommaSeparatedString(List<String> list) { + return commaSeparate(list.toArray(new String[list.size()])); + } + + public static String listToValueSeparatedString(List<String> list, String value) { + return separateWith(list.toArray(new String[list.size()]), value); + } + + public static String padWithLeadingZeroes(String toPad, int length) { + char[] charArray = new char[20]; + int charArrayIndex = charArray.length - 1; + for (int index = toPad.length() - 1; index >= 0; index--, charArrayIndex--) { + charArray[charArrayIndex] = toPad.charAt(index); + } + for (; charArrayIndex >= 0; charArrayIndex--) { + charArray[charArrayIndex] = '0'; + } + return new String(charArray); + } + + public static String truncate(String str, int length) { + return str.substring(0, Math.min(length, str.length())); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Strings.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Strings.java new file mode 100644 index 00000000000..87eba43417f --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Strings.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ + +package org.eclipse.osee.framework.jdk.core.util; + +/** + * @author Jeff C. Phillips + */ +public class Strings { + + /** + * Return string truncated if size > length, otherwise return string + * + * @param string + * @param length + * @return + */ + public static String truncate(String string, int length) { + + if (string.length() > length) { + return string.substring(0, length); + } + + return string; + } + + public static boolean isValid(String value) { + return value != null && value.length() > 0; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/ThreadKeyLocal.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/ThreadKeyLocal.java new file mode 100644 index 00000000000..e7ca34dd266 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/ThreadKeyLocal.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Jeff C. Phillips + * @author Robert A. Fisher + */ +public class ThreadKeyLocal<K, T> { + + private ThreadLocal<Map<K, T>> keyToValueMaps = new ThreadLocal<Map<K, T>>() { + + /* + * (non-Javadoc) + * + * @see java.lang.ThreadLocal#initialValue() + */ + @Override + protected Map<K, T> initialValue() { + return new HashMap<K, T>(); + } + }; + + public T get(K key) { + Map<K, T> map = keyToValueMaps.get(); + + T value = map.get(key); + + if (value == null) { + value = initialValue(); + map.put(key, value); + } + + return value; + } + + public void remove(K key) { + keyToValueMaps.get().remove(key); + } + + public void set(K key, T value) { + keyToValueMaps.get().put(key, value); + } + + /** + * Typically an anonymous inner class will be used and this method will be overridden to provide desired initial + * value. + * + * @return Returns value + */ + protected T initialValue() { + return null; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/benchmark/Benchmark.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/benchmark/Benchmark.java new file mode 100644 index 00000000000..0123b0e7331 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/benchmark/Benchmark.java @@ -0,0 +1,279 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.util.benchmark;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+/**
+ * Takes time measurements and provides some simple statistics. Useful for determining elapsed time between two points
+ * in frequently executed code.<BR>
+ * <P>
+ * <B>NOTE: </B>To enable benchmarking the JVM argument -Dosee.benchmark must be specified otherwise this code does
+ * nothing
+ *
+ * @author Ken J. Aguilar
+ */
+public class Benchmark {
+
+ private static boolean IS_BENCHMARKING_ENABLED = false;
+ private final long threshold;
+ private long totalSamples;
+ private long startTime;
+ private long totalTime;
+ private long exceedCount;
+ private long longestSample;
+ private long shortestSample;
+ private long totalExceedAmount;
+ private static final Vector<Benchmark> list = new Vector<Benchmark>(16);
+ private final HashMap<String, Integer> exceeders = new HashMap<String, Integer>(100);
+ private final String name;
+
+ public Benchmark(String name) {
+ this(name, Long.MAX_VALUE);
+ }
+
+ /**
+ * @param threshold if samples exceed this time (in microseconds) then the exceed count will be incremented
+ */
+ public Benchmark(String name, long threshold) {
+ this.name = name;
+ synchronized (list) {
+ list.add(this);
+ }
+ this.threshold = threshold;
+ totalSamples = 0;
+ totalTime = 0;
+ exceedCount = 0;
+ longestSample = 0;
+ shortestSample = Long.MAX_VALUE;
+ startTime = Long.MIN_VALUE;
+ totalExceedAmount = 0;
+ }
+
+ public static void resetAll() {
+ synchronized (list) {
+ for (Benchmark bm : list) {
+ bm.totalSamples = 0;
+ bm.totalTime = 0;
+ bm.exceedCount = 0;
+ bm.longestSample = 0;
+ bm.shortestSample = Long.MAX_VALUE;
+ bm.startTime = Long.MIN_VALUE;
+ bm.totalExceedAmount = 0;
+ bm.exceeders.clear();
+ }
+ }
+
+ }
+
+ /**
+ * Begins the sample
+ */
+ public void startSample() {
+ if (!isBenchmarkingEnabled()) return;
+ startSample(System.nanoTime());
+ }
+
+ public void startSample(long time) {
+ if (!isBenchmarkingEnabled()) return;
+ startTime = time;
+ }
+
+ public void samplePoint() {
+ if (!isBenchmarkingEnabled()) return;
+ samplePoint(System.nanoTime());
+ }
+
+ /**
+ * Measures time between sample points
+ */
+ public void samplePoint(long time) {
+ if (!isBenchmarkingEnabled()) return;
+ if (startTime == Long.MIN_VALUE) {
+ // this is the first time samplePoint was called
+ startTime = time;
+ } else {
+ final long duration = (time - startTime) / 1000;
+ totalTime += duration;
+ if (duration > threshold) {
+ exceedCount++;
+ totalExceedAmount += threshold - duration;
+ }
+ if (duration > longestSample) {
+ longestSample = duration;
+ }
+ if (duration < shortestSample) {
+ shortestSample = duration;
+ }
+
+ totalSamples++;
+ startTime = time;
+ }
+ }
+
+ public boolean endSample() {
+ if (!isBenchmarkingEnabled()) return false;
+ return endSample(System.nanoTime());
+ }
+
+ /**
+ * Ends the sample. Measures the elapsed time between the start of the sample and the time this method is called.
+ */
+ public boolean endSample(long time) {
+ boolean exceeded = false;
+ if (!isBenchmarkingEnabled()) return exceeded;
+ final long duration = (time - startTime) / 1000;
+ totalTime += duration;
+ if (duration > threshold) {
+ exceedCount++;
+ totalExceedAmount += threshold - duration;
+ exceeded = true;
+ }
+ if (duration > longestSample) {
+ longestSample = duration;
+ }
+ if (duration < shortestSample) {
+ shortestSample = duration;
+ }
+
+ totalSamples++;
+ return exceeded;
+ }
+
+ /**
+ * @return the number of samples that exceeded the threshold
+ */
+ public long getExceedCount() {
+ return exceedCount;
+ }
+
+ /**
+ * @return the longest sample in microseconds
+ */
+ public long getLongestSample() {
+ return longestSample;
+ }
+
+ /**
+ * @return the threshold value in microseconds. If no threshold was set this will return <CODE>Long.MAX_VALUE</CODE>
+ */
+ public long getThreshold() {
+ return threshold;
+ }
+
+ /**
+ * @return the total samples taken
+ */
+ public long getTotalSamples() {
+ return totalSamples;
+ }
+
+ /**
+ * @return the average of the samples in microseconds
+ */
+ public long getAverage() {
+ if (totalSamples > 0) {
+ return totalTime / totalSamples;
+ } else {
+ return Long.MAX_VALUE;
+ }
+ }
+
+ /**
+ * @return the shortest sample taken in microseconds
+ */
+ public long getShortestSample() {
+ return shortestSample;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public long getAverageExceedAmount() {
+ if (exceedCount == 0) {
+ return 0;
+ }
+ return Math.abs(totalExceedAmount / exceedCount);
+ }
+
+ public static void main(String[] args) {
+ Benchmark bm = new Benchmark("unit test", 10000);
+
+ if (isBenchmarkingEnabled()) {
+ System.out.println("benchmarking is enabled");
+ } else {
+ System.out.println("benchmarking is disabled");
+ }
+
+ for (int i = 0; i < 1000; i++) {
+ bm.startSample();
+ try {
+ Thread.sleep((i % 2) == 0 ? 5 : 10);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+ bm.endSample();
+ }
+
+ // Sorry Need to keep this java 1.4 compatible
+ Object[] formatArgs =
+ {new Long(bm.getTotalSamples()), new Float(bm.getLongestSample() / 1000),
+ new Float(bm.getShortestSample() / 1000), new Float(bm.getAverage() / 1000),
+ new Long(bm.getExceedCount())};
+ MessageFormat outmessage =
+ new MessageFormat(
+ "total samples: {0,number,integer}, max time: {1,number,integer}ms, min: {2,number,integer}ms, average: {3,number,integer}ms, exceed count: {4,number,integer}");
+
+ System.out.println(outmessage.format(formatArgs));
+
+ }
+
+ public String toString() {
+ return String.format("%s\t total samples: %d,\t average: %fms,\t max time: %f, min: %fms, exceed count: %d",
+ name, new Long(getTotalSamples()), new Float(getLongestSample() / 1000), new Float(
+ getShortestSample() / 1000), new Float(getAverage() / 1000), new Long(getExceedCount()));
+ }
+
+ public void addExceeder(String exceeder) {
+ Integer c = exceeders.get(exceeder);
+ if (c == null) {
+ exceeders.put(exceeder, 1);
+ } else {
+ exceeders.put(exceeder, c + 1);
+ }
+ }
+
+ public Collection<Map.Entry<String, Integer>> getExceeders() {
+ return exceeders.entrySet();
+ }
+
+ public static List<Benchmark> getAllBenchamrks() {
+ synchronized (list) {
+ return new ArrayList<Benchmark>(list);
+ }
+ }
+
+ public static void setBenchmarkingEnabled(boolean isEnabled) {
+ Benchmark.IS_BENCHMARKING_ENABLED = isEnabled;
+ }
+
+ public static boolean isBenchmarkingEnabled() {
+ return Benchmark.IS_BENCHMARKING_ENABLED;
+ }
+
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/images/Pawprint.jpg b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/images/Pawprint.jpg Binary files differnew file mode 100644 index 00000000000..06752a1ec52 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/images/Pawprint.jpg diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/images/done.gif b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/images/done.gif Binary files differnew file mode 100644 index 00000000000..e4247311cd1 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/images/done.gif diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/images/go.gif b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/images/go.gif Binary files differnew file mode 100644 index 00000000000..7b177f0035a --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/images/go.gif diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/images/not_done.gif b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/images/not_done.gif Binary files differnew file mode 100644 index 00000000000..68d265f91b6 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/images/not_done.gif diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/CharBackedInputStream.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/CharBackedInputStream.java new file mode 100644 index 00000000000..a264209a003 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/CharBackedInputStream.java @@ -0,0 +1,184 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Writer; +import java.nio.BufferUnderflowException; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.charset.CharacterCodingException; +import java.nio.charset.Charset; +import java.nio.charset.CharsetEncoder; +import java.util.LinkedList; + +/** + * @author Ryan D. Brooks + */ +public class CharBackedInputStream extends InputStream implements Appendable { + private LinkedList<ByteBuffer> backers; + private ByteBuffer currentBacker; + private CharsetEncoder encoder; + private Writer writer; + + /** + * @author Ryan D. Brooks + */ + public class InputStreamWriter extends Writer { + + public InputStreamWriter() { + super(); + } + + /** + * @param lock + */ + public InputStreamWriter(Object lock) { + super(lock); + } + + /* (non-Javadoc) + * @see java.io.Writer#write(char[], int, int) + */ + public void write(char[] cbuf, int off, int len) throws IOException { + addBackingSource(cbuf, off, len); + } + + /* (non-Javadoc) + * @see java.io.Flushable#flush() + */ + public void flush() throws IOException { + } + + /* (non-Javadoc) + * @see java.io.Closeable#close() + */ + public void close() throws IOException { + } + + public void write(CharSequence str) throws CharacterCodingException { + addBackingSource(str); + } + + public void write(String str, int off, int len) throws CharacterCodingException { + addBackingSource(str, off, len); + } + } + + /** + * @throws CharacterCodingException + */ + public CharBackedInputStream(CharBuffer source, String encodingName) throws CharacterCodingException { + super(); + this.encoder = Charset.forName(encodingName).newEncoder(); + this.backers = new LinkedList<ByteBuffer>(); + if (source != null) { + addBackingSource(source); + } + } + + public CharBackedInputStream() throws CharacterCodingException { + this((CharBuffer) null, "UTF-8"); + } + + public CharBackedInputStream(CharSequence backingStr) throws CharacterCodingException { + this(backingStr, "UTF-8"); + } + + public CharBackedInputStream(char[] backingChars) throws CharacterCodingException { + this(backingChars, "UTF-8"); + } + + public CharBackedInputStream(char[] backingChars, String encodingName) throws CharacterCodingException { + this(CharBuffer.wrap(backingChars), encodingName); + } + + public CharBackedInputStream(CharSequence backingStr, String encodingName) throws CharacterCodingException { + this(CharBuffer.wrap(backingStr), encodingName); + } + + public void addBackingSource(CharSequence backingStr) throws CharacterCodingException { + addBackingSource(CharBuffer.wrap(backingStr)); + } + + public void addBackingSource(CharSequence backingStr, int off, int len) throws CharacterCodingException { + addBackingSource(CharBuffer.wrap(backingStr.subSequence(off, len + off))); + } + + public void addBackingSource(char[] chars, int off, int len) throws CharacterCodingException { + addBackingSource(CharBuffer.wrap(chars, off, len)); + } + + public void addBackingSource(char[] chars) throws CharacterCodingException { + addBackingSource(CharBuffer.wrap(chars)); + } + + public void addBackingSource(CharBuffer source) throws CharacterCodingException { + ByteBuffer buffer = encoder.encode(source); + if (currentBacker == null) { + currentBacker = buffer; + } else { + backers.add(buffer); + } + } + + /* + * (non-Javadoc) + * + * @see java.io.InputStream#read() + */ + public int read() throws IOException { + if (currentBacker == null) { + return -1; + } + try { + return currentBacker.get(); + } catch (BufferUnderflowException ex) { + currentBacker = backers.poll(); + return read(); + } + } + + /** + * @return Returns the writer. + */ + public Writer getWriter() { + if (writer == null) { + writer = new InputStreamWriter(); + } + return writer; + } + + /* (non-Javadoc) + * @see java.lang.Appendable#append(java.lang.CharSequence) + */ + public Appendable append(CharSequence csq) throws IOException { + addBackingSource(csq); + return this; + } + + /* (non-Javadoc) + * @see java.lang.Appendable#append(java.lang.CharSequence, int, int) + */ + public Appendable append(CharSequence csq, int start, int end) throws IOException { + addBackingSource(csq, start, end - start); + return this; + } + + /* (non-Javadoc) + * @see java.lang.Appendable#append(char) + */ + public Appendable append(char c) throws IOException { + throw new UnsupportedOperationException( + "doing this one character at a time would be so inefficient it would defeat the whole purpose of this class"); + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/CsvReader.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/CsvReader.java new file mode 100644 index 00000000000..0260cf9e3ef --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/CsvReader.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.io.StreamTokenizer; +import java.util.Arrays; + +/** + * @author Ryan D. Brooks + */ +public class CsvReader { + private Reader reader; + private StreamTokenizer streamTokenizer; + private boolean[] fieldsUsed; + private int fieldCount; + private String[] nextRow; + + /** + * @param file a comma separate value file + * @param totalNumFields the largest number of fields on any row (whether they are used or not) + * @param enabled whether to enable or disable all the feilds initially + * @throws IOException + */ + public CsvReader(File file, int totalNumFields, boolean enabled) throws IOException { + this(new BufferedReader(new FileReader(file)), totalNumFields, enabled); + } + + /** + * All fields will be enabled initially + * + * @param file a comma separate value file + * @param totalNumFields the largest number of fields on any row (whether they are used or not) + * @throws IOException + */ + public CsvReader(File file, int totalNumFields) throws IOException { + this(new BufferedReader(new FileReader(file)), totalNumFields); + } + + public CsvReader(Reader reader, int totalNumFields) throws IOException { + this(reader, totalNumFields, true); + } + + public CsvReader(Reader reader, int totalNumFields, boolean enabled) throws IOException { + this.reader = reader; + this.streamTokenizer = new StreamTokenizer(reader); + this.fieldsUsed = new boolean[totalNumFields]; + Arrays.fill(fieldsUsed, enabled); + countFieldsUsed(); + + streamTokenizer.resetSyntax(); + streamTokenizer.eolIsSignificant(true); + streamTokenizer.whitespaceChars(0, ' ' - 1); + streamTokenizer.wordChars(' ', 255); // make all non-white space characters part of the returned string + streamTokenizer.ordinaryChar(','); // except the delimiter ',' + streamTokenizer.quoteChar('\"'); // and the quote char + + getRow(); //prime so hasNext might return true (and getRow will return the first row the next time it is called) + } + + private void countFieldsUsed() { + this.fieldCount = 0; + for (int i = 0; i < fieldsUsed.length; i++) { + if (fieldsUsed[i]) { + fieldCount++; + } + } + } + + /** + * inclusive range + * + * @param start + * @param end + * @param enable + */ + public void setFieldsEnabled(int start, int end, boolean enable) { + for (int i = start; i <= end; i++) { + setFieldEnabled(i, enable); + } + } + + public void setFieldEnabled(int index, boolean enable) { + fieldsUsed[index] = enable; + countFieldsUsed(); + } + + public String[] getRow() throws IOException { + String[] rowToReturn = nextRow; + this.nextRow = getRowInternal(); + return rowToReturn; + } + + public boolean hasNext() { + return nextRow != null; + } + + public void skipHeaderRow() throws IOException { + getRow(); + } + + /** + * @return an array + * @throws IOException + */ + private String[] getRowInternal() throws IOException { + String[] values = new String[fieldCount]; + int fieldIndex = 0; + int valuesIndex = 0; + while (streamTokenizer.nextToken() != StreamTokenizer.TT_EOL) { + if (streamTokenizer.ttype == ',') { + if (fieldsUsed[fieldIndex]) { + valuesIndex++; // accounts for fields that are used even if they are empty (i.e. two consecutive commas) + } + fieldIndex++; + } else if (streamTokenizer.ttype == StreamTokenizer.TT_WORD || streamTokenizer.ttype == '\"') { + if (fieldsUsed[fieldIndex]) { + values[valuesIndex] = streamTokenizer.sval; + } + } else if (streamTokenizer.ttype == StreamTokenizer.TT_EOF) { + return null; + } else { + throw new IllegalArgumentException("The token type was: " + streamTokenizer.ttype); + } + } + return values; + } + + public void close() { + try { + reader.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/DriveType.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/DriveType.java new file mode 100644 index 00000000000..e1893f48c60 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/DriveType.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +public enum DriveType { + Unknown((short) 0), NoRootDirectory((short) 1), Removable((short) 2), // Floppy, Zip, etc + Fixed((short) 3), // Hard disk + Remote((short) 4), // Network drive + CdRom((short) 5), + RamDrive((short) 6); + + private final short value; + + DriveType(short value) { + this.value = value; + } + + /** + * @return Returns the value. + */ + public short getValue() { + return value; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/EnumBaseBuilder.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/EnumBaseBuilder.java new file mode 100644 index 00000000000..6c42fb0b2dd --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/EnumBaseBuilder.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.util.Comparator; +import java.util.PriorityQueue; + +/** + * @author Robert A. Fisher + * @deprecated + */ +@Deprecated +public class EnumBaseBuilder extends JavaFileBuilder { + + protected PriorityQueue<EnumRecord> enums; + + private static final String stringTableMethod = + "\tprotected String[] getStringTable() {\n" + "\t\treturn stringTable;\n" + "\t}"; + private static final String enumTableMethod = + "\tprotected EnumSyntax[] getEnumValueTable() {\n" + "\t\treturn enumValueTable;\n" + "\t}"; + + public EnumBaseBuilder(String packageName, String className, String classJavaDoc) { + super(packageName, className, classJavaDoc, "EnumBase"); + + // Place the enums in a priority queue based on their number value + enums = new PriorityQueue<EnumRecord>(20, new Comparator<EnumRecord>() { + + public int compare(EnumRecord i, EnumRecord j) { + return i.number - j.number; + } + + }); + + addMethod(getGetEnum()); + addMethod(getToEnum1()); + addMethod(getToEnum2()); + addMethod(stringTableMethod); + addMethod(enumTableMethod); + } + + public void addEnum(String name, int enumNumber) { + addEnum(name, enumNumber, null); + } + + public void addEnum(String name, int enumNumber, String additionalValues) { + addField(new Field(className, name, true, true, true, getInitialValue(enumNumber, additionalValues))); + enums.offer(new EnumRecord(enumNumber, name)); + } + + protected String getBasicConstructor() { + return "\tprotected " + className + "(int value) {\n" + "\t\tsuper(value);\n" + "\t}"; + } + + private String getInitialValue(int enumNumber, String additionalValues) { + return "new " + className + "(" + enumNumber + ((additionalValues != null) ? "," + additionalValues : "") + ")"; + } + + private String getGetEnum() { + return "\tpublic static " + className + " getEnum(String str) {\n" + "\t\treturn (" + className + ") getEnum(str, stringTable, enumValueTable);\n" + "\t}"; + } + + private String getToEnum1() { + return "\tpublic static " + className + " toEnum(int value) {\n" + "\t\treturn (" + className + ") getEnum(value, enumValueTable);\n" + "\t}"; + } + + private String getToEnum2() { + return "\tpublic static " + className + " toEnum(EnumBase otherEnum) {\n" + "\t\treturn toEnum(otherEnum.getValue());\n" + "\t}"; + } + + /* + * Add the fields from the parent, along with fields that have to be generated dynamically + * based on what enums have been added over the lifetime of this builder. + * + * (non-Javadoc) + * @see org.eclipse.osee.framework.jdk.core.util.io.JavaFileBuilder#getFields(java.lang.StringBuilder) + */ + @Override + protected void getFields(StringBuilder string) { + super.getFields(string); + + // Get a copy of the priority queue, in case this is called many times + PriorityQueue<EnumRecord> records = new PriorityQueue<EnumRecord>(enums); + + StringBuilder stringTable = new StringBuilder(); + StringBuilder enumValueTable = new StringBuilder(); + + // This shoud start at one less than the first value since EnumBase accounts for non-zero based enums + int lastEnumVal = records.peek().number - 1; + + // Start the declarations for the two necessary fields + stringTable.append("\tprivate static final String[] stringTable = new String[] {"); + enumValueTable.append("\tprivate static final " + className + "[] enumValueTable = new " + className + "[] {"); + + EnumRecord record; + // Pop each of the records from the queue + while ((record = records.poll()) != null) { + + // Fill skipped values in the enum listing with null references + for (int x = lastEnumVal; x < (record.number - 1); x++) { + stringTable.append("null, "); + enumValueTable.append("null, "); + } + + stringTable.append("\"" + record.name + "\""); + enumValueTable.append(record.name); + + // If there are more items, then add a comma + if (!records.isEmpty()) { + stringTable.append(", "); + enumValueTable.append(", "); + } + + lastEnumVal = record.number; + } + + stringTable.append("};\n"); + enumValueTable.append("};\n"); + + string.append(stringTable.toString()); + string.append(enumValueTable.toString()); + } + + private class EnumRecord { + private int number; + private String name; + + /** + * @param number The ordinal value of the enumeration + * @param name The declarartion name of the enumeration + */ + public EnumRecord(int number, String name) { + this.number = number; + this.name = name; + } + + /** + * @return Returns the name. + */ + public String getName() { + return name; + } + + /** + * @return Returns the number. + */ + public int getNumber() { + return number; + } + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/ExtensionFilter.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/ExtensionFilter.java new file mode 100644 index 00000000000..117ad3c5abf --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/ExtensionFilter.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.io.File; +import java.io.FileFilter; + +/** + * Filter for filtering files that end with a specific string. + * + * @author Robert A. Fisher + */ +public class ExtensionFilter implements FileFilter { + private final String extension; + + /** + * @param extension The string to match the end of the filenames against. + * @throws IllegalArgumentException if <code>extension</code> is null. + */ + public ExtensionFilter(String extension) { + if (extension == null) throw new IllegalArgumentException("extension must not be null"); + this.extension = extension; + } + + public boolean accept(File file) { + return file.isFile() && file.getName().endsWith(extension); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/IEnumValueBuilder.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/IEnumValueBuilder.java new file mode 100644 index 00000000000..059504beb2e --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/IEnumValueBuilder.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.util.Comparator; +import java.util.PriorityQueue; + +/** + * Started with EnumBaseBuilder and made modifications for IEnumValue + * + * @author Cindy Maher + */ +public class IEnumValueBuilder extends JavaFileBuilder { + + protected PriorityQueue<EnumRecord> enums; + + public IEnumValueBuilder(String packageName, String className, String classJavaDoc) { + super(packageName, className, classJavaDoc, null); + + // Place the enums in a priority queue based on their number value + enums = new PriorityQueue<EnumRecord>(20, new Comparator<EnumRecord>() { + + public int compare(EnumRecord i, EnumRecord j) { + return i.number - j.number; + } + + }); + + addMethod(getBasicConstructor()); + addMethod(getGetIntValue()); + addMethod(getToEnum()); + addMethod(getGetToEnum()); + } + + public void addEnum(String name, int enumNumber) { + addEnumField(new EnumRecord(enumNumber, name)); + } + + protected String getBasicConstructor() { + return "\tprivate int value;\n\n" + "\tprivate " + className + "(int value) {\n" + "\t\tthis.value = value;\n" + "\t}\n"; + } + + private String getGetIntValue() { + return "\tpublic int getIntValue() {\n" + "\t\treturn value;\n" + "\t}\n"; + } + + private String getToEnum() { + return "\tpublic static " + className + " toEnum(int value) {\n" + "\t\tfor (" + className + " myEnum : " + className + ".values()) {\n" + "\t\t\tif (myEnum.getIntValue() == value) {\n" + "\t\t\t\treturn myEnum;\n" + "\t\t\t}\n" + "\t\t}\n" + "\t\tthrow new IllegalArgumentException(\"Unable to find " + className + " with value \" + value + \".\");\n" + "\t}\n"; + } + + private String getGetToEnum() { + return "\tpublic static " + className + " getEnum(String enumString) {\n" + "\t\tfor (" + className + " myEnum : " + className + ".values()) {\n" + "\t\t\tif (" + className + ".valueOf(enumString) == myEnum) {\n" + "\t\t\t\treturn myEnum;\n" + "\t\t\t}\n" + "\t\t}\n" + "\t\tthrow new IllegalArgumentException(\"Unable to find " + className + " to match \" + enumString + \".\");\n" + "\t}\n"; + } + + public class EnumRecord { + private int number; + private String name; + + /** + * @param number The ordinal value of the enumeration + * @param name The declaration name of the enumeration + */ + public EnumRecord(int number, String name) { + this.number = number; + this.name = name; + } + + /** + * @return Returns the name. + */ + public String getName() { + return name; + } + + /** + * @return Returns the number. + */ + public int getNumber() { + return number; + } + + @Override + public String toString() { + String enumStr = name + "(" + number + ")"; + return enumStr; + } + + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/IOInputThread.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/IOInputThread.java new file mode 100644 index 00000000000..e23eaa6e99c --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/IOInputThread.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.Reader; + +/** + * @author Ryan D. Brooks + * @author Andrew M. Finkbeiner + */ +public class IOInputThread extends Thread { + + private Reader input; + private BufferedWriter output; + + /** + * + */ + public IOInputThread(Reader input, BufferedWriter output) { + super(); + this.output = output; + this.input = input; + } + + public void run() { + int character; + try { + //* + while ((character = input.read()) != -1) { + output.write(character); + output.flush(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } finally { + try { + input.close(); + //output.flush(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/IOOutputThread.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/IOOutputThread.java new file mode 100644 index 00000000000..0cc5ba56687 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/IOOutputThread.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Writer; + +/** + * @author Ryan D. Brooks + * @author Andrew M. Finkbeiner + */ +public class IOOutputThread extends Thread { + + private Writer output; + private BufferedReader input; + + /** + * + */ + public IOOutputThread(Writer output, BufferedReader input, boolean verbose) { + super(); + this.output = output; + this.input = input; + } + + public IOOutputThread(Writer output, BufferedReader input) { + this(output, input, true); + } + + public void run() { + try { + final char[] buffer = new char[4096]; + int size; + while ((size = input.read(buffer)) != -1) { + output.write(buffer, 0, size); + output.flush(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } finally { + try { + input.close(); + output.flush(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/IZipEntryCompleteCallback.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/IZipEntryCompleteCallback.java new file mode 100644 index 00000000000..f5d6a7a247d --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/IZipEntryCompleteCallback.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +public interface IZipEntryCompleteCallback { + + void setValue(int i); + + void setMinimum(int i); + + void setMaximum(int i); + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/InputBufferThread.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/InputBufferThread.java new file mode 100644 index 00000000000..072f39afe46 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/InputBufferThread.java @@ -0,0 +1,245 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InterruptedIOException; +import java.util.regex.MatchResult; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Sole purpose is to read input from a specified stream and save it into a buffer providing some access methods to the + * buffer. + * + * @author Michael P. Masterson + */ +public class InputBufferThread extends Thread { + private final byte[] charBuffer = new byte[1024]; + private final InputStream input; + private final StringBuilder buffer; + private volatile boolean shouldStopRunning; + private long lastRead; + + /** + * @param input The stream to read from + */ + public InputBufferThread(InputStream input) { + super("Stream input buffer thread"); + shouldStopRunning = false; + this.input = input; + buffer = new StringBuilder(8196); + } + + /** + * Overridden Thread.run method. Reads from the input stream on character at a time until the end of available input + * or until the bold shouldStopRunning is set by an outside source. + */ + public void run() { + System.out.println("thread started"); + int count = 0; + try { + int size = input.read(charBuffer); + while (size >= 0) { + count++; + synchronized (this) { + lastRead = System.currentTimeMillis(); + if (shouldStopRunning) { + break; + } + append(charBuffer, size); + } + size = input.read(charBuffer); + } + } catch (InterruptedIOException e) { + if (shouldStopRunning != true) { + // this is an error + e.printStackTrace(System.err); + } + } catch (IOException e) { + if (!shouldStopRunning) { + System.err.println("error at count " + count); + e.printStackTrace(System.err); + } + } finally { + try { + input.close(); + } catch (IOException e) { + e.printStackTrace(System.out); + System.out.flush(); + } finally { + // wake up anyone waiting for data or else they will be stuck forever + synchronized (this) { + notifyAll(); + } + } + } + } + + /** + * Appends one character to the buffer. + * + * @param line The character to append + */ + private void append(byte[] line, int size) { + buffer.append(new String(line, 0, size)); + notify(); + } + + /** + * Checks if the string passed is contained in the buffer so far + * + * @param matcher The string to look for + * @return a positive value representing the index at which it was found or negative 1 if it was not found + */ + public synchronized int contains(String matcher, boolean remove) { + int index = buffer.lastIndexOf(matcher); + if (remove && index >= 0) { + buffer.delete(0, index + matcher.length()); + } + return index; + } + + /** + * Checks if the string passed is contained in the buffer so far + * + * @param matcher The string to look for + * @return a positive value representing the index at which it was found or negative 1 if it was not found + */ + public synchronized int contains(String matcher) { + return contains(matcher, false); + } + + public synchronized int waitFor(String matcher, int millis) throws InterruptedException { + return waitFor(matcher, false, millis); + } + + public synchronized int waitFor(String matcher, boolean remove, int millis) throws InterruptedException { + if (shouldStopRunning) { + throw new IllegalStateException("stream processing terminated"); + } + long time = System.currentTimeMillis(); + int result = contains(matcher, false); + long timeRemaining = millis; + while (result < 0 && timeRemaining > 0) { + wait(timeRemaining); + if (shouldStopRunning) { + // we were told to stop or the stream was closed on the other end + throw new InterruptedException("stream processing terminated"); + } + result = contains(matcher, false); + timeRemaining = millis - (System.currentTimeMillis() - time); + } + if (remove && result >= 0) { + buffer.delete(0, result + matcher.length()); + } + return result; + } + + public synchronized MatchResult waitFor(Pattern pattern, boolean remove, int millis) throws InterruptedException { + if (shouldStopRunning) { + throw new IllegalStateException("stream processing terminated"); + } + Matcher matcher = pattern.matcher(buffer.toString()); + long time = System.currentTimeMillis(); + long timeRemaining = millis; + boolean result = matcher.matches(); + while (!result && timeRemaining > 0) { + wait(timeRemaining); + if (shouldStopRunning) { + // we were told to stop or the stream was closed on the other end + throw new InterruptedException("stream processing terminated"); + } + matcher = matcher.reset(buffer.toString()); + result = matcher.matches(); + timeRemaining = millis - (System.currentTimeMillis() - time); + } + if (remove && result) { + buffer.delete(0, matcher.end()); + } + return result ? matcher.toMatchResult() : null; + } + + /** + * @param millis + * @return true if a transmission occurred false otherwise + * @throws InterruptedException + */ + public synchronized boolean waitFor(int millis) throws InterruptedException { + if (shouldStopRunning) { + throw new IllegalStateException("stream processing terminated"); + } + + long currentTime = System.currentTimeMillis(); + long savedLastRead = lastRead; + while (savedLastRead != lastRead) { + wait(millis); + // make sure we did not reach ourr timeout limit, also we need to handle potential 'spurious' wakeups + long next = System.currentTimeMillis(); + millis -= next - currentTime; + currentTime = next; + if (savedLastRead == lastRead && millis <= 0) { + return false; + } + } + return true; + } + + /** + * @return The entire buffered input. + */ + public synchronized String getBuffer() { + return buffer.toString(); + } + + public synchronized String subString(int beginIndex) { + return buffer.substring(beginIndex); + } + + public synchronized String subString(int beginIndex, int endIndex) { + return buffer.substring(beginIndex, endIndex); + } + + /** + * @return The entire buffered input. + */ + public synchronized int getLength() { + return buffer.length(); + } + + /** + * Tells this thread whether to stop on the next cycle or not + * + * @param b True if the thread should stop on the next run cycle. + */ + public void stopOnNextRun(boolean b) { + this.shouldStopRunning = b; + } + + public void stopNow() throws InterruptedException { + this.shouldStopRunning = true; + interrupt(); + join(5000); + } + + public long getLastRead() { + if (lastRead == 0) + return System.currentTimeMillis(); + else + return lastRead; + } + + public synchronized void clear() { + buffer.delete(0, buffer.length()); + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/JavaFileBuilder.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/JavaFileBuilder.java new file mode 100644 index 00000000000..e92cb713b32 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/JavaFileBuilder.java @@ -0,0 +1,287 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import org.eclipse.osee.framework.jdk.core.util.io.IEnumValueBuilder.EnumRecord; + +/** + * Allows java files to be built dynamically and written out to disk. + * + * @author Robert A. Fisher + */ +public class JavaFileBuilder { + protected String packageName; + protected String className; + protected String classJavaDoc; + protected String extendsClass; + private ArrayList<String> interfaces; + private List<Field> fields; + private List<String> imports; + private List<String> methods; + private List<EnumRecord> enumFields; + + /** + * Create a JavaFileBuilder for a class. + * + * @param className The class of the file. + */ + public JavaFileBuilder(String className) { + this(null, className, null, null); + } + + /** + * Constructor + */ + public JavaFileBuilder(String packageName, String className, String classJavaDoc, String extendsClass) { + this.packageName = packageName; + this.className = className; + this.classJavaDoc = classJavaDoc; + this.extendsClass = extendsClass; + interfaces = new ArrayList<String>(); + fields = new LinkedList<Field>(); + imports = new LinkedList<String>(); + methods = new LinkedList<String>(); + enumFields = new LinkedList<EnumRecord>(); + } + + public void addInterface(String interfaceName) { + interfaces.add(interfaceName); + } + + public void addField(Field field) { + fields.add(field); + } + + public void addEnumField(EnumRecord enumField) { + enumFields.add(enumField); + } + + public void addImport(String importName) { + imports.add(importName); + } + + public void addMethod(String method) { + methods.add(method); + } + + /** + * @param classJavaDoc The classJavaDoc to set. + */ + public void setClassJavaDoc(String classJavaDoc) { + this.classJavaDoc = classJavaDoc; + } + + /** + * @param className The className to set. + */ + public void setClassName(String className) { + this.className = className; + } + + /** + * @param extendsClass The extendsClass to set. + */ + public void setExtendsClass(String extendsClass) { + this.extendsClass = extendsClass; + } + + /** + * @param packageName The packageName to set. + */ + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + /** + * Write the file out to disk. The file will be written to the specified directory. By virtue of Java, the filename + * will be the name of the class with .java as the extension. + * + * @throws FileNotFoundException + */ + public void write(File directory) throws FileNotFoundException { + if (!directory.isDirectory()) throw new IllegalArgumentException("Supplied file is not a directory"); + + PrintWriter out = new PrintWriter(new File(directory, className + ".java")); + + out.write(this.toString()); + + out.close(); + } + + public static class Field { + private boolean isPublic; + private boolean isFinal; + private boolean isStatic; + private String type; + private String name; + private String initialValue; + + public Field(String type, String name, boolean isFinal) { + this(type, name, false, false, isFinal); + } + + public Field(String type, String name, boolean isPublic, boolean isStatic, boolean isFinal) { + this(type, name, isPublic, isStatic, isFinal, null); + } + + /** + * @param type The type of the field + * @param name The name of the field + * @param isPublic Whether the field should be declared as public + * @param isStatic Whether the field should be declared as static + * @param isFinal Whether the field should be declared as final + * @param initialValue An initial value to set the field to. + */ + public Field(String type, String name, boolean isPublic, boolean isStatic, boolean isFinal, String initialValue) { + this.type = type; + this.name = name; + this.isPublic = isPublic; + this.isStatic = isStatic; + this.isFinal = isFinal; + this.initialValue = initialValue; + } + + @Override + public String toString() { + String declaration = + "\t" + ((isPublic) ? "public " : "private ") + ((isStatic) ? "static " : "") + ((isFinal) ? "final " : "") + type + " " + name; + + if (initialValue != null) declaration += " = " + initialValue; + return declaration + ";"; + } + + /** + * @return Returns the isPublic. + */ + public boolean isPublic() { + return isPublic; + } + + /** + * @return Returns the isStatic. + */ + public boolean isStatic() { + return isStatic; + } + + /** + * @return Returns the isFinal. + */ + public boolean isFinal() { + return isFinal; + } + + /** + * @return Returns the name. + */ + public String getName() { + return name; + } + + /** + * @return Returns the type. + */ + public String getType() { + return type; + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder string = new StringBuilder(); + + SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy"); + + // Add the head comment for the file + string.append("/*\n * Created on " + dateFormat.format(new Date()) + "\n *\n * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE\n */\n\n"); + string.append("package " + packageName + ";"); + string.append("\n\n"); + + // Add all of the imports + for (String importName : imports) { + string.append("import " + importName + ";\n"); + } + + string.append("\n"); + + // Add the class comment if it is available + if (classJavaDoc != null) { + string.append(stringToJavadoc(classJavaDoc)); + } + + // add the start of the class + // Check to see if this is an IEnumValue file + if (interfaces.size() != 0 && interfaces.get(0).equals("IEnumValue") && extendsClass == null) { + string.append("public enum " + className + " implements IEnumValue"); + string.append(" {\n"); + getEnumFields(string); + } else { + string.append("public class " + className + ((extendsClass == null) ? "" : " extends " + extendsClass.trim())); + for (int i = 0; i < interfaces.size(); i++) { + if (i == 0) + string.append(" implements " + interfaces.get(i)); + else + string.append(", " + interfaces.get(i)); + } + string.append(" {\n"); + getFields(string); + } + + getMethods(string); + + // add the end of the file + string.append("}"); + + return string.toString(); + } + + protected void getFields(StringBuilder string) { + for (Field field : fields) + string.append(field.toString() + "\n"); + } + + protected void getEnumFields(StringBuilder string) { + Iterator<EnumRecord> enumFieldsIter = enumFields.iterator(); + while (enumFieldsIter.hasNext()) { + EnumRecord eField = enumFieldsIter.next(); + string.append("\t" + eField); + if (!enumFieldsIter.hasNext()) + string.append(";\n\n"); + else + string.append(",\n"); + } + + } + + protected void getMethods(StringBuilder string) { + for (String method : methods) + string.append(method + "\n"); + } + + private String stringToJavadoc(String string) { + return "/**\n" + string.replaceAll("^", " * ").replaceAll("\n", "\n * ") + "\n */\n"; + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/LnkWriter.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/LnkWriter.java new file mode 100644 index 00000000000..840c6d535a4 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/LnkWriter.java @@ -0,0 +1,826 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +/** + * Provides a way to produce simple lnk files. + * + * @author Robert A. Fisher + */ +public class LnkWriter { + + private String description; + private String longName; + private String shortName; + private char shareDriveLetter; + private String shareName; + private String relativePath; + private String commandLineArguments; + private String iconFilename; + private String volumeLabel; + private String workingDirectory; + private String localPath; + private String finalPath; + private int iconNumber; + private int fileLength; + private int volumeSerialNumber; + private DriveType driveType; + + private static final int DWORD = 4; // A dword is 4 bytes + + private static byte MAGIC_VAL[] = new byte[] {0x4C, 0x00, 0x00, 0x00}; + private static byte GUID[] = + new byte[] {0x01, 0x14, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x46}; + + public LnkWriter() { + this.description = null; + this.longName = null; + this.shortName = null; + this.shareName = null; + this.relativePath = null; + this.commandLineArguments = null; + this.iconFilename = null; + this.volumeLabel = null; + this.workingDirectory = null; + this.localPath = null; + this.finalPath = null; + this.iconNumber = 0; + this.fileLength = 0; + this.volumeSerialNumber = 0; + this.driveType = DriveType.Unknown; + } + + /** + * @param commandLineArguments The commandLineArguments to set. + */ + public void setCommandLineArguments(String commandLineArguments) { + this.commandLineArguments = commandLineArguments; + } + + /** + * @param description The description to set. + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @param driveType The driveType to set. + */ + public void setDriveType(DriveType driveType) { + this.driveType = driveType; + } + + /** + * @param fileLength The fileLength to set. + */ + public void setFileLength(int fileLength) { + this.fileLength = fileLength; + } + + /** + * @param finalPath The finalPath to set. + */ + public void setFinalPath(String finalPath) { + this.finalPath = finalPath; + } + + /** + * @param iconFilename The iconFilename to set. + */ + public void setIconFilename(String iconFilename) { + this.iconFilename = iconFilename; + } + + /** + * @param iconNumber The iconNumber to set. + */ + public void setIconNumber(int iconNumber) { + this.iconNumber = iconNumber; + } + + /** + * @param localPath The localPath to set. + */ + public void setLocalPath(String localPath) { + this.localPath = localPath; + } + + /** + * @param longName The longName to set. + */ + public void setLongName(String longName) { + this.longName = longName; + } + + /** + * @param shareName The networkShare to set. + */ + public void setShareName(String shareName, char driveLetter) { + this.shareName = shareName; + this.shareDriveLetter = driveLetter; + } + + /** + * @param relativePath The relativePath to set. + */ + public void setRelativePath(String relativePath) { + this.relativePath = relativePath; + } + + /** + * @param shortName The shortName to set. + */ + public void setShortName(String shortName) { + this.shortName = shortName; + } + + /** + * @param volumeLabel The volumeLabel to set. + */ + public void setVolumeLabel(String volumeLabel) { + this.volumeLabel = volumeLabel; + } + + /** + * @param volumeSerialNumber The volumeSerialNumber to set. + */ + public void setVolumeSerialNumber(int volumeSerialNumber) { + this.volumeSerialNumber = volumeSerialNumber; + } + + /** + * @param workingDirectory The workingDirectory to set. + */ + public void setWorkingDirectory(String workingDirectory) { + this.workingDirectory = workingDirectory; + } + + public static void writeOsee(String shortcutName) throws IOException { + writeFile(shortcutName, OSEE); + } + + public static void writeOseeMs(String shortcutName) throws IOException { + writeFile(shortcutName, OSEE_MS); + } + + private static void writeFile(String name, byte[] data) throws IOException { + File outfile = new File(name); + FileOutputStream out; + out = new FileOutputStream(outfile); + + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + byteOut.write(data); + byteOut.writeTo(out); + out.close(); + } + + public void write(String shortcutName) { + + File outfile = new File(shortcutName); + FileOutputStream out; + try { + out = new FileOutputStream(outfile); + } catch (FileNotFoundException ex) { + ex.printStackTrace(); + return; + } + + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + try { + byteOut.write(MAGIC_VAL); + byteOut.write(GUID); + byteOut.write(getTheFlags()); + byteOut.write(getFileAttributes()); + byteOut.write(getTimeFields()); + byteOut.write(getFileLength()); + byteOut.write(getIconNumber()); + byteOut.write(getShowWnd()); + byteOut.write(getHotKey()); + byteOut.write(new byte[2 * DWORD]); // There is a 2 DWORD bubble in the format + byteOut.write(getShellItemIdList()); + byteOut.write(getFileLocationInfo()); + if (description != null) byteOut.write(getStringByteData(description)); + if (relativePath != null) byteOut.write(getStringByteData(relativePath)); + if (workingDirectory != null) byteOut.write(getStringByteData(workingDirectory)); + if (commandLineArguments != null) byteOut.write(getStringByteData(commandLineArguments)); + if (iconFilename != null) byteOut.write(getStringByteData(iconFilename)); + byteOut.write(intToByteArray(0)); // End stuff ... + byteOut.writeTo(out); + out.close(); + } catch (IOException ex) { + ex.printStackTrace(); + return; + } + } + + private byte[] getTheFlags() { + // The flags field is one DWORD + byte data[] = new byte[DWORD]; + + // This will always be the case + data[0] |= 1 << 0; // Points to a file or directory + + if (description != null) data[0] |= 1 << 1; // Has a description string + if (relativePath != null) data[0] |= 1 << 2; // Has a relative path string + if (workingDirectory != null) data[0] |= 1 << 3; // Has a working directory string + if (commandLineArguments != null) data[0] |= 1 << 4; // Has command line arguments + if (iconFilename != null) data[0] |= 1 << 5; // Has a custom icon + return data; + } + + private byte[] getFileAttributes() { + // The file attributes field is one DWORD + byte data[] = new byte[DWORD]; + + // Nothing set here yet + + return data; + } + + private byte[] getTimeFields() { + // The 3 time fields are 64 bits each + byte data[] = new byte[3 * 8]; + + // Nothing to set here yet + + return data; + } + + private byte[] getFileLength() { + return intToByteArray(fileLength); + } + + private byte[] getIconNumber() { + return intToByteArray(iconNumber); + } + + private byte[] getShowWnd() { + + // SW_NORMAL = 1 + // SW_SHOWMINIMIZED = 2 + // SW_SHOWMAXIMIXED = 3 + return intToByteArray(1); + } + + private byte[] getHotKey() { + // No hot key setting yet + return intToByteArray(0); + } + + private byte[] getShellItemIdList() { + + // First must acquire all items that go within the table + byte shortNameString[] = getNullTerminatedBytes(shortName.getBytes()); + byte longNameString[] = getNullTerminatedBytes(longName.getBytes()); + + // The table has 4.5 dword's in addition to the two strings + byte data[] = new byte[(int) (4.5 * DWORD) + shortNameString.length + longNameString.length]; + + // Put the length of the list (everything except this 2 bytes + System.arraycopy(shortToByteArray((short) (data.length - 2)), 0, data, 0 * DWORD, 2); + + // Length of the first item (which is this whole block, minus one dword + System.arraycopy(shortToByteArray((short) (data.length - DWORD)), 0, data, (int) (0.5 * DWORD), 2); + + System.arraycopy(shortToByteArray((short) 0x32), 0, data, 1 * DWORD, 2); // Some mystical + // value + System.arraycopy(intToByteArray(fileLength), 0, data, (int) (1.5 * DWORD), 4); + System.arraycopy(intToByteArray(0x3E712576), 0, data, (int) (2.5 * DWORD), 4);// Some mystical + // value + System.arraycopy(shortToByteArray((short) (0x20)), 0, data, (int) (3.5 * DWORD), 2);// Some + // mystical + // value + + // Place the longname string in now + System.arraycopy(longNameString, 0, data, 4 * DWORD, longNameString.length); + + // Place the shortname string right after the longname + System.arraycopy(shortNameString, 0, data, 4 * DWORD + longNameString.length, shortNameString.length); + + return data; + } + + private byte[] getFileLocationInfo() { + // First must acquire all tables that follow this structure + byte localVolumeTable[] = getLocalVolumeTable(); + byte localPathString[] = (localPath != null) ? getNullTerminatedBytes(localPath.getBytes()) : new byte[0]; + byte networkVolumeTable[] = getNetworkVolumeTable(); + byte finalPathString[] = getNullTerminatedBytes(finalPath.getBytes()); + + // The file attributes field is seven DWORD's, plus the structures above + byte data[] = + new byte[7 * DWORD + localVolumeTable.length + localPathString.length + networkVolumeTable.length + finalPathString.length]; + + // This flag specifies whether local volume, and/or network volume data is available + int flags = 0; + if (localVolumeTable.length > 0) flags |= 0x1; + if (networkVolumeTable.length > 0) flags |= 0x2; + + // Calculate the necessary offets + int localVolumeOffset = 7 * DWORD; + int localPathOffset = localVolumeOffset + localVolumeTable.length; + int networkVolumeOffset = localPathOffset + localPathString.length; + int finalPathOffset = networkVolumeOffset + networkVolumeTable.length; + + // Put the length value in the first dword + System.arraycopy(intToByteArray(data.length), 0, data, 0 * DWORD, 4); + + // Write the following words + System.arraycopy(intToByteArray(0x1C), 0, data, 1 * DWORD, 4); // First offset after this + // structure + System.arraycopy(intToByteArray(flags), 0, data, 2 * DWORD, 4); + System.arraycopy(intToByteArray(localVolumeOffset), 0, data, 3 * DWORD, 4); + System.arraycopy(intToByteArray(localPathOffset), 0, data, 4 * DWORD, 4); + System.arraycopy(intToByteArray(networkVolumeOffset), 0, data, 5 * DWORD, 4); + System.arraycopy(intToByteArray(finalPathOffset), 0, data, 6 * DWORD, 4); + + // Write the referenced blocks + System.arraycopy(localVolumeTable, 0, data, localVolumeOffset, localVolumeTable.length); + System.arraycopy(localPathString, 0, data, localPathOffset, localPathString.length); + System.arraycopy(networkVolumeTable, 0, data, networkVolumeOffset, networkVolumeTable.length); + System.arraycopy(finalPathString, 0, data, finalPathOffset, finalPathString.length); + + return data; + } + + private byte[] getLocalVolumeTable() { + // If missing the label then don't put it in + if (volumeLabel == null) return new byte[0]; + + byte volumeLabelString[] = getNullTerminatedBytes(volumeLabel.getBytes()); + + // The first 4 dword's are static, then there is the volume label string + byte data[] = new byte[(4 * DWORD) + volumeLabelString.length]; + + // Put the length value in the first dword + System.arraycopy(intToByteArray((short) data.length), 0, data, 0 * DWORD, 4); + + // Write the following words + System.arraycopy(intToByteArray(driveType.getValue()), 0, data, 1 * DWORD, 4); + System.arraycopy(intToByteArray(volumeSerialNumber), 0, data, 2 * DWORD, 4); + System.arraycopy(intToByteArray(0x10), 0, data, 3 * DWORD, 4); + + // Place the string right after that + System.arraycopy(volumeLabelString, 0, data, 4 * DWORD, volumeLabelString.length); + + return data; + } + + private byte[] getNetworkVolumeTable() { + // If the network share is null, then no table + if (shareName == null) return new byte[0]; + + byte networkShareString[] = getNullTerminatedBytes(shareName.getBytes()); + + // The first 5 dword's are static, then there is the network share name, and drive letter + byte data[] = new byte[(5 * DWORD) + networkShareString.length + 3]; + + // Put the length value in the first dword + System.arraycopy(intToByteArray(data.length), 0, data, 0 * DWORD, 4); + + // Write the following words + System.arraycopy(intToByteArray(0x2), 0, data, 1 * DWORD, 4); + System.arraycopy(intToByteArray(0x14), 0, data, 2 * DWORD, 4); + System.arraycopy(intToByteArray(0x0), 0, data, 3 * DWORD, 4); + System.arraycopy(intToByteArray(0x200), 0, data, 4 * DWORD, 4); + + // Place the string right after that, then drive letter + System.arraycopy(networkShareString, 0, data, 5 * DWORD, networkShareString.length); + System.arraycopy(new byte[] {(byte) shareDriveLetter, ':'}, 0, data, data.length - 3, 2); + + return data; + } + + private byte[] getStringByteData(String theString) { + byte data[] = null; + + if (theString != null) { + byte string[] = getNullTerminatedBytes(theString.getBytes()); + + // The first 2 bytes tell the size of the string + // The following space is the string itself + data = new byte[2 + string.length]; + + // Put the length value in the first 2 bytes + System.arraycopy(shortToByteArray((short) string.length), 0, data, 0, 2); + + // Place the string right after that + System.arraycopy(string, 0, data, 2, string.length); + } + + return data; + } + + private byte[] getNullTerminatedBytes(byte string[]) { + // Need an array one larger for the null terminator + byte data[] = new byte[string.length + 1]; + + // Place the string into the new array + System.arraycopy(string, 0, data, 0, string.length); + + return data; + } + + private byte[] shortToByteArray(short val) { + byte data[] = new byte[2]; + + for (int i = 0; i < 2; i++) + data[i] = (byte) (0xFF & (val >> i * 8)); + + return data; + } + + private byte[] intToByteArray(int val) { + byte data[] = new byte[4]; + + // 32 bit values seem to be in reverse order + for (int i = 0; i < 4; i++) + data[i] = (byte) (0xFF & (val >> i * 8)); + + return data; + } + + // This is the binary for the OSEE lnk ;-) + private static final byte OSEE[] = + new byte[] {(byte) 0x4C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x14, (byte) 0x02, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xC0, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x46, (byte) 0xFB, (byte) 0x02, (byte) 0x00, + (byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x54, (byte) 0x20, (byte) 0x6E, + (byte) 0x73, (byte) 0x3B, (byte) 0xF8, (byte) 0xC4, (byte) 0x01, (byte) 0xEE, (byte) 0xDF, (byte) 0x76, + (byte) 0x9A, (byte) 0xD4, (byte) 0x83, (byte) 0xC5, (byte) 0x01, (byte) 0x7C, (byte) 0xF6, (byte) 0xA1, + (byte) 0x69, (byte) 0x3B, (byte) 0xF8, (byte) 0xC4, (byte) 0x01, (byte) 0x5F, (byte) 0xC0, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x75, (byte) 0x00, (byte) 0x14, + (byte) 0x00, (byte) 0x1F, (byte) 0x50, (byte) 0xE0, (byte) 0x4F, (byte) 0xD0, (byte) 0x20, (byte) 0xEA, + (byte) 0x3A, (byte) 0x69, (byte) 0x10, (byte) 0xA2, (byte) 0xD8, (byte) 0x08, (byte) 0x00, (byte) 0x2B, + (byte) 0x30, (byte) 0x30, (byte) 0x9D, (byte) 0x19, (byte) 0x00, (byte) 0x23, (byte) 0x43, (byte) 0x3A, + (byte) 0x5C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x91, (byte) 0x65, (byte) 0x15, (byte) 0x00, (byte) 0x31, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xF3, (byte) 0x32, (byte) 0xCA, (byte) 0x7D, + (byte) 0x30, (byte) 0x00, (byte) 0x57, (byte) 0x49, (byte) 0x4E, (byte) 0x4E, (byte) 0x54, (byte) 0x00, + (byte) 0x00, (byte) 0x18, (byte) 0x00, (byte) 0x31, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0xE8, (byte) 0x32, (byte) 0xE1, (byte) 0x6A, (byte) 0x30, (byte) 0x00, (byte) 0x73, + (byte) 0x79, (byte) 0x73, (byte) 0x74, (byte) 0x65, (byte) 0x6D, (byte) 0x33, (byte) 0x32, (byte) 0x00, + (byte) 0x00, (byte) 0x19, (byte) 0x00, (byte) 0x32, (byte) 0x00, (byte) 0x5F, (byte) 0xC0, (byte) 0x00, + (byte) 0x00, (byte) 0x2C, (byte) 0x32, (byte) 0x91, (byte) 0x01, (byte) 0x20, (byte) 0x00, (byte) 0x6A, + (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x77, (byte) 0x2E, (byte) 0x65, (byte) 0x78, (byte) 0x65, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x51, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x1C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x1C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x34, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x1C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x18, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0xC9, (byte) 0x72, (byte) 0x53, (byte) 0xAC, (byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x45, (byte) 0x32, (byte) 0x38, (byte) 0x32, (byte) 0x32, (byte) 0x30, (byte) 0x34, (byte) 0x00, + (byte) 0x43, (byte) 0x3A, (byte) 0x5C, (byte) 0x57, (byte) 0x49, (byte) 0x4E, (byte) 0x4E, (byte) 0x54, + (byte) 0x5C, (byte) 0x73, (byte) 0x79, (byte) 0x73, (byte) 0x74, (byte) 0x65, (byte) 0x6D, (byte) 0x33, + (byte) 0x32, (byte) 0x5C, (byte) 0x6A, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x77, (byte) 0x2E, + (byte) 0x65, (byte) 0x78, (byte) 0x65, (byte) 0x00, (byte) 0x00, (byte) 0x21, (byte) 0x00, (byte) 0x2E, + (byte) 0x00, (byte) 0x2E, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x2E, (byte) 0x00, (byte) 0x2E, + (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x2E, (byte) 0x00, (byte) 0x2E, (byte) 0x00, (byte) 0x5C, + (byte) 0x00, (byte) 0x57, (byte) 0x00, (byte) 0x49, (byte) 0x00, (byte) 0x4E, (byte) 0x00, (byte) 0x4E, + (byte) 0x00, (byte) 0x54, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x73, (byte) 0x00, (byte) 0x79, + (byte) 0x00, (byte) 0x73, (byte) 0x00, (byte) 0x74, (byte) 0x00, (byte) 0x65, (byte) 0x00, (byte) 0x6D, + (byte) 0x00, (byte) 0x33, (byte) 0x00, (byte) 0x32, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x6A, + (byte) 0x00, (byte) 0x61, (byte) 0x00, (byte) 0x76, (byte) 0x00, (byte) 0x61, (byte) 0x00, (byte) 0x77, + (byte) 0x00, (byte) 0x2E, (byte) 0x00, (byte) 0x65, (byte) 0x00, (byte) 0x78, (byte) 0x00, (byte) 0x65, + (byte) 0x00, (byte) 0x12, (byte) 0x00, (byte) 0x59, (byte) 0x00, (byte) 0x3A, (byte) 0x00, (byte) 0x5C, + (byte) 0x00, (byte) 0x4F, (byte) 0x00, (byte) 0x53, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x45, + (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x77, (byte) 0x00, (byte) 0x69, (byte) 0x00, (byte) 0x6E, + (byte) 0x00, (byte) 0x33, (byte) 0x00, (byte) 0x32, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x4F, + (byte) 0x00, (byte) 0x53, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x29, + (byte) 0x00, (byte) 0x2D, (byte) 0x00, (byte) 0x58, (byte) 0x00, (byte) 0x6D, (byte) 0x00, (byte) 0x78, + (byte) 0x00, (byte) 0x35, (byte) 0x00, (byte) 0x31, (byte) 0x00, (byte) 0x32, (byte) 0x00, (byte) 0x4D, + (byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x2D, (byte) 0x00, (byte) 0x6A, (byte) 0x00, (byte) 0x61, + (byte) 0x00, (byte) 0x72, (byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x59, (byte) 0x00, (byte) 0x3A, + (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x4F, (byte) 0x00, (byte) 0x53, (byte) 0x00, (byte) 0x45, + (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x77, (byte) 0x00, (byte) 0x69, + (byte) 0x00, (byte) 0x6E, (byte) 0x00, (byte) 0x33, (byte) 0x00, (byte) 0x32, (byte) 0x00, (byte) 0x5C, + (byte) 0x00, (byte) 0x4F, (byte) 0x00, (byte) 0x53, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x45, + (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x4F, (byte) 0x00, (byte) 0x53, (byte) 0x00, (byte) 0x45, + (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x2E, (byte) 0x00, (byte) 0x6A, (byte) 0x00, (byte) 0x61, + (byte) 0x00, (byte) 0x72, (byte) 0x00, (byte) 0x1B, (byte) 0x00, (byte) 0x59, (byte) 0x00, (byte) 0x3A, + (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x4F, (byte) 0x00, (byte) 0x53, (byte) 0x00, (byte) 0x45, + (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x77, (byte) 0x00, (byte) 0x69, + (byte) 0x00, (byte) 0x6E, (byte) 0x00, (byte) 0x33, (byte) 0x00, (byte) 0x32, (byte) 0x00, (byte) 0x5C, + (byte) 0x00, (byte) 0x4F, (byte) 0x00, (byte) 0x53, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x45, + (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x4F, (byte) 0x00, (byte) 0x53, (byte) 0x00, (byte) 0x45, + (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x2E, (byte) 0x00, (byte) 0x69, (byte) 0x00, (byte) 0x63, + (byte) 0x00, (byte) 0x6F, (byte) 0x00, (byte) 0x14, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x01, + (byte) 0x00, (byte) 0x00, (byte) 0xA0, (byte) 0x25, (byte) 0x53, (byte) 0x79, (byte) 0x73, (byte) 0x74, + (byte) 0x65, (byte) 0x6D, (byte) 0x52, (byte) 0x6F, (byte) 0x6F, (byte) 0x74, (byte) 0x25, (byte) 0x5C, + (byte) 0x73, (byte) 0x79, (byte) 0x73, (byte) 0x74, (byte) 0x65, (byte) 0x6D, (byte) 0x33, (byte) 0x32, + (byte) 0x5C, (byte) 0x6A, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x77, (byte) 0x2E, (byte) 0x65, + (byte) 0x78, (byte) 0x65, (byte) 0x00, (byte) 0x4C, (byte) 0x82, (byte) 0x57, (byte) 0x7C, (byte) 0x7B, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x33, (byte) 0x00, (byte) 0x00, (byte) 0xC0, (byte) 0x78, + (byte) 0x74, (byte) 0x58, (byte) 0x7C, (byte) 0x33, (byte) 0x00, (byte) 0x00, (byte) 0xC0, (byte) 0xE8, + (byte) 0xF1, (byte) 0xE3, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xC3, + (byte) 0x52, (byte) 0x58, (byte) 0x7C, (byte) 0x0D, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x18, + (byte) 0xEB, (byte) 0xE3, (byte) 0x03, (byte) 0xFC, (byte) 0x5F, (byte) 0xE4, (byte) 0x77, (byte) 0x30, + (byte) 0x75, (byte) 0x48, (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, + (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xDC, (byte) 0xEF, (byte) 0xE3, (byte) 0x03, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x6C, (byte) 0x41, (byte) 0xB9, (byte) 0xB3, + (byte) 0x5F, (byte) 0xE4, (byte) 0x77, (byte) 0x18, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xF0, + (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x3C, (byte) 0xEB, (byte) 0xE3, (byte) 0x03, (byte) 0x40, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x92, (byte) 0x00, (byte) 0x92, (byte) 0x00, (byte) 0xB6, + (byte) 0xE8, (byte) 0x56, (byte) 0x04, (byte) 0xF0, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x92, + (byte) 0x00, (byte) 0x92, (byte) 0x00, (byte) 0xB6, (byte) 0xE8, (byte) 0x56, (byte) 0x04, (byte) 0x64, + (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0x5B, (byte) 0xDA, (byte) 0xA9, (byte) 0x70, (byte) 0xE8, + (byte) 0xF1, (byte) 0xE3, (byte) 0x03, (byte) 0xDC, (byte) 0xEF, (byte) 0xE3, (byte) 0x03, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xD8, (byte) 0xEC, (byte) 0xE3, (byte) 0x03, (byte) 0x7C, + (byte) 0xEB, (byte) 0xE3, (byte) 0x03, (byte) 0x13, (byte) 0x50, (byte) 0xE2, (byte) 0x77, (byte) 0xB3, + (byte) 0x5F, (byte) 0xE4, (byte) 0x77, (byte) 0x7A, (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0x0D, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xDC, + (byte) 0xEF, (byte) 0xE3, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x98, + (byte) 0xEB, (byte) 0xE3, (byte) 0x03, (byte) 0xF0, (byte) 0x21, (byte) 0x75, (byte) 0x71, (byte) 0xB3, + (byte) 0x5F, (byte) 0xE4, (byte) 0x77, (byte) 0x7A, (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0x0D, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xDC, + (byte) 0xEF, (byte) 0xE3, (byte) 0x03, (byte) 0xF4, (byte) 0xEB, (byte) 0xE3, (byte) 0x03, (byte) 0x6F, + (byte) 0x27, (byte) 0x75, (byte) 0x71, (byte) 0x7A, (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0x0D, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xDC, + (byte) 0xEF, (byte) 0xE3, (byte) 0x03, (byte) 0x9B, (byte) 0x27, (byte) 0x75, (byte) 0x71, (byte) 0x25, + (byte) 0x00, (byte) 0x53, (byte) 0x00, (byte) 0x79, (byte) 0x00, (byte) 0x73, (byte) 0x00, (byte) 0x74, + (byte) 0x00, (byte) 0x65, (byte) 0x00, (byte) 0x6D, (byte) 0x00, (byte) 0x52, (byte) 0x00, (byte) 0x6F, + (byte) 0x00, (byte) 0x6F, (byte) 0x00, (byte) 0x74, (byte) 0x00, (byte) 0x25, (byte) 0x00, (byte) 0x5C, + (byte) 0x00, (byte) 0x73, (byte) 0x00, (byte) 0x79, (byte) 0x00, (byte) 0x73, (byte) 0x00, (byte) 0x74, + (byte) 0x00, (byte) 0x65, (byte) 0x00, (byte) 0x6D, (byte) 0x00, (byte) 0x33, (byte) 0x00, (byte) 0x32, + (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x6A, (byte) 0x00, (byte) 0x61, (byte) 0x00, (byte) 0x76, + (byte) 0x00, (byte) 0x61, (byte) 0x00, (byte) 0x77, (byte) 0x00, (byte) 0x2E, (byte) 0x00, (byte) 0x65, + (byte) 0x00, (byte) 0x78, (byte) 0x00, (byte) 0x65, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x18, + (byte) 0xEC, (byte) 0xE3, (byte) 0x03, (byte) 0x74, (byte) 0x25, (byte) 0x75, (byte) 0x71, (byte) 0x20, + (byte) 0xFC, (byte) 0x51, (byte) 0x04, (byte) 0x7A, (byte) 0xF2, (byte) 0xE3, (byte) 0x03, (byte) 0x00, + (byte) 0x00, (byte) 0x07, (byte) 0x00, (byte) 0x54, (byte) 0xEC, (byte) 0xE3, (byte) 0x03, (byte) 0xD0, + (byte) 0x57, (byte) 0xF8, (byte) 0x77, (byte) 0xEC, (byte) 0x57, (byte) 0xF8, (byte) 0x77, (byte) 0x08, + (byte) 0x06, (byte) 0x07, (byte) 0x00, (byte) 0x30, (byte) 0x00, (byte) 0x0D, (byte) 0x01, (byte) 0x05, + (byte) 0x96, (byte) 0x57, (byte) 0x7C, (byte) 0x00, (byte) 0x00, (byte) 0x07, (byte) 0x00, (byte) 0x7A, + (byte) 0xF2, (byte) 0xE3, (byte) 0x03, (byte) 0xE8, (byte) 0x3C, (byte) 0x0F, (byte) 0x00, (byte) 0x49, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x30, (byte) 0x00, (byte) 0x0D, (byte) 0x01, (byte) 0x30, + (byte) 0x00, (byte) 0x0D, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x24, + (byte) 0xEC, (byte) 0xE3, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xE0, + (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0x44, (byte) 0x1F, (byte) 0x5C, (byte) 0x7C, (byte) 0x50, + (byte) 0x24, (byte) 0x57, (byte) 0x7C, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x78, + (byte) 0xEC, (byte) 0xE3, (byte) 0x03, (byte) 0x30, (byte) 0x77, (byte) 0xE1, (byte) 0x77, (byte) 0x34, + (byte) 0x00, (byte) 0x0D, (byte) 0x01, (byte) 0x87, (byte) 0x78, (byte) 0xE1, (byte) 0x77, (byte) 0x34, + (byte) 0x00, (byte) 0x0D, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x2F, (byte) 0x78, (byte) 0xB2, + (byte) 0xFC, (byte) 0x51, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x90, (byte) 0xEC, (byte) 0xE3, (byte) 0x03, (byte) 0x0A, + (byte) 0x78, (byte) 0xE1, (byte) 0x77, (byte) 0xE8, (byte) 0x3C, (byte) 0x0F, (byte) 0x00, (byte) 0xE8, + (byte) 0x3C, (byte) 0x0F, (byte) 0x00, (byte) 0x30, (byte) 0x75, (byte) 0x48, (byte) 0x00, (byte) 0x7A, + (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0xCC, (byte) 0xEC, (byte) 0xE3, (byte) 0x03, (byte) 0x05, + (byte) 0x7B, (byte) 0xE1, (byte) 0x77, (byte) 0xE8, (byte) 0x3C, (byte) 0x0F, (byte) 0x00, (byte) 0x04, + (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xE8, (byte) 0xF1, (byte) 0xE3, (byte) 0x03, (byte) 0x01, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA8, (byte) 0x19, (byte) 0x2F, (byte) 0x00, (byte) 0x30, + (byte) 0x75, (byte) 0x48, (byte) 0x00, (byte) 0x7A, (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0x20, + (byte) 0x34, (byte) 0xE1, (byte) 0x77, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x08, + (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0x76, (byte) 0x26, (byte) 0x75, (byte) 0x71, (byte) 0x7A, + (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0x49, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xF0, + (byte) 0xEC, (byte) 0xE3, (byte) 0x03, (byte) 0xD7, (byte) 0x79, (byte) 0xE1, (byte) 0x77, (byte) 0x30, + (byte) 0x75, (byte) 0x48, (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, + (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xE8, (byte) 0xF1, (byte) 0xE3, (byte) 0x03, (byte) 0xA8, + (byte) 0x19, (byte) 0x2F, (byte) 0x00, (byte) 0x30, (byte) 0x75, (byte) 0x48, (byte) 0x00, (byte) 0x0D, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x14, (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0xFC, + (byte) 0x5F, (byte) 0xE4, (byte) 0x77, (byte) 0x30, (byte) 0x75, (byte) 0x48, (byte) 0x00, (byte) 0x0D, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xE8, + (byte) 0xF1, (byte) 0xE3, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0D, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xB3, (byte) 0x5F, (byte) 0xE4, (byte) 0x77, (byte) 0x34, + (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0xD0, (byte) 0xA3, (byte) 0xE3, (byte) 0x77, (byte) 0x7A, + (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, + (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xE8, (byte) 0xF1, (byte) 0xE3, (byte) 0x03, (byte) 0xB3, + (byte) 0x5F, (byte) 0xE4, (byte) 0x77, (byte) 0xCD, (byte) 0xAB, (byte) 0xBA, (byte) 0xDC, (byte) 0x58, + (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0xA6, (byte) 0x52, (byte) 0x58, (byte) 0x7C, (byte) 0xFF, + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x0C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x50, + (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0xEF, (byte) 0x52, (byte) 0x58, (byte) 0x7C, (byte) 0xFF, + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x0C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x60, + (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0xA4, + (byte) 0xEF, (byte) 0xE3, (byte) 0x03, (byte) 0x75, (byte) 0x4E, (byte) 0xAA, (byte) 0x70, (byte) 0x01, + (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xE8, + (byte) 0xF1, (byte) 0xE3, (byte) 0x03, (byte) 0xD8, (byte) 0x8F, (byte) 0x52, (byte) 0x04, (byte) 0xF0, + (byte) 0x21, (byte) 0x75, (byte) 0x71, (byte) 0xB3, (byte) 0x5F, (byte) 0xE4, (byte) 0x77, (byte) 0x7A, + (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, + (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xE8, (byte) 0xF1, (byte) 0xE3, (byte) 0x03, (byte) 0xF0, + (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0x6F, (byte) 0x27, (byte) 0x75, (byte) 0x71, (byte) 0x7A, + (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, + (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xE8, (byte) 0xF1, (byte) 0xE3, (byte) 0x03, (byte) 0x9B, + (byte) 0x27, (byte) 0x75, (byte) 0x71, (byte) 0xD4, (byte) 0xEE, (byte) 0xE3, (byte) 0x03, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x80, (byte) 0x04, (byte) 0x52, (byte) 0x04, (byte) 0x60, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0xA0, (byte) 0x58, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x65, + (byte) 0x32, (byte) 0x38, (byte) 0x32, (byte) 0x32, (byte) 0x30, (byte) 0x34, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x06, + (byte) 0xA0, (byte) 0x78, (byte) 0xF9, (byte) 0x08, (byte) 0x80, (byte) 0xFF, (byte) 0x4E, (byte) 0x9C, + (byte) 0x47, (byte) 0xF1, (byte) 0xD0, (byte) 0x77, (byte) 0xFE, (byte) 0x54, (byte) 0xB6, (byte) 0x46, + (byte) 0x18, (byte) 0x99, (byte) 0x1F, (byte) 0xA2, (byte) 0xE1, (byte) 0xD9, (byte) 0x11, (byte) 0x86, + (byte) 0xC3, (byte) 0x00, (byte) 0x0F, (byte) 0x1F, (byte) 0xD8, (byte) 0x1B, (byte) 0x0F, (byte) 0x06, + (byte) 0xA0, (byte) 0x78, (byte) 0xF9, (byte) 0x08, (byte) 0x80, (byte) 0xFF, (byte) 0x4E, (byte) 0x9C, + (byte) 0x47, (byte) 0xF1, (byte) 0xD0, (byte) 0x77, (byte) 0xFE, (byte) 0x54, (byte) 0xB6, (byte) 0x46, + (byte) 0x18, (byte) 0x99, (byte) 0x1F, (byte) 0xA2, (byte) 0xE1, (byte) 0xD9, (byte) 0x11, (byte) 0x86, + (byte) 0xC3, (byte) 0x00, (byte) 0x0F, (byte) 0x1F, (byte) 0xD8, (byte) 0x1B, (byte) 0x0F, (byte) 0x10, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0x00, (byte) 0x00, (byte) 0xA0, (byte) 0x24, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00}; + + // This is the binary for the OSEE_MS lnk ;-) + private static final byte[] OSEE_MS = + new byte[] {(byte) 0x4C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x14, (byte) 0x02, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xC0, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x46, (byte) 0xFB, (byte) 0x02, (byte) 0x00, + (byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x54, (byte) 0x20, (byte) 0x6E, + (byte) 0x73, (byte) 0x3B, (byte) 0xF8, (byte) 0xC4, (byte) 0x01, (byte) 0xAB, (byte) 0x00, (byte) 0xE4, + (byte) 0x8F, (byte) 0xA2, (byte) 0x9E, (byte) 0xC5, (byte) 0x01, (byte) 0x7C, (byte) 0xF6, (byte) 0xA1, + (byte) 0x69, (byte) 0x3B, (byte) 0xF8, (byte) 0xC4, (byte) 0x01, (byte) 0x5F, (byte) 0xC0, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x9E, (byte) 0x00, (byte) 0x14, + (byte) 0x00, (byte) 0x1F, (byte) 0x50, (byte) 0xE0, (byte) 0x4F, (byte) 0xD0, (byte) 0x20, (byte) 0xEA, + (byte) 0x3A, (byte) 0x69, (byte) 0x10, (byte) 0xA2, (byte) 0xD8, (byte) 0x08, (byte) 0x00, (byte) 0x2B, + (byte) 0x30, (byte) 0x30, (byte) 0x9D, (byte) 0x19, (byte) 0x00, (byte) 0x23, (byte) 0x43, (byte) 0x3A, + (byte) 0x5C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x91, (byte) 0x65, (byte) 0x15, (byte) 0x00, (byte) 0x31, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x17, (byte) 0x33, (byte) 0xB5, (byte) 0xBB, + (byte) 0x30, (byte) 0x00, (byte) 0x57, (byte) 0x49, (byte) 0x4E, (byte) 0x4E, (byte) 0x54, (byte) 0x00, + (byte) 0x00, (byte) 0x18, (byte) 0x00, (byte) 0x31, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x08, (byte) 0x33, (byte) 0x1D, (byte) 0x6E, (byte) 0x30, (byte) 0x00, (byte) 0x73, + (byte) 0x79, (byte) 0x73, (byte) 0x74, (byte) 0x65, (byte) 0x6D, (byte) 0x33, (byte) 0x32, (byte) 0x00, + (byte) 0x00, (byte) 0x42, (byte) 0x00, (byte) 0x32, (byte) 0x00, (byte) 0x5F, (byte) 0xC0, (byte) 0x00, + (byte) 0x00, (byte) 0xE5, (byte) 0x32, (byte) 0x10, (byte) 0x89, (byte) 0x20, (byte) 0x00, (byte) 0x6A, + (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x77, (byte) 0x2E, (byte) 0x65, (byte) 0x78, (byte) 0x65, + (byte) 0x00, (byte) 0x2A, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0xEF, + (byte) 0xBE, (byte) 0xE5, (byte) 0x32, (byte) 0x19, (byte) 0x89, (byte) 0x04, (byte) 0x33, (byte) 0x60, + (byte) 0x8D, (byte) 0x14, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x6A, (byte) 0x00, (byte) 0x61, + (byte) 0x00, (byte) 0x76, (byte) 0x00, (byte) 0x61, (byte) 0x00, (byte) 0x77, (byte) 0x00, (byte) 0x2E, + (byte) 0x00, (byte) 0x65, (byte) 0x00, (byte) 0x78, (byte) 0x00, (byte) 0x65, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x18, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x4C, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x1C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x1C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2D, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x4B, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x11, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x34, (byte) 0xCC, (byte) 0xE0, (byte) 0x84, (byte) 0x10, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x43, (byte) 0x3A, (byte) 0x5C, (byte) 0x57, (byte) 0x49, (byte) 0x4E, + (byte) 0x44, (byte) 0x4F, (byte) 0x57, (byte) 0x53, (byte) 0x5C, (byte) 0x73, (byte) 0x79, (byte) 0x73, + (byte) 0x74, (byte) 0x65, (byte) 0x6D, (byte) 0x33, (byte) 0x32, (byte) 0x5C, (byte) 0x6A, (byte) 0x61, + (byte) 0x76, (byte) 0x61, (byte) 0x77, (byte) 0x2E, (byte) 0x65, (byte) 0x78, (byte) 0x65, (byte) 0x00, + (byte) 0x00, (byte) 0x1A, (byte) 0x00, (byte) 0x2E, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x57, + (byte) 0x00, (byte) 0x49, (byte) 0x00, (byte) 0x4E, (byte) 0x00, (byte) 0x4E, (byte) 0x00, (byte) 0x54, + (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x73, (byte) 0x00, (byte) 0x79, (byte) 0x00, (byte) 0x73, + (byte) 0x00, (byte) 0x74, (byte) 0x00, (byte) 0x65, (byte) 0x00, (byte) 0x6D, (byte) 0x00, (byte) 0x33, + (byte) 0x00, (byte) 0x32, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x6A, (byte) 0x00, (byte) 0x61, + (byte) 0x00, (byte) 0x76, (byte) 0x00, (byte) 0x61, (byte) 0x00, (byte) 0x77, (byte) 0x00, (byte) 0x2E, + (byte) 0x00, (byte) 0x65, (byte) 0x00, (byte) 0x78, (byte) 0x00, (byte) 0x65, (byte) 0x00, (byte) 0x15, + (byte) 0x00, (byte) 0x59, (byte) 0x00, (byte) 0x3A, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x4F, + (byte) 0x00, (byte) 0x53, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x5C, + (byte) 0x00, (byte) 0x77, (byte) 0x00, (byte) 0x69, (byte) 0x00, (byte) 0x6E, (byte) 0x00, (byte) 0x33, + (byte) 0x00, (byte) 0x32, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x4F, (byte) 0x00, (byte) 0x53, + (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x5F, (byte) 0x00, (byte) 0x4D, + (byte) 0x00, (byte) 0x53, (byte) 0x00, (byte) 0x2C, (byte) 0x00, (byte) 0x2D, (byte) 0x00, (byte) 0x58, + (byte) 0x00, (byte) 0x6D, (byte) 0x00, (byte) 0x78, (byte) 0x00, (byte) 0x35, (byte) 0x00, (byte) 0x31, + (byte) 0x00, (byte) 0x32, (byte) 0x00, (byte) 0x4D, (byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x2D, + (byte) 0x00, (byte) 0x6A, (byte) 0x00, (byte) 0x61, (byte) 0x00, (byte) 0x72, (byte) 0x00, (byte) 0x20, + (byte) 0x00, (byte) 0x59, (byte) 0x00, (byte) 0x3A, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x4F, + (byte) 0x00, (byte) 0x53, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x5C, + (byte) 0x00, (byte) 0x77, (byte) 0x00, (byte) 0x69, (byte) 0x00, (byte) 0x6E, (byte) 0x00, (byte) 0x33, + (byte) 0x00, (byte) 0x32, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x4F, (byte) 0x00, (byte) 0x53, + (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x5F, (byte) 0x00, (byte) 0x4D, + (byte) 0x00, (byte) 0x53, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x4F, (byte) 0x00, (byte) 0x53, + (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x2E, (byte) 0x00, (byte) 0x6A, + (byte) 0x00, (byte) 0x61, (byte) 0x00, (byte) 0x72, (byte) 0x00, (byte) 0x1B, (byte) 0x00, (byte) 0x59, + (byte) 0x00, (byte) 0x3A, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x4F, (byte) 0x00, (byte) 0x53, + (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x77, + (byte) 0x00, (byte) 0x69, (byte) 0x00, (byte) 0x6E, (byte) 0x00, (byte) 0x33, (byte) 0x00, (byte) 0x32, + (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x4F, (byte) 0x00, (byte) 0x53, (byte) 0x00, (byte) 0x45, + (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x4F, (byte) 0x00, (byte) 0x53, + (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x2E, (byte) 0x00, (byte) 0x69, + (byte) 0x00, (byte) 0x63, (byte) 0x00, (byte) 0x6F, (byte) 0x00, (byte) 0x14, (byte) 0x03, (byte) 0x00, + (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xA0, (byte) 0x25, (byte) 0x53, (byte) 0x79, + (byte) 0x73, (byte) 0x74, (byte) 0x65, (byte) 0x6D, (byte) 0x52, (byte) 0x6F, (byte) 0x6F, (byte) 0x74, + (byte) 0x25, (byte) 0x5C, (byte) 0x73, (byte) 0x79, (byte) 0x73, (byte) 0x74, (byte) 0x65, (byte) 0x6D, + (byte) 0x33, (byte) 0x32, (byte) 0x5C, (byte) 0x6A, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x77, + (byte) 0x2E, (byte) 0x65, (byte) 0x78, (byte) 0x65, (byte) 0x00, (byte) 0x4C, (byte) 0x82, (byte) 0x57, + (byte) 0x7C, (byte) 0x7B, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x33, (byte) 0x00, (byte) 0x00, + (byte) 0xC0, (byte) 0x78, (byte) 0x74, (byte) 0x58, (byte) 0x7C, (byte) 0x33, (byte) 0x00, (byte) 0x00, + (byte) 0xC0, (byte) 0xE8, (byte) 0xF1, (byte) 0xE3, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0xC3, (byte) 0x52, (byte) 0x58, (byte) 0x7C, (byte) 0x0D, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x18, (byte) 0xEB, (byte) 0xE3, (byte) 0x03, (byte) 0xFC, (byte) 0x5F, (byte) 0xE4, + (byte) 0x77, (byte) 0x30, (byte) 0x75, (byte) 0x48, (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x04, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xDC, (byte) 0xEF, (byte) 0xE3, + (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x6C, (byte) 0x41, + (byte) 0xB9, (byte) 0xB3, (byte) 0x5F, (byte) 0xE4, (byte) 0x77, (byte) 0x18, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0xF0, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x3C, (byte) 0xEB, (byte) 0xE3, + (byte) 0x03, (byte) 0x40, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x92, (byte) 0x00, (byte) 0x92, + (byte) 0x00, (byte) 0xB6, (byte) 0xE8, (byte) 0x56, (byte) 0x04, (byte) 0xF0, (byte) 0x08, (byte) 0x00, + (byte) 0x00, (byte) 0x92, (byte) 0x00, (byte) 0x92, (byte) 0x00, (byte) 0xB6, (byte) 0xE8, (byte) 0x56, + (byte) 0x04, (byte) 0x64, (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0x5B, (byte) 0xDA, (byte) 0xA9, + (byte) 0x70, (byte) 0xE8, (byte) 0xF1, (byte) 0xE3, (byte) 0x03, (byte) 0xDC, (byte) 0xEF, (byte) 0xE3, + (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xD8, (byte) 0xEC, (byte) 0xE3, + (byte) 0x03, (byte) 0x7C, (byte) 0xEB, (byte) 0xE3, (byte) 0x03, (byte) 0x13, (byte) 0x50, (byte) 0xE2, + (byte) 0x77, (byte) 0xB3, (byte) 0x5F, (byte) 0xE4, (byte) 0x77, (byte) 0x7A, (byte) 0x03, (byte) 0x0D, + (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x01, (byte) 0x00, + (byte) 0x00, (byte) 0xDC, (byte) 0xEF, (byte) 0xE3, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x98, (byte) 0xEB, (byte) 0xE3, (byte) 0x03, (byte) 0xF0, (byte) 0x21, (byte) 0x75, + (byte) 0x71, (byte) 0xB3, (byte) 0x5F, (byte) 0xE4, (byte) 0x77, (byte) 0x7A, (byte) 0x03, (byte) 0x0D, + (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x01, (byte) 0x00, + (byte) 0x00, (byte) 0xDC, (byte) 0xEF, (byte) 0xE3, (byte) 0x03, (byte) 0xF4, (byte) 0xEB, (byte) 0xE3, + (byte) 0x03, (byte) 0x6F, (byte) 0x27, (byte) 0x75, (byte) 0x71, (byte) 0x7A, (byte) 0x03, (byte) 0x0D, + (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x01, (byte) 0x00, + (byte) 0x00, (byte) 0xDC, (byte) 0xEF, (byte) 0xE3, (byte) 0x03, (byte) 0x9B, (byte) 0x27, (byte) 0x75, + (byte) 0x71, (byte) 0x25, (byte) 0x00, (byte) 0x53, (byte) 0x00, (byte) 0x79, (byte) 0x00, (byte) 0x73, + (byte) 0x00, (byte) 0x74, (byte) 0x00, (byte) 0x65, (byte) 0x00, (byte) 0x6D, (byte) 0x00, (byte) 0x52, + (byte) 0x00, (byte) 0x6F, (byte) 0x00, (byte) 0x6F, (byte) 0x00, (byte) 0x74, (byte) 0x00, (byte) 0x25, + (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x73, (byte) 0x00, (byte) 0x79, (byte) 0x00, (byte) 0x73, + (byte) 0x00, (byte) 0x74, (byte) 0x00, (byte) 0x65, (byte) 0x00, (byte) 0x6D, (byte) 0x00, (byte) 0x33, + (byte) 0x00, (byte) 0x32, (byte) 0x00, (byte) 0x5C, (byte) 0x00, (byte) 0x6A, (byte) 0x00, (byte) 0x61, + (byte) 0x00, (byte) 0x76, (byte) 0x00, (byte) 0x61, (byte) 0x00, (byte) 0x77, (byte) 0x00, (byte) 0x2E, + (byte) 0x00, (byte) 0x65, (byte) 0x00, (byte) 0x78, (byte) 0x00, (byte) 0x65, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x18, (byte) 0xEC, (byte) 0xE3, (byte) 0x03, (byte) 0x74, (byte) 0x25, (byte) 0x75, + (byte) 0x71, (byte) 0x20, (byte) 0xFC, (byte) 0x51, (byte) 0x04, (byte) 0x7A, (byte) 0xF2, (byte) 0xE3, + (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x07, (byte) 0x00, (byte) 0x54, (byte) 0xEC, (byte) 0xE3, + (byte) 0x03, (byte) 0xD0, (byte) 0x57, (byte) 0xF8, (byte) 0x77, (byte) 0xEC, (byte) 0x57, (byte) 0xF8, + (byte) 0x77, (byte) 0x08, (byte) 0x06, (byte) 0x07, (byte) 0x00, (byte) 0x30, (byte) 0x00, (byte) 0x0D, + (byte) 0x01, (byte) 0x05, (byte) 0x96, (byte) 0x57, (byte) 0x7C, (byte) 0x00, (byte) 0x00, (byte) 0x07, + (byte) 0x00, (byte) 0x7A, (byte) 0xF2, (byte) 0xE3, (byte) 0x03, (byte) 0xE8, (byte) 0x3C, (byte) 0x0F, + (byte) 0x00, (byte) 0x49, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x30, (byte) 0x00, (byte) 0x0D, + (byte) 0x01, (byte) 0x30, (byte) 0x00, (byte) 0x0D, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x24, (byte) 0xEC, (byte) 0xE3, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0xE0, (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0x44, (byte) 0x1F, (byte) 0x5C, + (byte) 0x7C, (byte) 0x50, (byte) 0x24, (byte) 0x57, (byte) 0x7C, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + (byte) 0xFF, (byte) 0x78, (byte) 0xEC, (byte) 0xE3, (byte) 0x03, (byte) 0x30, (byte) 0x77, (byte) 0xE1, + (byte) 0x77, (byte) 0x34, (byte) 0x00, (byte) 0x0D, (byte) 0x01, (byte) 0x87, (byte) 0x78, (byte) 0xE1, + (byte) 0x77, (byte) 0x34, (byte) 0x00, (byte) 0x0D, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x2F, + (byte) 0x78, (byte) 0xB2, (byte) 0xFC, (byte) 0x51, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x90, (byte) 0xEC, (byte) 0xE3, + (byte) 0x03, (byte) 0x0A, (byte) 0x78, (byte) 0xE1, (byte) 0x77, (byte) 0xE8, (byte) 0x3C, (byte) 0x0F, + (byte) 0x00, (byte) 0xE8, (byte) 0x3C, (byte) 0x0F, (byte) 0x00, (byte) 0x30, (byte) 0x75, (byte) 0x48, + (byte) 0x00, (byte) 0x7A, (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0xCC, (byte) 0xEC, (byte) 0xE3, + (byte) 0x03, (byte) 0x05, (byte) 0x7B, (byte) 0xE1, (byte) 0x77, (byte) 0xE8, (byte) 0x3C, (byte) 0x0F, + (byte) 0x00, (byte) 0x04, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xE8, (byte) 0xF1, (byte) 0xE3, + (byte) 0x03, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA8, (byte) 0x19, (byte) 0x2F, + (byte) 0x00, (byte) 0x30, (byte) 0x75, (byte) 0x48, (byte) 0x00, (byte) 0x7A, (byte) 0x03, (byte) 0x0D, + (byte) 0x00, (byte) 0x20, (byte) 0x34, (byte) 0xE1, (byte) 0x77, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + (byte) 0xFF, (byte) 0x08, (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0x76, (byte) 0x26, (byte) 0x75, + (byte) 0x71, (byte) 0x7A, (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0x49, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0xF0, (byte) 0xEC, (byte) 0xE3, (byte) 0x03, (byte) 0xD7, (byte) 0x79, (byte) 0xE1, + (byte) 0x77, (byte) 0x30, (byte) 0x75, (byte) 0x48, (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x04, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xE8, (byte) 0xF1, (byte) 0xE3, + (byte) 0x03, (byte) 0xA8, (byte) 0x19, (byte) 0x2F, (byte) 0x00, (byte) 0x30, (byte) 0x75, (byte) 0x48, + (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x14, (byte) 0xED, (byte) 0xE3, + (byte) 0x03, (byte) 0xFC, (byte) 0x5F, (byte) 0xE4, (byte) 0x77, (byte) 0x30, (byte) 0x75, (byte) 0x48, + (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x01, (byte) 0x00, + (byte) 0x00, (byte) 0xE8, (byte) 0xF1, (byte) 0xE3, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xB3, (byte) 0x5F, (byte) 0xE4, + (byte) 0x77, (byte) 0x34, (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0xD0, (byte) 0xA3, (byte) 0xE3, + (byte) 0x77, (byte) 0x7A, (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x04, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xE8, (byte) 0xF1, (byte) 0xE3, + (byte) 0x03, (byte) 0xB3, (byte) 0x5F, (byte) 0xE4, (byte) 0x77, (byte) 0xCD, (byte) 0xAB, (byte) 0xBA, + (byte) 0xDC, (byte) 0x58, (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0xA6, (byte) 0x52, (byte) 0x58, + (byte) 0x7C, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x0C, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x50, (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0xEF, (byte) 0x52, (byte) 0x58, + (byte) 0x7C, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x0C, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x60, (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0x04, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x80, (byte) 0x00, + (byte) 0x00, (byte) 0xA4, (byte) 0xEF, (byte) 0xE3, (byte) 0x03, (byte) 0x75, (byte) 0x4E, (byte) 0xAA, + (byte) 0x70, (byte) 0x01, (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0xE8, (byte) 0xF1, (byte) 0xE3, (byte) 0x03, (byte) 0xD8, (byte) 0x8F, (byte) 0x52, + (byte) 0x04, (byte) 0xF0, (byte) 0x21, (byte) 0x75, (byte) 0x71, (byte) 0xB3, (byte) 0x5F, (byte) 0xE4, + (byte) 0x77, (byte) 0x7A, (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x04, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xE8, (byte) 0xF1, (byte) 0xE3, + (byte) 0x03, (byte) 0xF0, (byte) 0xED, (byte) 0xE3, (byte) 0x03, (byte) 0x6F, (byte) 0x27, (byte) 0x75, + (byte) 0x71, (byte) 0x7A, (byte) 0x03, (byte) 0x0D, (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x04, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xE8, (byte) 0xF1, (byte) 0xE3, + (byte) 0x03, (byte) 0x9B, (byte) 0x27, (byte) 0x75, (byte) 0x71, (byte) 0xD4, (byte) 0xEE, (byte) 0xE3, + (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x80, (byte) 0x04, (byte) 0x52, + (byte) 0x04, (byte) 0x60, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, + (byte) 0xA0, (byte) 0x58, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x65, (byte) 0x32, (byte) 0x38, (byte) 0x32, (byte) 0x32, (byte) 0x30, (byte) 0x34, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x06, (byte) 0xA0, (byte) 0x78, (byte) 0xF9, (byte) 0x08, (byte) 0x80, (byte) 0xFF, + (byte) 0x4E, (byte) 0x9C, (byte) 0x47, (byte) 0xF1, (byte) 0xD0, (byte) 0x77, (byte) 0xFE, (byte) 0x54, + (byte) 0xB6, (byte) 0x46, (byte) 0x18, (byte) 0x99, (byte) 0x1F, (byte) 0xA2, (byte) 0xE1, (byte) 0xD9, + (byte) 0x11, (byte) 0x86, (byte) 0xC3, (byte) 0x00, (byte) 0x0F, (byte) 0x1F, (byte) 0xD8, (byte) 0x1B, + (byte) 0x0F, (byte) 0x06, (byte) 0xA0, (byte) 0x78, (byte) 0xF9, (byte) 0x08, (byte) 0x80, (byte) 0xFF, + (byte) 0x4E, (byte) 0x9C, (byte) 0x47, (byte) 0xF1, (byte) 0xD0, (byte) 0x77, (byte) 0xFE, (byte) 0x54, + (byte) 0xB6, (byte) 0x46, (byte) 0x18, (byte) 0x99, (byte) 0x1F, (byte) 0xA2, (byte) 0xE1, (byte) 0xD9, + (byte) 0x11, (byte) 0x86, (byte) 0xC3, (byte) 0x00, (byte) 0x0F, (byte) 0x1F, (byte) 0xD8, (byte) 0x1B, + (byte) 0x0F, (byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0x00, (byte) 0x00, + (byte) 0xA0, (byte) 0x24, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}; +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/MatchFilter.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/MatchFilter.java new file mode 100644 index 00000000000..8e73837a59c --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/MatchFilter.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.io.File; +import java.io.FilenameFilter; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author Ryan D. Brooks + */ +public class MatchFilter implements FilenameFilter { + protected Matcher matcher; + + public MatchFilter(String pattern) { + this.matcher = Pattern.compile(pattern).matcher(""); + } + + public boolean accept(File dir, String fileName) { + matcher.reset(fileName); + return matcher.matches(); + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/MinicomConnection.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/MinicomConnection.java new file mode 100644 index 00000000000..325b8ad86d2 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/MinicomConnection.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.io.IOException; +import java.io.PipedReader; +import java.io.PipedWriter; +import java.io.PrintWriter; +import org.eclipse.osee.framework.jdk.core.util.Lib; + +/** + * Specifically used for connecting to minicom via the serial port and setting up an input and output stream. + * + * @author Michael P. Masterson + */ +public class MinicomConnection { + private static final int MAX_RESPONSE_TIME = 100000; + private static final int ITERATION_TIME = 2000; + + private InputBufferThread inputBuffer; + private PrintWriter commandLine; + + /** + * saves input and output streams then waits for minicom to load completely + */ + public MinicomConnection() { + super(); + setupConnection(); + waitForWelcomeScreen(); + } + + public static void main(String[] args) { + for (int i = 0; i < 20; i++) { + System.out.println("i = " + i + ", Making Connection..."); + MinicomConnection connection = new MinicomConnection(); + System.out.println("Connection made"); + System.out.println("Restarting..."); + connection.resetPizzaBox(); + } + System.out.println("Done with main"); + + } + + /** + * Uses a process builder to set up the minicom process executable. Using this it will create a thread for inputting + * commands to minicom. + */ + private void setupConnection() { + try { + ProcessBuilder pb = new ProcessBuilder(); + + // the path to the minicom program through linux. + String[] minicomExe = new String[] {"/usr/bin/minicom"}; + + // sets up the operating system command + pb.command(minicomExe); + + // starts a new process based on the minicom command + Process minicomProc = pb.start(); + + // the following three writers and readers will be used to issue minicom commands and read its responses + PipedWriter pw = new PipedWriter(); + commandLine = new PrintWriter(pw); + PipedReader pr = new PipedReader(pw); + + // send the textual output of minicom to the trash + PrintWriter outputFromTheMinicom = new PrintWriter(System.out); + + // sets up the minicom thread and directs minicom output to the two streams passed + inputBuffer = (InputBufferThread) Lib.handleMinicomProcess(minicomProc, outputFromTheMinicom, pr)[1]; + } catch (IOException ex) { + ex.printStackTrace(); + } + + } + + /** + * @return The printWriter for issuing commands to minicom + */ + public PrintWriter getCommandLine() { + return this.commandLine; + } + + /** + * reads input from the minicom until it sees a common line singifying it has completely loaded + */ + private void waitForWelcomeScreen() { + waitFor("Press CTRL-A Z for help on special keys"); + } + + /** + * Waits to either read in the expected reset completion line OR for the run command to see the completion line + */ + public void waitForReset() { + waitFor("Decompression complete"); + } + + /** + * Waits for the parameter passed to appear in the minicom output. Uses the InputBufferThread that should have been + * started before this. + * + * @param matcher The string to look for in the minicom's output stream + */ + public synchronized void waitFor(String matcher) { + try { + int elapsedTime = 0; + while (elapsedTime <= MAX_RESPONSE_TIME) { + if (inputBuffer.contains(matcher) >= 0) break; + + System.out.println("Input buffer did not contain " + matcher + " after " + elapsedTime + " milisecs"); + this.wait(ITERATION_TIME); + elapsedTime += ITERATION_TIME; + } + if (elapsedTime > MAX_RESPONSE_TIME) { + throw new InterruptedException( + "Waiting for '" + matcher + "' took longer then " + MAX_RESPONSE_TIME + " miliseconds."); + } + wait(4000); + + } catch (InterruptedException ex) { + ex.printStackTrace(); + } + + } + + /** + * Stops the buffering thread from running and closes the commandLine + */ + public void disconnect() { + System.out.println("Disconnecting..."); + inputBuffer.stopOnNextRun(true); + commandLine.close(); + System.out.println("Disconnect Finished"); + } + + /** + * Runs through the commands given through minicom that will reset the pizzabox. Once the command/s are given, it + * waits for the reset to complete before exitting minicom. + */ + public void resetPizzaBox() { + System.out.println("Issuing rset Command"); + // Issues the reset command to the OFP + commandLine.println("rset"); + + System.out.println("Waiting for reset"); + waitForReset(); + System.out.println("Reset Finished"); + + System.out.println("Issuing CTRL-A Q command"); + // quits minicom + commandLine.println((char) 1 + "q"); + + System.out.println("hitting enter on 'you sure you want to quit'"); + // hit enter on the "Are you sure you want to quit?" popup + commandLine.println(); + + disconnect(); + System.out.println("Done with resetPizzaBox"); + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/MinicomOutputThread.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/MinicomOutputThread.java new file mode 100644 index 00000000000..487202bb8c8 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/MinicomOutputThread.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Writer; + +/** + * Thread specifically used for connecting to minicom via the serial port and setting up an input and output stream. + * + * @author Michael P. Masterson + */ +public class MinicomOutputThread extends Thread { + private Writer output; + private BufferedReader input; + private boolean resetFinished; + + /** + * saves input and output streams then waits for minicom to load completely + */ + public MinicomOutputThread(Writer output, BufferedReader input) { + super(); + this.output = output; + this.input = input; + waitForWelcomScreen(); + resetFinished = false; + } + + /** + * reads input from the minicom until it sees a common line singifying it has completely loaded + */ + private void waitForWelcomScreen() { + try { + String welcomeLine = "Press CTRL-A Z for help on special keys"; + String outLine = null; + while ((outLine = input.readLine()) != null) { + output.write("\nWELCOME: " + outLine); + if (outLine.contains(welcomeLine)) break; + + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + /** + * @return True if the text for the completion of a reset has been seen on the line + */ + public boolean isResetFinished() { + return this.resetFinished; + } + + /** + * Common run command for the thread. Sits on the serial line reading input from the minicom and printing it to the + * the output stream. If the expected end of a reset is found, it sets that field to indicate the reset is finished. + */ + public void run() { + String outLine = null; + try { + while ((outLine = input.readLine()) != null) { + if (!outLine.contains("[")) output.write(outLine + "\n"); + + if (outLine.contains("Start of wp_periodic_task")) { + output.write("Found end of reset\n"); + this.resetFinished = true; + } + + } + } catch (IOException ex) { + ex.printStackTrace(); + } finally { + try { + input.close(); + output.flush(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + + /** + * Waits to either read in the expected reset completion line OR for the run command to see the completion line + */ + public void waitForReset() { + try { + String outLine; + while ((outLine = input.readLine()) != null && !isResetFinished()) { + if (!outLine.contains("[")) output.write(outLine + "\n"); + + if (outLine.contains("Start of wp_periodic_task")) { + output.write("Found end of reset\n"); + break; + } + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/MultipleLinks.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/MultipleLinks.java new file mode 100644 index 00000000000..b23461f23bf --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/MultipleLinks.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.io.File; +import java.io.IOException; +import org.eclipse.osee.framework.jdk.core.util.Lib; + +/** + * @author Ryan D. Brooks + */ +public class MultipleLinks { + + public static void main(String[] args) throws IOException { + if (args.length < 3) { + System.out.println("Usage: java tc.MultipleLinks <file to link> <directory for links> <# of links>"); + return; + } + link(new File(args[0]), new File(args[1]), Integer.parseInt(args[2])); + } + + public static void link(File fileToLink, File directory, int linkCount) throws IOException { + if (!fileToLink.isFile()) { + throw new IllegalArgumentException(fileToLink + " is not a file."); + } + + fileToLink = fileToLink.getCanonicalFile(); + directory = directory.getCanonicalFile(); + if (directory.mkdir()) { + System.out.println("Created " + directory); + } + + //separate exstension and file name + String fileName = fileToLink.getName(); + String extension = ""; + int pos = fileName.lastIndexOf('.'); + if (pos != -1) { + extension = fileName.substring(pos); + } + fileName = Lib.removeExtension(fileToLink.getName()); + + String command = "ln -s " + fileToLink.getPath() + " " + directory.getPath() + File.separator + fileName; + for (int i = 0; i < linkCount; i++) { + Lib.handleProcess(Runtime.getRuntime().exec(command + i + extension)); + } + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/RenameFiles.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/RenameFiles.java new file mode 100644 index 00000000000..0e67bd2ac28 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/RenameFiles.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.regex.Pattern; +import org.eclipse.osee.framework.jdk.core.text.Rule; +import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet; +import org.eclipse.osee.framework.jdk.core.text.rules.ReplaceAll; +import org.eclipse.osee.framework.jdk.core.util.Lib; + +/** + * @author Ryan D. Brooks + */ +public class RenameFiles { + + public static void main(String[] args) throws IOException { + if (args.length < 3) { + System.out.println("Usage: java library.RenameFiles <directory> <full path pattern> <replacement>\n"); + return; + } + + Rule rule = new ReplaceAll(Pattern.compile(args[1]), args[2]); + List<File> files = Lib.recursivelyListFiles(new File(args[0]).getCanonicalFile(), null); + int size = files.size(); + int renamedFileCount = 0; + + for (int i = 0; i < size; i++) { + File file = (File) files.get(i); + ChangeSet newName = rule.computeChanges(file.getPath()); + if (rule.ruleWasApplicable()) { + File newFile = new File(newName.toString()); + if (file.renameTo(newFile)) { + System.out.println(file.getPath() + " became " + newFile.getPath()); + renamedFileCount++; + } else { + System.out.println(file.getPath() + " failed to become " + newFile.getPath()); + } + } + } + System.out.println("Changed " + renamedFileCount + " files"); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/Streams.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/Streams.java new file mode 100644 index 00000000000..b36d98fce16 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/Streams.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.util.LinkedList; + +/** + * Utility class for working with Streams. + * + * @author Jeff C. Phillips + */ +public class Streams { + + private final static int ORACLE_BUFF_LENGTH = 4 * 8192; + + /** + * Converts a String into a InputStream using specifiec charSet + * + * @param string + * @param charSet + * @return Return input stream reference + * @throws UnsupportedEncodingException + */ + public static InputStream convertStringToInputStream(String string, String charSet) throws UnsupportedEncodingException { + return new ByteArrayInputStream(string.getBytes(charSet)); + } + + public static byte[] getByteArray(InputStream stream) { + + if (stream == null) throw new IllegalStateException("stream can not be null"); + + int length = -1; + long read = 0; + byte[] data = new byte[ORACLE_BUFF_LENGTH]; + LinkedList<byte[]> linkedByteArrays = new LinkedList<byte[]>(); + + try { + while ((length = stream.read(data)) != -1) { + linkedByteArrays.add(data); + read += length; + + // Get another buffer for the next go around + data = new byte[ORACLE_BUFF_LENGTH]; + + if (read > Integer.MAX_VALUE) throw new UnsupportedOperationException("The data is too large."); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + + // Get a contiguous buffer for all of the pieces to go into + data = new byte[(int) read]; + int writeSize; + int index = 0; + + for (byte[] chunk : linkedByteArrays) { + writeSize = Math.min((int) read, ORACLE_BUFF_LENGTH); + System.arraycopy(chunk, 0, data, index, writeSize); + + read -= writeSize; + index += writeSize; + } + return data; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/Zip.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/Zip.java new file mode 100644 index 00000000000..49d5da31161 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/Zip.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import java.util.zip.ZipOutputStream; + +public class Zip { + + public static void zip(String[] filenames, String outFilename) { + // These are the files to include in the ZIP file + // String[] filenames = new String[]{"filename1", "filename2"}; + + // Create a buffer for reading the files + byte[] buf = new byte[1024]; + + try { + // Create the ZIP file + ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename)); + + // Compress the files + for (int i = 0; i < filenames.length; i++) { + FileInputStream in = new FileInputStream(filenames[i]); + + // Add ZIP entry to output stream. + out.putNextEntry(new ZipEntry(filenames[i])); + + // Transfer bytes from the file to the ZIP file + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + + // Complete the entry + out.closeEntry(); + in.close(); + } + + // Complete the ZIP file + out.close(); + } catch (IOException e) { + } + + } + + public static void unzip(File zipFile, File destinationDir, IZipEntryCompleteCallback progressBar) throws IOException { + int BUFFER = 2048; + BufferedOutputStream dest = null; + BufferedInputStream is = null; + ZipEntry entry = null; + + try { + ZipFile zipfile = new ZipFile(zipFile.getAbsolutePath()); + progressBar.setValue(0); + progressBar.setMinimum(0); + progressBar.setMaximum(zipfile.size()); + System.out.println(zipfile.size()); + Enumeration<? extends ZipEntry> e = zipfile.entries(); + int size = 0; + while (e.hasMoreElements()) { + entry = (ZipEntry) e.nextElement(); + is = new BufferedInputStream(zipfile.getInputStream(entry)); + int count; + byte data[] = new byte[BUFFER]; + File fileDir = new File(destinationDir.getAbsolutePath() + File.separator + entry.getName()); + if (entry.isDirectory()) { + fileDir.mkdirs(); + progressBar.setValue(++size); + continue; + } else { + fileDir.getParentFile().mkdirs(); + } + + if (!fileDir.exists() || (fileDir.exists() && fileDir.canWrite())) { + FileOutputStream fos = new FileOutputStream(fileDir.getAbsolutePath()); + dest = new BufferedOutputStream(fos, BUFFER); + while ((count = is.read(data, 0, BUFFER)) != -1) { + dest.write(data, 0, count); + } + dest.flush(); + dest.close(); + } + + is.close(); + + if (fileDir.getAbsolutePath().endsWith(".lnk")) { + if (fileDir.canWrite()) { + fileDir.setReadOnly(); + } + } + progressBar.setValue(++size); + } + } catch (Exception ex) { + String information = + "ZipFile: " + (zipFile != null ? zipFile.getAbsolutePath() : "NULL") + "\n" + "DestinationDir: " + (destinationDir != null ? destinationDir.getAbsolutePath() : "NULL") + "\n" + "Entry Processed: " + (entry != null ? entry.toString() : "NULL") + "\n"; + throw new IOException(information + ex.getMessage()); + } + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/streams/StreamCatcher.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/streams/StreamCatcher.java new file mode 100644 index 00000000000..c2e2b2efed7 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/streams/StreamCatcher.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io.streams; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * @author Jeff C. Phillips + */ +public class StreamCatcher extends Thread { + private InputStream is; + private String type; + private Logger logger; + + public StreamCatcher(InputStream is, String type) { + this(is, type, null); + } + + public StreamCatcher(InputStream is, String type, Logger logger) { + this.is = is; + this.type = type; + this.logger = logger; + } + + public void run() { + try { + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + String line = null; + String loggerError = ""; + + while ((line = br.readLine()) != null) { + + if (logger == null) + System.out.println(type + ">" + line); + else + loggerError += line + "\n"; + + } + + if (logger != null && loggerError.length() > 0) logger.log(Level.SEVERE, loggerError); + + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/AbstractSaxHandler.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/AbstractSaxHandler.java new file mode 100644 index 00000000000..b7c51447e66 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/AbstractSaxHandler.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io.xml; + +import java.io.IOException; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.ext.LexicalHandler; +import org.xml.sax.helpers.DefaultHandler; + +/** + * @author Ryan D. Brooks + * + * If you want to preserve CDATA sections you need to follow this pattern: + * + * XMLReader xmlReader = XMLReaderFactory.createXMLReader(); + * xmlReader.setContentHandler(this); + * xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", this); //This is the important part + * + */ +public abstract class AbstractSaxHandler extends DefaultHandler implements LexicalHandler{ +// Buffer for collecting data from the "characters" SAX event. + private StringBuilder contents; + private final int maxContentLength; + + protected AbstractSaxHandler() { + this(0); + } + + protected AbstractSaxHandler(int maxContentLength) { + this.contents = new StringBuilder(2000); + this.maxContentLength = maxContentLength; + } + + /* (non-Javadoc) + * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int) + */ + @Override + public void characters(char[] ch, int start, int length) throws SAXException { + if (maxContentLength > 0 && contents.length() + length > maxContentLength) { + return; // don't add more characters if doing so will make the content too long + } + contents.append(ch, start, length); + } + + /* (non-Javadoc) + * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + endElementFound(uri, localName, qName); + contents.setLength(0); // efficiently reset the StringBuilder to be empty (but preserve its capacity) + } + + /* (non-Javadoc) + * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) + */ + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + startElementFound(uri, localName, qName, attributes); + contents.setLength(0); // efficiently reset the StringBuilder to be empty (but preserve its capacity) + } + + public abstract void startElementFound(String uri, String localName, String qName, Attributes attributes) throws SAXException; + + public abstract void endElementFound(String uri, String localName, String qName) throws SAXException; + + public String getContents() { + return contents.toString(); + } + + public void addContentsTo(Appendable appendable) throws IOException { + appendable.append(contents); + } + + /* (non-Javadoc) + * @see org.xml.sax.ext.LexicalHandler#comment(char[], int, int) + */ + public void comment(char[] ch, int start, int length) throws SAXException { + } + + /* (non-Javadoc) + * @see org.xml.sax.ext.LexicalHandler#endCDATA() + */ + public void endCDATA() throws SAXException { + contents.append("]]>"); + } + + /* (non-Javadoc) + * @see org.xml.sax.ext.LexicalHandler#endDTD() + */ + public void endDTD() throws SAXException { + } + + /* (non-Javadoc) + * @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String) + */ + public void endEntity(String name) throws SAXException { + } + + /* (non-Javadoc) + * @see org.xml.sax.ext.LexicalHandler#startCDATA() + */ + public void startCDATA() throws SAXException { + contents.append("<![CDATA["); + } + + /* (non-Javadoc) + * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String) + */ + public void startDTD(String name, String publicId, String systemId) + throws SAXException { + } + + /* (non-Javadoc) + * @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String) + */ + public void startEntity(String name) throws SAXException { + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/AbstractSheetWriter.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/AbstractSheetWriter.java new file mode 100644 index 00000000000..36a6a959129 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/AbstractSheetWriter.java @@ -0,0 +1,84 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.osee.framework.jdk.core.util.io.xml;
+
+import java.io.IOException;
+import java.util.Collection;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public abstract class AbstractSheetWriter implements ISheetWriter {
+ private boolean startRow;
+ private int defaultCellIndex;
+
+ public AbstractSheetWriter() {
+ startRow = true;
+ defaultCellIndex = 0;
+ }
+
+ /**
+ * must be called by subclasses in their implementations of writeCell(String data, int cellIndex)
+ *
+ * @throws IOException
+ */
+ protected void startRowIfNecessary() throws IOException {
+ if (startRow) {
+ startRow();
+ startRow = false;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.jdk.core.util.io.xml.excel.ISheetWriter#writeRow(java.util.Collection)
+ */
+ public void writeRow(Collection<String> row) throws IOException {
+ writeRow(row.toArray(new String[row.size()]));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.jdk.core.util.io.xml.excel.ISheetWriter#writeRow(java.lang.String)
+ */
+ public void writeRow(String... row) throws IOException {
+ for (int i = 0; i < row.length; i++) {
+ writeCell(row[i], i);
+ }
+
+ endRow();
+ }
+
+ public void writeCell(String data, int cellIndex) throws IOException {
+ startRowIfNecessary();
+ defaultCellIndex = cellIndex + 1;
+ writeCellText(data, cellIndex);
+ }
+
+ public void endRow() throws IOException {
+ startRowIfNecessary();
+ startRow = true;
+ defaultCellIndex = 0;
+ writeEndRow();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.jdk.core.util.io.xml.ISheetWriter#writeCell(java.lang.String)
+ */
+ public void writeCell(String cellData) throws IOException {
+ writeCell(cellData, defaultCellIndex);
+ }
+
+ protected abstract void startRow() throws IOException;
+
+ protected abstract void writeEndRow() throws IOException;
+
+ protected abstract void writeCellText(String data, int cellIndex) throws IOException;
+}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/ExcelSaxHandler.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/ExcelSaxHandler.java new file mode 100644 index 00000000000..263b6e9c785 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/ExcelSaxHandler.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io.xml; + +import java.util.Arrays; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * @author Ryan D. Brooks + */ +public class ExcelSaxHandler extends AbstractSaxHandler { + private String[] row; + private int cellIndex; + private int rowIndex; + private final RowProcessor rowProcessor; + private boolean isRowHeader; + private final boolean firstRowIsHeader; + private final boolean multiTable; + private boolean rowEmpty; + + public ExcelSaxHandler(RowProcessor rowProcessor, boolean firstRowIsHeader, boolean enableMultiTableSupport) { + super(); + this.rowProcessor = rowProcessor; + this.firstRowIsHeader = firstRowIsHeader; + this.multiTable = enableMultiTableSupport; + rowIndex = 0; + } + + public ExcelSaxHandler(RowProcessor rowProcessor, boolean hasHeaderRow) { + this(rowProcessor, hasHeaderRow, false); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.osee.framework.jdk.core.util.io.xml.AbstractSaxHandler#startElementFound(java.lang.String, + * java.lang.String, java.lang.String, org.xml.sax.Attributes) + */ + @Override + public void startElementFound(String uri, String localName, String qName, Attributes attributes) throws SAXException { + if (localName.equalsIgnoreCase("Row")) { + cellIndex = -1; // so that upon finding the first cell start element the index becomes 0 + rowEmpty = true; + // null out because any empty cells would otherwise contain data from the previous row + Arrays.fill(row, 0, row.length, null); + + String indexStr = attributes.getValue("ss:Index"); + if (indexStr != null) { + int oldRowIndex = rowIndex; + rowIndex = Integer.parseInt(indexStr) - 1; // translate from Excel's 1-based index to + // our 0-based index + for (int i = oldRowIndex; i < rowIndex; i++) { + rowProcessor.processEmptyRow(); + } + } else { + rowIndex++; + } + } else if (localName.equalsIgnoreCase("Cell")) { + String indexStr = attributes.getValue("ss:Index"); + if (indexStr != null) { + cellIndex = Integer.parseInt(indexStr) - 1; // translate from Excel's 1-based index to + // our 0-based index + } else { + cellIndex++; + } + } else if (localName.equalsIgnoreCase("Table")) { + String columnCountStr = attributes.getValue("ss:ExpandedColumnCount"); + if (columnCountStr == null) { + throw new IllegalArgumentException("missing ss:ExpandedColumnCount attribute of Table element"); + } + row = new String[Integer.parseInt(columnCountStr)]; + + String rowCountStr = attributes.getValue("ss:ExpandedRowCount"); + if (rowCountStr == null) { + rowCountStr = "0"; + } + rowProcessor.detectedRowAndColumnCounts(Integer.parseInt(rowCountStr), row.length); + } else if (localName.equalsIgnoreCase("Worksheet")) { + isRowHeader = firstRowIsHeader; // next non-empty row will be considered a header (if + // applicable) + rowProcessor.foundStartOfWorksheet(attributes.getValue("ss:Name")); + // System.out.println("Worksheet =" +attributes.getValue("ss:Name")); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.osee.framework.jdk.core.util.io.xml.AbstractSaxHandler#endElementWithClearContents(java.lang.String, + * java.lang.String, java.lang.String) + */ + @Override + public void endElementFound(String uri, String localName, String qName) throws SAXException { + if (localName.equalsIgnoreCase("Data")) { + String contentStr = getContents(); + if (!contentStr.equals(ExcelXmlWriter.blobMessage)) { + if (contentStr.equals(ExcelXmlWriter.defaultEmptyString)) { + row[cellIndex] = ""; + } else { + row[cellIndex] = contentStr; + } + } + rowEmpty = false; + } else if (localName.equalsIgnoreCase("Row")) { + if (rowEmpty) { + rowProcessor.processEmptyRow(); + if (multiTable) { + isRowHeader = true; // next non-empty row will be considered a header + } + } else if (row[0] != null && row[0].startsWith("#")) { + rowProcessor.processCommentRow(row); + } else if (isRowHeader) { + isRowHeader = false; + rowProcessor.processHeaderRow(row); + } else { + rowProcessor.processRow(row); + } + } else if (localName.equalsIgnoreCase("Worksheet")) { + rowProcessor.reachedEndOfWorksheet(); + } else if (localName.equalsIgnoreCase("EmbeddedClob")) { + row[cellIndex] = getContents(); + } + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/ExcelXmlWriter.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/ExcelXmlWriter.java new file mode 100644 index 00000000000..30a6b9f87ba --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/ExcelXmlWriter.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io.xml; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import org.eclipse.osee.framework.jdk.core.util.xml.Xml; + +/** + * @author Ryan D. Brooks + */ +public class ExcelXmlWriter extends AbstractSheetWriter { + private BufferedWriter out; + private boolean inSheet; + private boolean startTable; + private int columnCount; + private String emptyStringRepresentation; + private int previuosCellIndex; + + public static final String defaultEmptyStringXmlRep = "ø"; + public static final String defaultEmptyString = "\u00F8"; + public static final String blobMessage = "data stored in EmbeddedClob since longer than 32767 chars"; + + public ExcelXmlWriter(Writer writer) throws IOException { + super(); + out = new BufferedWriter(writer); + emptyStringRepresentation = defaultEmptyStringXmlRep; + + out.write("<?xml version=\"1.0\"?>\n"); + out.write("<?mso-application progid=\"Excel.Sheet\"?>\n"); + out.write("<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\n"); + out.write(" xmlns:o=\"urn:schemas-microsoft-com:office:office\"\n"); + out.write(" xmlns:x=\"urn:schemas-microsoft-com:office:excel\"\n"); + out.write(" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\"\n"); + out.write(" xmlns:html=\"http://www.w3.org/TR/REC-html40\">\n"); + } + + public ExcelXmlWriter(File file) throws IOException { + this(new FileWriter(file)); + } + + public void startSheet(String worksheetName, int columnCount) throws IOException { + this.columnCount = columnCount; + if (worksheetName.length() > 31) { + worksheetName = worksheetName.substring(0, 31); + } + out.write(String.format(" <Worksheet ss:Name=\"%s\">\n", worksheetName)); + + inSheet = true; + startTable = true; + } + + /* (non-Javadoc) + * @see org.eclipse.osee.framework.jdk.core.util.io.xml.excel.ISheetWriter#endSheet() + */ + public void endSheet() throws IOException { + startTableIfNecessary(); + + out.write(" </Table>\n"); + out.write(" </Worksheet>\n"); + inSheet = false; + startTable = false; + } + + public void endWorkbook() throws IOException { + if (inSheet) { + endSheet(); + } + out.write("</Workbook>\n"); + out.close(); + } + + protected void startRow() throws IOException { + startTableIfNecessary(); + + out.write(" <Row>\n"); + previuosCellIndex = -1; + } + + @Override + public void writeEndRow() throws IOException { + out.write(" </Row>\n"); + } + + private void startTableIfNecessary() throws IOException { + if (startTable) { + out.write(" <Table x:FullColumns=\"1\" x:FullRows=\"1\" ss:ExpandedColumnCount=\"" + columnCount + "\">\n"); + startTable = false; + } + } + + @Override + public void writeCellText(String cellData, int cellIndex) throws IOException { + if (cellData == null) { + previuosCellIndex = -1; // the next cell will need to use an explicit index + } else { + out.write(" <Cell"); + if (previuosCellIndex + 1 != cellIndex) { // use explicit index if at least one cell was skipped + out.write(" ss:Index=\"" + (cellIndex + 1) + "\""); + } + previuosCellIndex = cellIndex; + if (!cellData.equals("") && cellData.charAt(0) == '=') { + out.write(" ss:Formula=\"" + cellData + "\">"); + } else { + out.write("><Data ss:Type=\"String\">"); + if (cellData.equals("")) { + out.write(emptyStringRepresentation); + } else { + if (cellData.length() > 32767) { + out.write(blobMessage); + } else { + Xml.writeAsCdata(out, cellData); + } + } + out.write("</Data>"); + if (cellData.length() > 32767) { + out.write("<EmbeddedClob>"); + Xml.writeAsCdata(out, cellData); + out.write("</EmbeddedClob>"); + } + } + out.write("</Cell>\n"); + } + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/ISheetWriter.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/ISheetWriter.java new file mode 100644 index 00000000000..a03c75d020d --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/ISheetWriter.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io.xml; + +import java.io.IOException; +import java.util.Collection; + +/** + * @author Robert A. Fisher + * @author Ryan D. Brooks + */ +public interface ISheetWriter { + + public void startSheet(String worksheetName, int columnCount) throws IOException; + + public void endSheet() throws IOException; + + public void writeRow(String... row) throws IOException; + + public void writeRow(Collection<String> row) throws IOException; + + public void writeCell(String cellData) throws IOException; + + /** + * @param cellData text value of cell + * @param cellIndex zero-based index + * @throws IOException + */ + public void writeCell(String cellData, int cellIndex) throws IOException; + + public void endRow() throws IOException; + + public void endWorkbook() throws IOException; + +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/RowProcessor.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/RowProcessor.java new file mode 100644 index 00000000000..fd8553fc073 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/RowProcessor.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io.xml; + +/** + * @author Ryan D. Brooks + */ +public interface RowProcessor { + public abstract void processRow(String[] row); + + public abstract void processHeaderRow(String[] row); + + public abstract void processEmptyRow(); + + public abstract void processCommentRow(String[] row); + + public abstract void reachedEndOfWorksheet(); + + public abstract void foundStartOfWorksheet(String sheetName); + + public abstract void detectedRowAndColumnCounts(int rowCount, int columnCount); +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/WordMlTableWriter.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/WordMlTableWriter.java new file mode 100644 index 00000000000..ac182c4ec0a --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/WordMlTableWriter.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io.xml; + +import java.io.IOException; +import java.nio.charset.CharacterCodingException; + +/** + * @author Jeff C. Phillips + */ +public class WordMlTableWriter extends AbstractSheetWriter { + private static final String TABLE_START = + "<w:tbl><w:tblPr><w:tblBorders><w:top w:val=\"single\" w:sz=\"1\" /><w:left w:val=\"single\" w:sz=\"1\" /><w:bottom w:val=\"single\" w:sz=\"1\" /><w:right w:val=\"single\" w:sz=\"1\" /><w:insideH w:val=\"single\" w:sz=\"1\" /><w:insideV w:val=\"single\" w:sz=\"1\" /></w:tblBorders></w:tblPr>"; + private static final String TABLE_END = "</w:tbl>"; + private static final String START_TABLE_GRID = "<w:tblGrid>"; + private static final String END_TABLE_GRID = "</w:tblGrid>"; + private static final String TABLE_GRID = "<w:gridCol w:w=\"1024\" />"; + private static final String CELL_STRART = "<w:tc><w:tcPr><w:tcW w:w=\"1024\" /></w:tcPr><w:p><w:r><w:t>"; + private static final String CELL_END = "</w:t></w:r></w:p></w:tc>"; + private static final String ROW_START = "<w:tr>"; + private static final String ROW_END = "</w:tr>"; + private final Appendable str; + private int columnSize; + private boolean startTable; + + public WordMlTableWriter(Appendable str) throws CharacterCodingException { + this.str = str; + } + + public void startSheet(String worksheetName, int columnCount) throws IOException { + str.append(TABLE_START); + columnSize = columnCount; + startTable = true; + } + + public void endSheet() throws IOException { + str.append(TABLE_END); + } + + /* (non-Javadoc) + * @see org.eclipse.osee.framework.jdk.core.util.io.xml.AbstractSheetWriter#startRow() + */ + @Override + protected void startRow() throws IOException { + // column size is set when the first row is created. + if (startTable) { + writeTableGridData(); + } + + str.append(ROW_START); + } + + @Override + public void writeEndRow() throws IOException { + str.append(ROW_END); + } + + private void writeTableGridData() throws IOException { + str.append(START_TABLE_GRID); + + for (int i = 0; i < columnSize; i++) { + str.append(TABLE_GRID); + } + str.append(END_TABLE_GRID); + } + + @Override + public void writeCellText(String cellData, int cellIndex) throws IOException { + str.append(CELL_STRART); + if (cellData != null) { + str.append(cellData); + } + str.append(CELL_END); + } + + public void endWorkbook() throws IOException { + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/WordSaxHandler.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/WordSaxHandler.java new file mode 100644 index 00000000000..18a0f116a10 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/WordSaxHandler.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io.xml; + +import java.io.IOException; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * @author Ryan D. Brooks + */ +public class WordSaxHandler extends AbstractSaxHandler { + private boolean inHeader; + private boolean inFooter; + private StringBuilder headerText; + private StringBuilder footerText; + + public WordSaxHandler() { + super(); + headerText = new StringBuilder(); + footerText = new StringBuilder(); + } + + public void reset() { + headerText.delete(0, 99999999); + footerText.delete(0, 99999999); + } + + /* (non-Javadoc) + * @see org.eclipse.osee.framework.jdk.core.util.io.xml.AbstractSaxHandler#startElementFound(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) + */ + @Override + public void startElementFound(String uri, String localName, String qName, Attributes attributes) throws SAXException { + if (localName.equalsIgnoreCase("hdr")) { + inHeader = true; + } else if (localName.equalsIgnoreCase("ftr")) { + inFooter = true; + } else if (localName.equalsIgnoreCase("Table")) { + + } else if (localName.equalsIgnoreCase("Worksheet")) { + + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.osee.framework.jdk.core.util.io.xml.AbstractSaxHandler#endElementWithClearContents(java.lang.String, + * java.lang.String, java.lang.String) + */ + @Override + public void endElementFound(String uri, String localName, String qName) throws SAXException { + try { + if (localName.equalsIgnoreCase("t")) { + if (inHeader) { + addContentsTo(headerText); + } else if (inFooter) { + addContentsTo(footerText); + } + } else if (localName.equalsIgnoreCase("hdr")) { + inHeader = false; + } else if (localName.equalsIgnoreCase("ftr")) { + inFooter = false; + } + } catch (IOException ex) { + throw new SAXException(ex); + } + } + + public String getHeaderText() { + return headerText.toString(); + } + + public String getFooterText() { + return footerText.toString(); + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/XmlStraightener.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/XmlStraightener.java new file mode 100644 index 00000000000..ae870a16540 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/io/xml/XmlStraightener.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.io.xml; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.osee.framework.jdk.core.text.Rule; +import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet; +import org.eclipse.osee.framework.jdk.core.util.Lib; + +/** + * @author Ryan D. Brooks + */ +public class XmlStraightener extends Rule { + private static final Pattern tagPattern = Pattern.compile("<[^!][^>]*>"); + + /** + * @param outExtension + */ + public XmlStraightener(String outExtension) { + super(outExtension); + } + + /* (non-Javadoc) + * @see org.eclipse.osee.framework.jdk.core.text.Rule#computeChanges(java.lang.CharSequence) + */ + @Override + public ChangeSet computeChanges(CharSequence seq) { + ChangeSet changeSet = new ChangeSet(seq); + + Matcher tagMatcher = tagPattern.matcher(seq); + while (tagMatcher.find()) { + changeSet.insertBefore(tagMatcher.end(), Lib.lineSeparator); + ruleWasApplicable = true; + } + + return changeSet; + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/network/PortUtil.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/network/PortUtil.java new file mode 100644 index 00000000000..edbf0ce7ef3 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/network/PortUtil.java @@ -0,0 +1,136 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.osee.framework.jdk.core.util.network;
+
+import java.io.IOException;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import org.eclipse.osee.framework.jdk.core.util.OseeProperties;
+
+/**
+ * @author Andrew M. Finkbeiner
+ */
+public class PortUtil {
+
+ private static PortUtil singleton;
+ @SuppressWarnings("unused")
+ private ServerSocket ss;
+
+ public static PortUtil getInstance() {
+ if (singleton == null) {
+ singleton = new PortUtil();
+ }
+ return singleton;
+ }
+
+ int basePort = 18000;
+ int nextPort = 18000;
+
+ private PortUtil() {
+ basePort = nextPort = OseeProperties.getOseePortScannerStartPort();
+ for (int j = nextPort; j < 64000; j += 250) {
+ if (checkIfPortIsTaken(j)) {
+ basePort = nextPort = j;
+ try {
+ ss = new ServerSocket(basePort);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ break;
+ }
+ }
+ }
+
+ public void computeNewBasePort() {
+ basePort = nextPort = basePort + 1000;
+ for (int j = nextPort; j < 64000; j += 250) {
+ if (checkIfPortIsTaken(j)) {
+ basePort = nextPort = j;
+ try {
+ ss = new ServerSocket(basePort);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ break;
+ }
+ }
+ }
+
+ public int getValidPort() throws IOException {
+ int port = getConsecutiveValidPorts(1);
+ return port;
+ }
+
+ public int getConsecutiveValidPorts(int numberOfPorts) throws IOException {
+ try {
+ int returnVal = getConsecutiveLocalPorts(numberOfPorts);
+ nextPort = returnVal + numberOfPorts;
+ return returnVal;
+ } catch (Exception e) {
+ e.printStackTrace();
+ IOException ioE = new IOException("Unable to get a valid port.");
+ ioE.initCause(e);
+ throw ioE;
+ }
+ }
+
+ /**
+ * @param numberOfPorts The number of consecutive available ports to find
+ * @return The port of first number in the sequence of valid ports
+ * @throws Exception
+ */
+ private int getConsecutiveLocalPorts(int numberOfPorts) throws Exception {
+ if (nextPort >= basePort + 250 - numberOfPorts) {
+ nextPort = basePort;
+ }
+ for (int i = nextPort, count = 1; i < basePort + 250; i++, count++) {
+ boolean passed = true;
+ for (int j = i; j < numberOfPorts + i; j++) {
+ if (!checkIfPortIsTaken(j)) {
+ passed = false;
+ break;
+ }
+ }
+ if (passed) {
+ return i;
+ }
+ }
+ throw new Exception("Unable to find valid port.");
+ }
+
+ private boolean checkIfPortIsTaken(int port) {
+ return checkTcpIp(port) && checkUdpPort(port);
+ }
+
+ private boolean checkTcpIp(int port) {
+ try {
+ ServerSocket socket;
+ socket = new ServerSocket(port);
+ socket.close();
+ } catch (Exception e) {
+ return false;
+ }
+ return true;
+ }
+
+ private boolean checkUdpPort(int port) {
+ try {
+ DatagramSocket ds = new DatagramSocket(port, InetAddress.getLocalHost());
+ ds.close();
+ ds.disconnect();
+ } catch (Exception e) {
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/requirement/RequirementId.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/requirement/RequirementId.java new file mode 100644 index 00000000000..585c385c79a --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/requirement/RequirementId.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.requirement; + +import java.util.Vector; +import org.eclipse.osee.framework.jdk.core.persistence.Xmlizable; +import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * @author Ryan D. Brooks + * @author Robert A. Fisher + */ +public class RequirementId implements Xmlizable { + // TODO add requirement data + private String description; + private Vector<String> partialDescriptions; + private int timesVerified; + private boolean isPartial, isWhole, conflictExists; + + /** + * + */ + public RequirementId() { + this(""); + this.timesVerified = 0; + this.isPartial = false; + this.isWhole = false; + this.conflictExists = false; + } + + public RequirementId(String description) { + super(); + this.description = description; + } + + public String toString() { + return description; + } + + public Element toXml(Document doc) { + return Jaxp.createElement(doc, "RequirementId", description); + } + + public boolean conflictPresent() { + return conflictExists; + } + + /** + * Increments the count for how many times this requirement has been verified (which should only be once). If this + * requirement has already been marked as being previously verified (either partially or wholly) than a conflict flag + * will be set since a requirement can only be wholly verified once. + */ + public void verifiedHere() { + + // TODO add ability to store in what script this requirement is verified. + + if (isPartial || isWhole) { + conflictExists = true; + } else { + isWhole = true; + timesVerified++; + } + + } + + /** + * Adds a new description to the partial requirement description vector and increments the count for how many times + * this requirement has been verified. If this requirement has already been marked as being wholly verified than a + * conflict flag will be set since a partial verify is not needed. + * + * @param partialDesc - Helpful and concise description of what part of the requirement is being verified. + */ + public void partiallyVerifiedHere(String partialDesc) { + + // TODO add ability to store in what script or function this requirement is partially verified. + + if (isWhole) { + conflictExists = true; + } else { + if (!isPartial) { + isPartial = true; + } + + partialDescriptions.add(partialDesc); + timesVerified++; + } + + } + + public void usedHere() { + + // TODO add ability to store in what script or function this requirement is used. + + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/time/GlobalTime.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/time/GlobalTime.java new file mode 100644 index 00000000000..d34556959ad --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/time/GlobalTime.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.time; + +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.TimeZone; + +/** + * @author Jeff C. Phillips + */ +public class GlobalTime { + + public static Timestamp GreenwichMeanTimestamp() { + return new Timestamp(GreenwichMeanTimeMillis()); + } + + public static long GreenwichMeanTimeMillis() { + return Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTimeInMillis(); + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/windows/OutlookCalendarEvent.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/windows/OutlookCalendarEvent.java new file mode 100644 index 00000000000..82c229f01f7 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/windows/OutlookCalendarEvent.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.windows; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class OutlookCalendarEvent { + + private final String location; + private final String event; + private final Date date; + private final DateFormat myDateFormat; + private final String startTime; + private final String endTime; + + /** + * @param location - String the event location + * @param event - String the scheduled event + * @param date + * @param startTime - 0800 - 8am + * @param endTime - 1300 - 1pm + */ + public OutlookCalendarEvent(String location, String event, Date date, String startTime, String endTime) { + super(); + this.location = location; + this.event = event; + this.date = date; + this.startTime = startTime; + this.endTime = endTime; + myDateFormat = new SimpleDateFormat("yyyyMMdd"); + } + + public String getEvent() { + return "\nBEGIN:VCALENDAR\n" + + // + "PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN\n" + + // + "VERSION:1.0\n" + + // + "BEGIN:VEVENT\n" + + // + "DTSTART:" + myDateFormat.format(date) + "T" + startTime + "00\n" + + // + "DTEND:" + myDateFormat.format(date) + "T" + endTime + "00\n" + + // + "LOCATION;ENCODING=QUOTED-PRINTABLE:" + location + "\n" + + // + "TRANSP:1\n" + + // + "DESCRIPTION;ENCODING=QUOTED-PRINTABLE:=0D=0A\n" + + // + "SUMMARY;ENCODING=QUOTED-PRINTABLE:Event:" + event + "\n" + + // + "PRIORITY:3\n" + + // + "END:VEVENT\n" + + // + "END:VCALENDAR\n"; + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/windows/Registry.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/windows/Registry.java new file mode 100644 index 00000000000..9b953d46e81 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/windows/Registry.java @@ -0,0 +1,214 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.windows; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.osee.framework.jdk.core.util.Lib; + +public class Registry { + + public static final String HKEY_LOCAL_MACHINE = "HKLM"; + public static final String HKEY_CURRENT_USER = "HKCU"; + public static final String REG_SZ = "REG_SZ"; + public static final String REG_HELP_CMD = "reg /?"; + + public abstract interface RegVersion { + abstract public String getQueryCmd(String root, String path, String key); + + abstract public String getQueryPattern(String key); + + abstract public String getUpdateCommand(String root, String path, String key, String value, String[] regArray); + + abstract public String isVersion(); + } + + public class RegVersion_1_00 implements RegVersion { + public String getQueryCmd(String root, String path, String key) { + return "reg query " + root + "\\" + path + "\\" + key; + } + + public String getQueryPattern(String key) { + return "out:\\s*(\\w*)\\s*" + key + "\\s*(.*)"; + } + + public String getUpdateCommand(String root, String path, String key, String value, String[] regArray) { + String cmd = ""; + if (regArray != null) { + value = value + File.pathSeparator + regArray[1]; + System.out.println("THE VALUE IS: " + value); + cmd = "reg update \"" + root + "\\" + path + "\\" + key + "=" + value + "\""; + } else { + cmd = "reg add \"" + root + "\\" + path + "\\" + key + "=" + value + "\""; + } + + System.out.println("THE CMD IS: " + cmd); + + return cmd; + } + + public String isVersion() { + return "1.00"; + } + } + + public class RegVersion_3_0 implements RegVersion { + + public String getQueryCmd(String root, String path, String key) { + return "reg query " + root + "\\" + path + " /v " + key; + } + + public String getQueryPattern(String key) { + return ".*?" + key + "\\s*(\\w*)\\s*(\\S*).*"; + } + + public String getUpdateCommand(String root, String path, String key, String value, String[] regArray) { + String type = Registry.REG_SZ; + if (regArray != null) { + value = value + File.pathSeparator + regArray[1]; + type = regArray[0]; + } + return "reg add " + root + "\\" + path + " /v " + key + " /t " + type + " /f /d \"" + value + "\""; + } + + public String isVersion() { + return "3.0"; + } + } + + public static boolean isRegVersion(double lowerBound, double upperBound) throws IOException { + boolean matched = false; + Process p = Runtime.getRuntime().exec(Registry.REG_HELP_CMD); + StringWriter stringWriter = new StringWriter(); + Lib.handleProcess(p, stringWriter); + + Pattern pattern = Pattern.compile(".*version\\s(\\d*\\.\\d+).*", Pattern.DOTALL); + Matcher matcher = pattern.matcher(stringWriter.toString()); + + System.out.println(matcher.groupCount()); + if (matcher.matches()) { + String regVersion = matcher.group(1).trim(); + System.out.println("Found Version: " + regVersion); + + double foundVersion = Double.parseDouble(regVersion); + if ((foundVersion >= lowerBound) && (foundVersion <= upperBound)) { + matched = true; + } + } + return matched; + } + + public static RegVersion getVersion() throws IOException { + Registry r = new Registry(); + RegVersion regVersion = null; + if (Registry.isRegVersion(1.00, 1.99)) { + regVersion = r.new RegVersion_1_00(); + } else { + regVersion = r.new RegVersion_3_0(); + } + return regVersion; + } + + public static String[] getValue(RegVersion version, String root, String path, String key) throws IOException { + String toReturn[] = null; + + Process p = Runtime.getRuntime().exec(version.getQueryCmd(root, path, key)); + StringWriter stringWriter = new StringWriter(); + Lib.handleProcess(p, stringWriter); + + Pattern pattern = Pattern.compile(version.getQueryPattern(key), Pattern.DOTALL); + Matcher matcher = pattern.matcher(stringWriter.toString()); + if (matcher.matches()) { + toReturn = new String[matcher.groupCount()]; + + for (int i = 1; i <= matcher.groupCount(); i++) { + toReturn[i - 1] = matcher.group(i).trim(); + } + } + + if (toReturn != null) { + for (String temp : toReturn) { + System.out.println("VAL: " + temp); + } + } + return toReturn; + } + + public static boolean prependRegistryValue(File updatedReg, String root, String path, String key, String value) throws IOException { + + RegVersion version = Registry.getVersion(); + + String[] regArray = Registry.getValue(version, root, path, key); + + if (regArray != null) { + if (regArray[1].contains(value)) { + System.out.println("Value is already there."); + return true; + } + } + + String command = version.getUpdateCommand(root, path, key, value, regArray); + + /* + * If we are using a 1.0 version then use a provided reg.exe executable to use commands. If + * not operation will fail. + */ + if (version.isVersion().equals("1.00")) { + if (updatedReg.exists() && updatedReg.isFile()) { + command = updatedReg.getAbsolutePath() + command.replaceAll("reg", ""); + ; + } + } + + Process p = Runtime.getRuntime().exec(command); + StringWriter stringWriter = new StringWriter(); + + Lib.handleProcess(p, stringWriter); + + System.out.println("The string: " + stringWriter); + + if (stringWriter.toString().contains("err:")) { + return false; + } + return true; + } + + public static boolean prependRegistryValue(String root, String path, String key, String value) throws IOException { + + RegVersion version = Registry.getVersion(); + + String[] regArray = Registry.getValue(version, root, path, key); + + Process p = Runtime.getRuntime().exec(version.getUpdateCommand(root, path, key, value, regArray)); + StringWriter stringWriter = new StringWriter(); + + Lib.handleProcess(p, stringWriter); + + System.out.println("The string: " + stringWriter); + + if (stringWriter.toString().contains("err:")) { + return false; + } + return true; + } + + public static void main(String[] args) { + try { + Registry.prependRegistryValue(Registry.HKEY_CURRENT_USER, "environment", "path", "HI THERE"); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/Jaxp.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/Jaxp.java new file mode 100644 index 00000000000..84da2b7187d --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/Jaxp.java @@ -0,0 +1,610 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.util.xml;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import org.eclipse.osee.framework.jdk.core.util.io.CharBackedInputStream;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
+import org.xml.sax.SAXException;
+import com.sun.org.apache.xml.internal.serialize.OutputFormat;
+import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+
+public class Jaxp {
+ private static final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+
+ /**
+ * Obtains a list of all direct descendants of element
+ *
+ * @param element the element to find the children of
+ * @return A list of elements that are direct children of element. If no children exist, an empty list is returned.
+ */
+ public static List<Element> getChildDirects(Element element) {
+ NodeList nl = element.getChildNodes();
+ List<Element> elementList = new ArrayList<Element>(nl.getLength()); // this may be oversized
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node n = nl.item(i);
+ if (n.getNodeType() == Node.ELEMENT_NODE) elementList.add((Element) n);
+ }
+ return elementList;
+ }
+
+ /**
+ * Obtains a list of all direct descendants of element with the matching tag.
+ *
+ * @param element the element to find the children of
+ * @param childTagName the tag name for the children
+ * @return A list of elements that are direct children of element whose tag names match childTagName. If no such
+ * children exist, an empty list is returned.
+ */
+ public static List<Element> getChildDirects(Element element, String childTagName) {
+ List<Element> elementList = new ArrayList<Element>();
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node n = nl.item(i);
+ if (n.getNodeType() == Node.ELEMENT_NODE && ((Element) n).getTagName().equals(childTagName)) elementList.add((Element) n);
+ }
+ return elementList;
+ }
+
+ /**
+ * Obtains the first child that is a direct descendant of element with the matching tag
+ *
+ * @param element the element to find the child of
+ * @param childTagName the tag name for the child
+ * @return the first child with the given tag one level deep from element, null if no such child exists.
+ */
+ public static Element getChildDirect(Element element, String childTagName) {
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node n = nl.item(i);
+ if (n.getNodeType() == Node.ELEMENT_NODE && ((Element) n).getTagName().equals(childTagName)) return ((Element) n);
+ }
+ return null;
+ }
+
+ /**
+ * Obtains the first child that is a descendant of element with the matching tag
+ *
+ * @param element the element to find the child of
+ * @param childTagName the tag name for the child
+ * @return the first child with the given tag, or null if no such children exist
+ */
+ public static Element getChild(Element element, String childTagName) {
+ NodeList elementList = element.getElementsByTagName(childTagName);
+ return (Element) elementList.item(0);
+ }
+
+ public static Element createElement(Document d, String tag, String characterData) {
+ Element e = d.createElement(tag);
+ Text t = d.createTextNode(characterData);
+ e.appendChild(t);
+ // e.setTextContent(characterData);
+ // the above two lines do the same thing as this, but I trust them more so we'll go that
+ // route.
+ return e;
+ }
+
+ /**
+ * Obtains the character data for the Element. Note this differs from the Node.getTextContext(); call, which returns
+ * the concatenation of the character data for all children of this Element.
+ *
+ * @param e The element go get the character data for
+ * @param trimWhitespace iff true, each segment will be trimmed.
+ * @return All of the character data for the Element e. This means if there are elements separating the character
+ * data, it will all be concatenated together. If trimWhitespace, each segment will be trimmed of whitespace,
+ * with a single space between segments; otherwise the segments will be concatenated without any space
+ * separation. If no character data is present, returns an empty string.
+ */
+ public static String getElementCharacterData(Element e, boolean trimWhitespace) {
+ NodeList childNodes = e.getChildNodes();
+ String resultString = "";
+ boolean first = true;
+
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ Node n = childNodes.item(i);
+ if (n.getNodeType() == Node.TEXT_NODE) {
+ if (!first && trimWhitespace) resultString += " ";
+ resultString += trimWhitespace ? n.getNodeValue().trim() : n.getNodeValue();
+ first = false;
+ } else if (n.getNodeType() == Node.CDATA_SECTION_NODE) {
+ if (!first && trimWhitespace) resultString += " ";
+ resultString += trimWhitespace ? n.getNodeValue().trim() : n.getNodeValue();
+ first = false;
+ }
+
+ }
+ return resultString;
+ }
+
+ /**
+ * Obtains the character data for the Element. Note this differs from the Node.getTextContext(); call, which returns
+ * the concatenation of the character data for all children of this Element.
+ *
+ * @param e The element go get the character data for
+ * @return All of the character data for the Element e. This means if there are elements separating the character
+ * data, it will all be concatenated together. Each segment will be trimmed of whitespace, with a single
+ * space between segments. If no character data is present, returns an empty string.
+ */
+ public static String getElementCharacterData(Element e) {
+ return getElementCharacterData(e, true);
+ }
+
+ /**
+ * Obtains the character data for each element in the collection, return as a List. Each entry in the list
+ * corresponding to the character data for one of the elements in the collection.
+ *
+ * @param elements
+ * @return
+ */
+ public static List<String> getElementsCharacterData(Collection<Element> elements) {
+ List<String> result = new ArrayList<String>(elements.size());
+ for (Element e : elements) {
+ result.add(Jaxp.getElementCharacterData(e));
+ }
+ return result;
+ }
+
+ /**
+ * @param nodes The NodeList whose text we will return
+ * @return An ArrayList<String> of the text for all nodes
+ */
+ public static ArrayList<String> getChildrenTexts(NodeList nodes) {
+ ArrayList<String> retVal = new ArrayList<String>(nodes.getLength());
+
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Element element = (Element) nodes.item(i);
+ retVal.add(getElementCharacterData(element));
+ }
+ return retVal;
+ }
+
+ /**
+ * Obtains a list of Strings of the character data for all elements in the document whose tag name matches.
+ *
+ * @param document The document to be searched
+ * @param tagName The tagName for the children whose text we will obtain
+ * @return An ArrayList<String> of the text for all child nodes matching tagName
+ */
+ public static ArrayList<String> getChildrenTexts(Document document, String tagName) {
+ return getChildrenTexts(document.getElementsByTagName(tagName));
+ }
+
+ /**
+ * Obtains a list of Strings of the character data for all descendants of element whose tag name matches.
+ *
+ * @param document The document to be searched
+ * @param tagName The tagName for the children whose text we will obtain
+ * @return An ArrayList<String> of the text for all child nodes matching tagName
+ */
+ public static ArrayList<String> getChildrenTexts(Element element, String tagName) {
+ return getChildrenTexts(element.getElementsByTagName(tagName));
+ }
+
+ public static String getChildText(Element element, String childTagName, boolean trim) {
+ Element child = getChild(element, childTagName);
+ if (child != null) {
+ return getElementCharacterData(child, trim);
+ }
+ return null;
+ }
+
+ public static String getChildText(Element element, String childTagName) {
+ return getChildText(element, childTagName, false);
+ }
+
+ public static String getChildTextTrim(Element element, String childTagName) {
+ return getChildText(element, childTagName, true);
+ }
+
+ private static void findElementsInternal(List<Element> source, LinkedList<String> path, List<Element> list) {
+ String tag = path.poll();
+ LinkedList<String> childPath = new LinkedList<String>(path);
+
+ for (Element e : source) {
+ List<Element> children = getChildDirects(e, tag);
+ if (!children.isEmpty()) {
+ if (path.size() == 0) // we're at the end of the path
+ list.addAll(children);
+ else {
+ findElementsInternal(children, childPath, list);
+ }
+ }
+ }
+ }
+
+ /**
+ * Searches for all sub-elements found at the path provided.
+ *
+ * @param element The element underneath which we will search
+ * @param elementPath The path to follow. For example ["script","configuration","element_i_want"]
+ * @param firstIsRoot If true, the first item in elementPath must match element. That is, in the above example, e's
+ * tag name must be "script". This is useful when calling from the document level, that is where element is
+ * Document.getDocumentElement(), the first item in the path would be the first root element of the xml
+ * tree.
+ * @return All elements that match the specified path.
+ */
+ public static List<Element> findElements(Element element, List<String> elementPath, boolean firstIsRoot) {
+ List<Element> result = new LinkedList<Element>();
+ List<Element> source = new ArrayList<Element>(1);
+ source.add(element);
+
+ LinkedList<String> path;
+ if (elementPath instanceof LinkedList)
+ path = (LinkedList<String>) (elementPath);
+ else
+ path = new LinkedList<String>(elementPath);
+
+ // Strip off the first item of elementPath and make sure it matches 'element'
+ if (firstIsRoot) {
+ String firstTagName = path.poll();
+ if (element.getTagName().equals(firstTagName)) return result;
+ }
+
+ findElementsInternal(source, path, result);
+ return result;
+ }
+
+ private static List<Element> findElementsSinglePath(Element e, String elementPath, boolean firstIsRoot) {
+ return findElements(e, Arrays.asList(elementPath.split("/")), firstIsRoot);
+ }
+
+ private static List<Element> findElements(Element e, String elementPath, boolean firstIsRoot) {
+ List<Element> result = new LinkedList<Element>();
+ String[] paths = elementPath.split("\\|");
+
+ for (String path : paths) {
+ result.addAll(findElementsSinglePath(e, path, firstIsRoot));
+ }
+ return result;
+ }
+
+ public static List<Element> findElements(Element element, String elementPath) {
+ return findElements(element, elementPath, false);
+ }
+
+ public static List<Element> findElements(Document d, String elementPath) {
+ return findElements(d.getDocumentElement(), elementPath, true);
+ }
+
+ /**
+ * Searches for a sub-element found at the path provided. Each list element indicates the tag name for the next
+ * sub-element.
+ *
+ * @param e The element underneath which we will search
+ * @param elementPath The path to follow. For example ["script","configuration","element_i_want"]
+ * @return The first element that matches the provided path, beneath the provided element e, or null if no such
+ * element exists.
+ */
+ public static Element findElement(Element element, List<String> elementPath) {
+
+ Element e = element;
+ for (String tag : elementPath) {
+ NodeList a = e.getChildNodes();
+ Element nextElement = null;
+ for (int i = 0; i < a.getLength() && nextElement == null; i++) {
+ Node n = a.item(i);
+ if (n.getNodeType() == Node.ELEMENT_NODE && ((Element) n).getTagName().equals(tag)) nextElement =
+ (Element) n;
+ }
+ if (nextElement == null)
+ return null;
+ else
+ e = nextElement;
+ }
+ return e;
+ }
+
+ /**
+ * Searches the Document for the Element found at the '/' delimited path provided. The path should begin with the
+ * root node of the document.
+ *
+ * @param d The document to search
+ * @param elementPath The path to follow. For example "script/configuration/element_i_want"
+ * @return The first element that matches the provided path, or null if no such element exists.
+ */
+ public static Element findElement(Document d, String elementPath) {
+ List<String> pathList = Arrays.asList(elementPath.split("/"));
+ String rootTagName = pathList.get(0);
+ // Remove the first item from the list, Arrays.asList List type doesn't support .remove()
+ if (pathList.size() > 1)
+ pathList = pathList.subList(1, pathList.size());
+ else
+ pathList.clear();
+
+ Element root = d.getDocumentElement();
+ if (!root.getTagName().equals(rootTagName)) return null;
+ return findElement(d.getDocumentElement(), pathList);
+ }
+
+ /**
+ * Searches for a sub-element found at the '/' delimited path provided. The path should begin with the first node
+ * underneath the provided element.
+ *
+ * @param e The element underneath which we will search
+ * @param elementPath The path to follow. For example "script/configuration/element_i_want"
+ * @return The first element that matches the provided path, beneath the provided element e, or null if no such
+ * element exists.
+ */
+ public static Element findElement(Element e, String elementPath) {
+ return findElement(e, Arrays.asList(elementPath.split("/")));
+ }
+
+ public static Document readXmlDocument(InputStream is) throws ParserConfigurationException, SAXException, IOException {
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder.parse(is);
+ }
+
+ public static Document readXmlDocument(String xmlString) throws ParserConfigurationException, SAXException, IOException {
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ CharBackedInputStream charBak = new CharBackedInputStream();
+ charBak.addBackingSource(xmlString);
+ Document document = builder.parse(charBak);
+ return document;
+ }
+
+ public static Document readXmlDocument(File xmlFile) throws ParserConfigurationException, SAXException, IOException {
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document document = builder.parse(xmlFile);
+ return document;
+ }
+
+ public static Document readXmlDocumentFromResource(Class<?> base, String name) throws ParserConfigurationException, SAXException, IOException {
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document document = builder.parse(base.getResourceAsStream(name));
+ return document;
+ }
+
+ public static Document readXmlDocumentNamespaceAware(InputStream is) throws ParserConfigurationException, SAXException, IOException {
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder.parse(is);
+ }
+
+ public static Document readXmlDocumentNamespaceAware(String xmlString) throws ParserConfigurationException, SAXException, IOException {
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ CharBackedInputStream charBak = new CharBackedInputStream();
+ charBak.addBackingSource(xmlString);
+ Document document = builder.parse(charBak);
+ return document;
+ }
+
+ public static Document readXmlDocumentNamespaceAware(File xmlFile) throws ParserConfigurationException, SAXException, IOException {
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+
+ Document document = builder.parse(xmlFile);
+ return document;
+ }
+
+ public static Document readXmlDocumentFromResourceNamespaceAware(Class<?> base, String name) throws ParserConfigurationException, SAXException, IOException {
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document document = builder.parse(base.getResourceAsStream(name));
+ return document;
+ }
+
+ /**
+ * Adds the XSL style sheet processing instruction to the document.
+ *
+ * @param d
+ * @param xslPath
+ */
+ public static void setXslProperty(Document d, String xslPath) {
+ ProcessingInstruction xsl = d.createProcessingInstruction("xml-stylesheet", //
+ "type=\"text/xsl\" href=\"" + xslPath + "\"");
+ d.appendChild(xsl);
+ }
+
+ /**
+ * Adds an XML comment to a document
+ *
+ * @param d
+ * @param comment
+ */
+ public static void addComment(Document d, String comment) {
+ d.appendChild(d.createComment(comment));
+ d.getChildNodes().item(0);
+ }
+
+ public static void prependComment(Document d, String comment) {
+ Node commentNode = d.createComment(comment);
+
+ Node firstNode = getChild(d.getDocumentElement(), "TestScript");
+ d.insertBefore(commentNode, firstNode);
+ }
+
+ /**
+ * Writes the XML document 'document' to the 'file'.
+ *
+ * @param document The XML document to output
+ * @param file Where to put the output
+ * @throws TransformerException
+ * @throws IOException
+ */
+ public static void writeXmlDocument(Document document, File file) throws TransformerException, IOException {
+ writeXmlDocument(document, file, getCompactFormat(document));
+ }
+
+ /**
+ * Writes the XML document 'document' to the 'file'.
+ *
+ * @param document The XML document to output
+ * @param file Where to put the output
+ * @param prettyOutput If true, turns on indention so the output is more easily readable, if False turns indention
+ * off to save space.
+ * @throws TransformerException
+ * @throws IOException
+ */
+ public static void writeXmlDocument(Document document, File file, OutputFormat format) throws TransformerException, IOException {
+ BufferedWriter out = new BufferedWriter(new FileWriter(file));
+ outputXmlDocument(document, out, format);
+ out.close();
+ }
+
+ /**
+ * Gets the XML document 'document' as a string
+ *
+ * @param document The XML document to output
+ * @param file Where to put the output
+ * @param prettyOutput If true, turns on indention so the output is more easily readable, if False turns indention
+ * off and is assumed to provide the XML as compactly as possible.
+ * @throws TransformerException
+ */
+ public static String xmlToString(Document document, OutputFormat format) throws IOException {
+ StringWriter stringWriter = new StringWriter();
+ outputXmlDocument(document, stringWriter, format);
+ return stringWriter.toString();
+ }
+
+ /**
+ * Sends the XML to the output
+ *
+ * @param document The source XML
+ * @param output Where the XML is 'printed' to
+ * @param format The format style to use
+ * @throws IOException
+ */
+ private static void outputXmlDocument(Document document, Writer output, OutputFormat format) throws IOException {
+ XMLSerializer serializer = new XMLSerializer(output, format);
+ serializer.serialize(document);
+ }
+
+ /**
+ * Generates an OutputFormat that is pleasing to look at (indention, newlines, etc)
+ *
+ * @param document the document to be formatted
+ * @return the OutputFormat object to use for XML Formatting
+ * @see XMLSerializer
+ */
+ public static OutputFormat getPrettyFormat(Document document) {
+ OutputFormat format = new OutputFormat(document);
+ format.setIndenting(true);
+ format.setIndent(2);
+ return format;
+ }
+
+ /**
+ * Generates an OutputFormat that is compact (no extra whitepsace)
+ *
+ * @param document the document to be formatted
+ * @return the OutputFormat object to use for XML Formatting
+ * @see XMLSerializer
+ */
+ public static OutputFormat getCompactFormat(Document document) {
+ OutputFormat format = new OutputFormat(document);
+ format.setIndenting(false);
+ format.setLineSeparator("");
+ return format;
+ }
+
+ public static Document newDocument() throws ParserConfigurationException {
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder.newDocument();
+ }
+
+ public static String getDocumentXml(Document doc) throws TransformerException {
+ Source source = new DOMSource(doc);
+ StringWriter stringWriter = new StringWriter();
+ Result result = new StreamResult(stringWriter);
+ TransformerFactory factory = TransformerFactory.newInstance();
+ Transformer transformer = factory.newTransformer();
+ transformer.transform(source, result);
+ return stringWriter.getBuffer().toString();
+ }
+
+ public static void main(String args[]) {
+ try {
+ Document doc = readXmlDocument("<A name='george' type='level1'>" + " <B type='level2'>I'm at level 2</B>" //
+ + " <B type='level2'>I'm also at level 2</B>" //
+ + " <C type='level2'>" //
+ + " <D>likes to be C's child</D>" //
+ + "C has some more text here" //
+ + " <D>2nd round</D>"//
+ + "END of C" //
+ + " </C>" //
+ + "</A>");
+
+ Element e = (Element) getChild(doc.getDocumentElement(), "C");
+ System.out.println("e.getTagName :" + e.getTagName());
+ System.out.println("e.getLocalName :" + e.getLocalName());
+ System.out.println("e.getNodeName :" + e.getNodeName());
+ System.out.println("e.getNodeType :" + e.getNodeType());
+ System.out.println("e.getNodeValue :" + e.getNodeValue());
+ System.out.println("e.getPrefix :" + e.getPrefix());
+ System.out.println("e.getTextContent :" + e.getTextContent());
+ System.out.println("");
+ System.out.println("e.getFirstChild().getNodeValue :" + e.getFirstChild().getNodeValue());
+ System.out.println("e.getFirstChild().getTextContent :" + e.getFirstChild().getTextContent());
+ System.out.println("");
+ System.out.println(getElementCharacterData(e));
+
+ System.out.println("");
+ System.out.println("Looking for the Top level item:");
+ NodeList nl = doc.getElementsByTagName("A");
+ for (int i = 0; i < nl.getLength(); i++) {
+ System.out.println(" Found: " + nl.item(i).getNodeName());
+ }
+ System.out.println("Looking for the Top level item:");
+ nl = doc.getDocumentElement().getElementsByTagName("A");
+ for (int i = 0; i < nl.getLength(); i++) {
+ System.out.println("Found: " + nl.item(i).getNodeName());
+ }
+
+ System.out.println("");
+ System.out.println("Searching For D:");
+ Element em = findElement(doc, "A/C/D");
+ System.out.println(em.getTagName() + ":" + getElementCharacterData(em));
+
+ List<Element> list = findElements(doc.getDocumentElement(), "C/D");
+ for (Element te : list)
+ System.out.println(te.getTagName() + ":" + getElementCharacterData(te));
+
+ Element joe = Jaxp.createElement(doc, "f", "This is F's Data");
+ em.appendChild(joe);
+
+ System.out.println(Jaxp.getElementCharacterData(joe));
+
+ System.out.println("******");
+ System.out.println(xmlToString(doc, getPrettyFormat(doc)));
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/SimpleNamespaceContext.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/SimpleNamespaceContext.java new file mode 100644 index 00000000000..9001607ee11 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/SimpleNamespaceContext.java @@ -0,0 +1,71 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.osee.framework.jdk.core.util.xml;
+
+/**
+ * @author b289820
+ */
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+
+public class SimpleNamespaceContext implements NamespaceContext {
+
+ private Map urisByPrefix = new HashMap();
+
+ private Map prefixesByURI = new HashMap();
+
+ public SimpleNamespaceContext() {
+ // prepopulate with xml and xmlns prefixes
+ // per JavaDoc of NamespaceContext interface
+ addNamespace(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI);
+ addNamespace(XMLConstants.XMLNS_ATTRIBUTE, XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
+ }
+
+ public synchronized void addNamespace(String prefix, String namespaceURI) {
+ urisByPrefix.put(prefix, namespaceURI);
+ if (prefixesByURI.containsKey(namespaceURI)) {
+ ((Set) prefixesByURI.get(namespaceURI)).add(prefix);
+ } else {
+ Set set = new HashSet();
+ set.add(prefix);
+ prefixesByURI.put(namespaceURI, set);
+ }
+ }
+
+ public String getNamespaceURI(String prefix) {
+ if (prefix == null) throw new IllegalArgumentException("prefix cannot be null");
+ if (urisByPrefix.containsKey(prefix))
+ return (String) urisByPrefix.get(prefix);
+ else
+ return XMLConstants.NULL_NS_URI;
+ }
+
+ public String getPrefix(String namespaceURI) {
+ return (String) getPrefixes(namespaceURI).next();
+ }
+
+ public Iterator getPrefixes(String namespaceURI) {
+ if (namespaceURI == null) throw new IllegalArgumentException("namespaceURI cannot be null");
+ if (prefixesByURI.containsKey(namespaceURI)) {
+ return ((Set) prefixesByURI.get(namespaceURI)).iterator();
+ } else {
+ return Collections.EMPTY_SET.iterator();
+ }
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/Xml.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/Xml.java new file mode 100644 index 00000000000..13b4584d57d --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/Xml.java @@ -0,0 +1,460 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.util.xml;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList;
+
+/**
+ * @author David Diepenbrock
+ * @author Paul Waldfogel
+ */
+public class Xml {
+ private static final String[] XML_CHARS = new String[] {"[&]", "[<]", "[>]", "[\"]"};
+ private static final String[] XML_ESCAPES = new String[] {"&", "<", ">", """};
+ private static final String LINEFEED = " ";
+ private static final String CARRIAGE_RETURN = " ";
+ private static final Pattern squareBracket = Pattern.compile("\\]");
+ public final static XPathFactory myXPathFactory = XPathFactory.newInstance();
+ public final static XPath myXPath = myXPathFactory.newXPath();
+ public final static String wordLeader1 =
+ "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" + "<?mso-application progid='Word.Document'?>";
+ public final static String wordLeader2 =
+ "<w:wordDocument xmlns:w='http://schemas.microsoft.com/office/word/2003/wordml' xmlns:v='urn:schemas-microsoft-com:vml' xmlns:w10='urn:schemas-microsoft-com:office:word' xmlns:sl='http://schemas.microsoft.com/schemaLibrary/2003/core' xmlns:aml='http://schemas.microsoft.com/aml/2001/core' xmlns:wx='http://schemas.microsoft.com/office/word/2003/auxHint' xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882' xmlns:wsp='http://schemas.microsoft.com/office/word/2003/wordml/sp2' xmlns:ns0='http://www.w3.org/2001/XMLSchema' xmlns:ns1='http://eclipse.org/artifact.xsd' xmlns:st1='urn:schemas-microsoft-com:office:smarttags' w:macrosPresent='no' w:embeddedObjPresent='no' w:ocxPresent='no' xml:space='preserve'>";
+ public final static String wordLeader = wordLeader1.concat(wordLeader2);
+ public final static String wordBody = "<w:body></w:body>";
+ public final static String wordTrailer = "</w:wordDocument> ";
+ public final SimpleNamespaceContext mySimpleNamespaceContext = new SimpleNamespaceContext();
+ public final static Matcher theFunnyQuoteMatcher = Pattern.compile("’").matcher("");
+
+ /**
+ * TODO Optimize algorithm
+ *
+ * @param text
+ * @return Returns a string with entity reference characters unescaped.
+ */
+ public static StringBuilder unescape(String text) {
+ StringBuilder strB = new StringBuilder();
+ int startIndex, endIndex;
+ char chr;
+
+ for (int index = 0; index < text.length(); index++) {
+ chr = text.charAt(index);
+ if (chr == '&') {
+ startIndex = index;
+ endIndex = text.indexOf(';', startIndex) + 1;
+ if (endIndex > startIndex && endIndex < (startIndex + 6)) {
+ String entityReference = text.substring(startIndex, endIndex);
+ if (entityReference.equals("&"))
+ strB.append('&');
+ else if (entityReference.equals("<"))
+ strB.append('<');
+ else if (entityReference.equals(">"))
+ strB.append('>');
+ else if (entityReference.equals(" "))
+ strB.append(' ');
+ else if (entityReference.equals("""))
+ strB.append('"');
+ else
+ throw new IllegalArgumentException(
+ "unknown entity reference: " + text.substring(startIndex, endIndex));
+ index = endIndex - 1;
+ } else {
+ strB.append(chr);
+ }
+ } else {
+ strB.append(chr);
+ }
+ }
+ return strB;
+ }
+
+ /**
+ * TODO Optimize algorithm
+ *
+ * @param text
+ * @return Returns a string with entity reference characters escaped.
+ */
+ public static CharSequence escape(CharSequence text) {
+ String textString = text.toString();
+ for (int x = 0; x < XML_CHARS.length; x++) {
+ textString = textString.replaceAll(XML_CHARS[x], XML_ESCAPES[x]);
+ }
+
+ return textString;
+ }
+
+ public static void writeAsCdata(Appendable appendable, String string) throws IOException {
+ if (string.indexOf('<') == -1 && string.indexOf('&') == -1 && string.indexOf("]]>") == -1) {
+ writeData(appendable, string);
+ } else {
+ if (string.indexOf(']') == -1) {
+ writeCdata(appendable, string);
+ } else {
+ // work around bug in excel xml parsing that thinks a single ] closes CDATA
+ String[] tokens = squareBracket.split(string);
+ for (int i = 0; i < tokens.length; i++) {
+ writeCdata(appendable, tokens[i]);
+ if (i != tokens.length - 1) { // the last token would not have been followed by ]
+ appendable.append(']');
+ }
+ }
+ }
+ }
+ }
+
+ private static void writeCdata(Appendable appendable, String content) throws IOException {
+ appendable.append("<![CDATA[");
+ appendable.append(content);
+ appendable.append("]]>");
+ }
+
+ private static void writeData(Appendable appendable, String string) throws IOException {
+ for (int index = 0; index < string.length(); index++) {
+ char value = string.charAt(index);
+ if (value == '\r') {
+ appendable.append(CARRIAGE_RETURN);
+ } else if (value == '\n') {
+ appendable.append(LINEFEED);
+ } else {
+ appendable.append(value);
+ }
+ }
+ }
+
+ public static String treatNonUTF8Characters(String contentString) {
+ String resultString = contentString;
+ String[][] nonUTF8CharactersOfInterest = { {"–", "-"}, {"’", "'"}, {"’", "'"}, {"“", "\""}, {"”", "\""}};//Wider than usual dash , smaller than usual bullet
+ for (int i = 0; i < nonUTF8CharactersOfInterest.length; i++) {
+ String[] splitsOfNonUTF8 = resultString.split(nonUTF8CharactersOfInterest[i][0]);//Wider than usual dash or bullet
+ if (splitsOfNonUTF8.length > 1) {
+ StringBuffer myStringBuffer = new StringBuffer();
+ for (int j = 0; j < splitsOfNonUTF8.length; j++) {
+ myStringBuffer.append(splitsOfNonUTF8[j]);
+ if (splitsOfNonUTF8[j].length() > 0 && j < splitsOfNonUTF8.length - 1) {
+ myStringBuffer.append(nonUTF8CharactersOfInterest[i][1]);
+ }
+ }
+ resultString = myStringBuffer.toString();
+ }
+ }
+ String[] splits = resultString.split("[^\\p{Space}\\p{Graph}]");
+ int stringPosition = 0;
+ if (splits.length > 1) {
+ StringBuffer myStringBuffer = new StringBuffer();
+ for (int i = 0; i < splits.length; i++) {
+ stringPosition = stringPosition + splits[i].length();
+ myStringBuffer.append(splits[i]);
+ stringPosition = stringPosition + 1;
+ if (splits[i].length() > 0 && i < splits.length - 1) {
+ myStringBuffer.append("-");
+ }
+ }
+ resultString = myStringBuffer.toString();
+ }
+
+ return resultString;
+ }
+
+ public static final Element appendNewElementWithText(Node parentNode, String newElementTagName, String newText) {
+ Element newElement = null;
+ try {
+ Document ownerDocument =
+ (parentNode.getNodeType() == Node.DOCUMENT_NODE) ? (Document) parentNode : parentNode.getOwnerDocument();
+ newElement = ownerDocument.createElement(newElementTagName);
+ parentNode.appendChild(newElement);
+ if (newText != null) {
+ Node newTextNode = ownerDocument.createTextNode(newText);
+ newElement.appendChild(newTextNode);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ ;
+ return newElement;
+ }
+
+ public static final Element appendNewElementWithTextCData(Node parentNode, String newElementTagName, String newText) {
+ Element newElement = null;
+ try {
+ Document ownerDocument =
+ (parentNode.getNodeType() == Node.DOCUMENT_NODE) ? (Document) parentNode : parentNode.getOwnerDocument();
+ newElement = ownerDocument.createElement(newElementTagName);
+ parentNode.appendChild(newElement);
+ if (newText != null) {
+ Node newTextNode = ownerDocument.createCDATASection(newText);
+ newElement.appendChild(newTextNode);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ ;
+ return newElement;
+ }
+
+ public static final Element appendNewElementWithTextAndAttributes(Node parentNode, String newElementTagName, String newText, String[][] attributes) {
+ Element newElement = null;
+ try {
+ Document ownerDocument =
+ (parentNode.getNodeType() == Node.DOCUMENT_NODE) ? (Document) parentNode : parentNode.getOwnerDocument();
+ newElement = ownerDocument.createElement(newElementTagName);
+ parentNode.appendChild(newElement);
+ if (newText != null) {
+ Node newTextNode = ownerDocument.createTextNode(newText);
+ newElement.appendChild(newTextNode);
+ }
+ if (attributes != null) {
+ for (String[] attribute : attributes) {
+ newElement.setAttribute(attribute[0], attribute[1]);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return newElement;
+ }
+
+ public static final Element[] appendNewElementsWithText(Node parentNode, String newElementsTagName, String[] textInstances) {
+ Element[] newElements = new Element[textInstances.length];
+ try {
+ if (textInstances != null) {
+ Document ownerDocument =
+ (parentNode.getNodeType() == Node.DOCUMENT_NODE) ? (Document) parentNode : parentNode.getOwnerDocument();
+ for (int i = 0; i < textInstances.length; i++) {
+ newElements[i] = ownerDocument.createElement(newElementsTagName);
+ parentNode.appendChild(newElements[i]);
+ String textInstance = (textInstances[i] == null) ? "null" : textInstances[i];
+ textInstance = (textInstance.length() == 0) ? "null" : textInstance;
+ newElements[i].appendChild(ownerDocument.createTextNode(textInstance));
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return newElements;
+ }
+
+ public static final Element appendNewElementWithTextAndOneAttribute(Node parentNode, String newElementTagName, String newText, String attributeName, String attributeValue) {
+ Element newElement = null;
+ try {
+ newElement = appendNewElementWithText(parentNode, newElementTagName, newText);
+ newElement.setAttribute(attributeName, attributeValue);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ ;
+ return newElement;
+ }
+
+ public final static String restartNumberingWhenPreparingToEditWithWord(InputStream myInputStream) throws XPathExpressionException, ParserConfigurationException, TransformerException, SAXException, IOException {
+ SimpleNamespaceContext mySimpleNamespaceContext = new SimpleNamespaceContext();
+ addNamespacesForWordMarkupLanguage(myXPath, mySimpleNamespaceContext);
+ Document myDocument = Jaxp.readXmlDocumentNamespaceAware(myInputStream);
+ Element myDocumentElement = myDocument.getDocumentElement();
+ Node[] myListss = selectNodeList(myDocumentElement, "descendant::w:lists");
+ Node[] myLists = selectNodeList(myDocumentElement, "descendant::w:lists/w:list");
+ if (myLists.length > 0 && myListss.length > 0) {
+ Node[] mywilfo = selectNodeList(myLists[myLists.length - 1], "@w:ilfo");
+ if (mywilfo.length > 0) {
+ String myLastUsedListInitializeListFormat = mywilfo[0].getNodeValue();//
+ int myNextILFO = Integer.parseInt(myLastUsedListInitializeListFormat);
+ Node[] myListDefinition =
+ selectNodeList(myDocumentElement,
+ "descendant::w:listDef[child::w:lvl[1]/w:pStyle/@w:val = 'listlvl1'][1]");//<w:pStyle w:val="listlvl1"/>
+ if (myListDefinition.length > 0) {
+ String mylistDefaultID = selectNodeList(myListDefinition[0], "@w:listDefId")[0].getNodeValue();
+ Node[] myWord_Formatted_Contents = selectNodeList(myDocument, "descendant::ns1:Word_Formatted_Content");
+ for (int i = 0; i < myWord_Formatted_Contents.length; i++) {
+ Node[] myPStyles =
+ selectNodeList(myWord_Formatted_Contents[i],
+ "descendant::w:pPr[child::w:pStyle[@w:val = 'listlvl1']]");
+ for (int j = 0; j < Math.min(1, myPStyles.length); j++) {
+ Node[] myListProperties = selectNodeList(myPStyles[j], "child::w:listPr");
+ if (myListProperties.length > 0) {
+ myNextILFO++;
+ Element newWList =
+ appendNewElementWithTextAndOneAttribute(myListss[0], "w:list", null, "w:ilfo",
+ "" + myNextILFO);
+ appendNewElementWithTextAndOneAttribute(newWList, "w:ilst", null, "w:val", mylistDefaultID);
+ Element new_lvlOverride =
+ appendNewElementWithTextAndOneAttribute(newWList, "w:lvlOverride", null, "w:ilvl", "0");
+ appendNewElementWithTextAndOneAttribute(new_lvlOverride, "w:startOverride", null, "w:val", "1");
+ appendNewElementWithTextAndOneAttribute(myListProperties[0], "w:ilvl", null, "w:val", "0");
+ appendNewElementWithTextAndOneAttribute(myListProperties[0], "w:ilfo", null, "w:val",
+ "" + myNextILFO);
+ }
+ }
+ }
+ }
+ }
+ }
+ String myString = Jaxp.xmlToString(myDocument, Jaxp.getPrettyFormat(myDocument));
+ return myString;
+ }
+
+ public static Document readWordFormattedContent(String myInputString) throws IOException, ParserConfigurationException, SAXException {
+ Document myDocument = null;
+ myDocument = Jaxp.readXmlDocumentNamespaceAware(wordLeader.concat(myInputString).concat(wordTrailer));
+ return myDocument;
+ }
+
+ public static final Object addNamespacesForWordMarkupLanguage(XPath myXPath, SimpleNamespaceContext mySimpleNamespaceContext) {
+ try {
+ if (myXPath.getNamespaceContext() == null) {
+ mySimpleNamespaceContext.addNamespace("w", "http://schemas.microsoft.com/office/word/2003/wordml");
+ mySimpleNamespaceContext.addNamespace("wx", "http://schemas.microsoft.com/office/word/2003/auxHint");
+ mySimpleNamespaceContext.addNamespace("o", "urn:schemas-microsoft-com:office:office");
+ mySimpleNamespaceContext.addNamespace("v", "urn:schemas-microsoft-com:vml");
+ mySimpleNamespaceContext.addNamespace("aml", "http://schemas.microsoft.com/aml/2001/core");
+ mySimpleNamespaceContext.addNamespace("dt", "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882");
+ mySimpleNamespaceContext.addNamespace("ns0", "http://www.w3.org/2001/XMLSchema");
+ mySimpleNamespaceContext.addNamespace("ns1", "http://eclipse.org/artifact.xsd");
+ mySimpleNamespaceContext.addNamespace("ns2", "urn:schemas-microsoft-com:office:smarttags");
+ mySimpleNamespaceContext.addNamespace("sl", "http://schemas.microsoft.com/schemaLibrary/2003/core");
+ mySimpleNamespaceContext.addNamespace("st0", "urn:schemas-microsoft-com:office:smarttags");
+ mySimpleNamespaceContext.addNamespace("st1", "urn:schemas-microsoft-com:office:smarttags");
+ mySimpleNamespaceContext.addNamespace("st2", "urn:schemas-microsoft-com:office:smarttags");
+ mySimpleNamespaceContext.addNamespace("st3", "urn:schemas-microsoft-com:office:smarttags");
+ mySimpleNamespaceContext.addNamespace("st4", "urn:schemas-microsoft-com:office:smarttags");
+ mySimpleNamespaceContext.addNamespace("w10", "urn:schemas-microsoft-com:office:word");
+ mySimpleNamespaceContext.addNamespace("wsp", "http://schemas.microsoft.com/office/word/2003/wordml/sp2");
+ mySimpleNamespaceContext.addNamespace("foo", "http://apache.org/foo");
+ mySimpleNamespaceContext.addNamespace("bar", "http://apache.org/bar");
+ myXPath.setNamespaceContext(mySimpleNamespaceContext);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static final boolean isSeriousXPath(String xPathExpression) {
+ return (xPathExpression.indexOf("[") > -1 || xPathExpression.indexOf("]") > -1 || xPathExpression.indexOf("(") > -1 || xPathExpression.indexOf(")") > -1 || xPathExpression.indexOf(":") > -1);
+ }
+
+ public static final Node[] selectNodeList(Node startingNode, String xPathExpression) throws XPathExpressionException {
+ Node[] resultNodes = null;
+ if (!isSeriousXPath(xPathExpression) && startingNode.getNodeType() == Node.ELEMENT_NODE) {
+ List<Element> resultElementList = Jaxp.findElements((Element) startingNode, xPathExpression);
+ resultNodes = resultElementList.toArray(new Node[0]);
+ } else {
+ Object publisherNodeSet = null;
+ publisherNodeSet = myXPath.evaluate(xPathExpression, startingNode, XPathConstants.NODESET);
+ DTMNodeList myNodeList = (DTMNodeList) publisherNodeSet;
+ resultNodes = new Node[myNodeList.getLength()];
+ for (int i = 0; i < resultNodes.length; i++) {
+ resultNodes[i] = myNodeList.item(i);
+ }
+ }
+ return resultNodes;
+ }
+
+ public static final String selectNodesText(Node startingNode, String xPathExpression) throws XPathExpressionException {
+ String resultString = null;
+ if (!isSeriousXPath(xPathExpression) && startingNode.getNodeType() == Node.ELEMENT_NODE) {
+ Element foundElement = Jaxp.findElement((Element) startingNode, xPathExpression);
+ if (foundElement != null) {
+ resultString = selectNodesText(foundElement).trim();
+ }
+ } else {
+ Node[] selectedNodes = selectNodeList(startingNode, xPathExpression);
+ if (selectedNodes.length > 0) {
+ resultString = selectNodesText((Element) selectedNodes[0]).trim();
+ }
+ }
+ return resultString;
+ }
+
+ public static final String selectNodesText(Node startingNode) {
+ StringBuffer resultStringBuffer = new StringBuffer();
+ NodeList childNodes = startingNode.getChildNodes();
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ if (childNodes.item(i).getNodeType() == Node.CDATA_SECTION_NODE || childNodes.item(i).getNodeType() == Node.TEXT_NODE) {
+ resultStringBuffer.append(childNodes.item(i).getNodeValue().trim());
+ }
+ }
+ return resultStringBuffer.toString();
+ }
+
+ public static final Element makeTable(Element parentDivElement, String caption, String[][] columnDescriptors) {
+ Element newTableElement =
+ appendNewElementWithTextAndAttributes(parentDivElement, "table", null, new String[][] { {"border", "1"},
+ {"cellpadding", "3"}, {"cellspacing", "0"}, {"width", "100%"}});
+ appendNewElementWithText(newTableElement, "caption", caption);
+ Element columnGroupElement =
+ appendNewElementWithTextAndAttributes(newTableElement, "colgroup", null, new String[][] {{"align", "left"}});
+ String[] columnNames = new String[columnDescriptors.length];
+ for (int i = 0; i < columnDescriptors.length; i++) {
+ columnNames[i] = columnDescriptors[i][0];
+ appendNewElementWithTextAndAttributes(columnGroupElement, "col", null, new String[][] {{"width",
+ columnDescriptors[i][1]}});//width,33
+ }
+ Element headingTableRowElement = appendNewElementWithText(newTableElement, "tr", null);
+ appendNewElementsWithText(headingTableRowElement, "th", columnNames);
+ return newTableElement;
+ }
+
+ public static final Element[] makeDivElementAndTableElement(Element parentDivElement, String caption, String[][] columnDescriptors) {
+ Element[] divAndTableElements =
+ new Element[] {parentDivElement, parentDivElement.getOwnerDocument().createElement("div"), null};
+ divAndTableElements[2] = makeTable(divAndTableElements[1], caption, columnDescriptors);
+ return divAndTableElements;
+ }
+
+ public static final Element[] makeTableRow(Element[] devAndTableElements, String[] cellContents) {
+ Element nextRow = Xml.appendNewElementWithText(devAndTableElements[2], "tr", null);
+ appendNewElementsWithText(nextRow, "td", cellContents);
+ return devAndTableElements;
+ }
+
+ public static final Element makeTableRow(Element[] devAndTableElements, String[][] cellContentsAndStyle) {
+ Element nextRow = Xml.appendNewElementWithText(devAndTableElements[2], "tr", null);
+ for (String[] cellContentsAndStyleArray : cellContentsAndStyle) {
+ if (cellContentsAndStyleArray.length > 1) {
+ appendNewElementWithTextAndOneAttribute(nextRow, "td", cellContentsAndStyleArray[0],
+ cellContentsAndStyleArray[1], cellContentsAndStyleArray[2]);
+ } else {
+ appendNewElementsWithText(nextRow, "td", new String[] {cellContentsAndStyleArray[0]});
+ }
+ }
+ return nextRow;
+ }
+
+ public static final Node writePrettyXML(Node aNode, File resultXmlFile) {
+ try {
+ Node[] notUTF8Nodes = Xml.selectNodeList(aNode, "descendant::text()[contains(.,'’')]");
+ for (int i = 0; i < notUTF8Nodes.length; i++) {
+ notUTF8Nodes[i].setNodeValue(theFunnyQuoteMatcher.reset(notUTF8Nodes[i].getNodeValue()).replaceAll("'"));
+ }
+ Jaxp.writeXmlDocument(aNode.getOwnerDocument(), resultXmlFile, Jaxp.getPrettyFormat(aNode.getOwnerDocument()));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return aNode;
+ }
+
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/XmlOutputTransform.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/XmlOutputTransform.java new file mode 100644 index 00000000000..14a3ecd90b2 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/XmlOutputTransform.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.xml; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStream; +import java.io.StringWriter; +import java.io.Writer; +import javax.xml.transform.Result; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +/** + * @author Roberto E. Escobar + */ +public final class XmlOutputTransform { + + // Prevent Instantiation + private XmlOutputTransform() { + } + + protected static void xmlToHtml(InputStream inputXML, InputStream inputXslt, Result result) throws Exception { + Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(inputXslt)); + xmlToHtml(inputXML, transformer, result); + } + + private static void xmlToHtml(InputStream inputXML, Transformer transformer, Result result) throws Exception { + try { + transformer.transform(new StreamSource(inputXML), result); + } catch (Exception ex) { + throw new Exception("Error during Transform. ", ex); + } + } + + private static void xmlToHtml(InputStream inputXML, InputStream inputXslt, Writer result) throws Exception { + boolean isNetworked = false; + + if (true != isNetworked) { + // Perform Transform Directly + xmlToHtml(inputXML, inputXslt, new StreamResult(result)); + } else { + // Perform Transform as a Separate process by launching an XmlTransformServer. + XmlTransformAsProcess.getHtmlFromXml(inputXML, inputXslt, result); + } + } + + public static String xmlToHtmlString(String sourceFile, File transformToApply) { + return xmlToHtmlString(new File(sourceFile), transformToApply); + } + + public static String xmlToHtmlString(File sourceFile, String transformToApply) { + return xmlToHtmlString(sourceFile, new File(transformToApply)); + } + + public static String xmlToHtmlString(String sourceFile, String transformToApply) { + return xmlToHtmlString(new File(sourceFile), new File(transformToApply)); + } + + public static File xmlToHtmlFile(File sourceFile, File transformToApply) throws Exception { + File file = new File(sourceFile.getAbsolutePath().replace(".tmo", ".html")); + xmlToHtml(new FileInputStream(sourceFile), new FileInputStream(transformToApply), new FileWriter(file)); + return file; + } + + public static String xmlToHtmlString(File sourceFile, File transformToApply) { + StringWriter sWriter = new StringWriter(); + try { + xmlToHtml(new FileInputStream(sourceFile), new FileInputStream(transformToApply), sWriter); + } catch (Exception e) { + e.printStackTrace(); + } + return sWriter.toString(); + } + + public static String xmlToHtmlString(InputStream sourceXML, Transformer transformer) throws Exception { + StringWriter sWriter = new StringWriter(); + xmlToHtml(sourceXML, transformer, new StreamResult(sWriter)); + return sWriter.toString(); + } +}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/XmlTransformAsProcess.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/XmlTransformAsProcess.java new file mode 100644 index 00000000000..c600b33a86b --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/XmlTransformAsProcess.java @@ -0,0 +1,183 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.xml; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.Writer; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.Socket; +import java.net.URISyntaxException; +import java.net.URL; +import java.security.CodeSource; +import java.security.ProtectionDomain; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.osee.framework.jdk.core.util.network.PortUtil; + +/** + * @author Roberto E. Escobar + */ +public class XmlTransformAsProcess { + + private Socket clientSocket; + private InputStream inputFromNetwork; + private OutputStream outputFromNetwork; + private Process process; + + private XmlTransformAsProcess() { + process = null; + clientSocket = null; + inputFromNetwork = null; + outputFromNetwork = null; + } + + @SuppressWarnings("unchecked") + private URL getClassLocation(final Class classToFind) { + URL result = null; + if (classToFind == null) { + throw new IllegalArgumentException("Class is null"); + } + final String classAsResource = classToFind.getName().replace('.', '/').concat(".class"); + final ProtectionDomain pd = classToFind.getProtectionDomain(); + if (pd != null) { + final CodeSource cs = pd.getCodeSource(); + if (cs != null) { + result = cs.getLocation(); + } + if (result != null) { + // Convert a code source location into a full class file location + if (result.getProtocol().equals("file")) { + try { + if (result.toExternalForm().endsWith(".jar") || result.toExternalForm().endsWith(".zip")) + result = new URL("jar:".concat(result.toExternalForm()).concat("!/").concat(classAsResource)); + else if (new File(result.getFile()).isDirectory()) result = new URL(result, classAsResource); + } catch (MalformedURLException ignore) { + } + } + } + } + if (result == null) { + // Try to find class definition as a resource + final ClassLoader classLoader = classToFind.getClassLoader(); + result = + classLoader != null ? classLoader.getResource(classAsResource) : ClassLoader.getSystemResource(classAsResource); + } + return result; + } + + private void connectToServer(InetAddress address, int port) throws Exception { + try { + for (int i = 0; i < 10; i++) { + try { + clientSocket = new Socket(address, port); + break; + } catch (Throwable th) { + Thread.sleep(1000); + } + } + System.out.println("Connected"); + inputFromNetwork = new BufferedInputStream(clientSocket.getInputStream()); + outputFromNetwork = new BufferedOutputStream(clientSocket.getOutputStream()); + } catch (Exception ex) { + throw new Exception("Unable to Connect to Transform Server. ", ex); + } + } + + private void launchServer(int port) throws Exception { + List<String> commands = new ArrayList<String>(); + try { + URL url = getClassLocation(XmlTransformServer.class); + String path = new File(url.toURI()).getAbsolutePath(); + int indexOf = path.indexOf("bin"); + path = path.substring(0, indexOf + 4); + File classFileLocation = new File(path); + + String className = XmlTransformServer.class.getName(); + + commands.add("java"); + commands.add("-Xmx1024M"); + commands.add(className); + commands.add(Integer.toString(port)); + + ProcessBuilder builder = new ProcessBuilder(); + builder.directory(classFileLocation); + builder.command(commands); + process = builder.start(); + Thread.sleep(800); + } catch (URISyntaxException ex) { + throw new Exception("Unable to find XmlTransformServer class in File System. ", ex); + } catch (Exception ex) { + throw new Exception("Unable to launch TransformServer. ", ex); + } + } + + public void processXml(InputStream xmlSource, InputStream xsltSource, Writer result) { + try { + XmlTransformServer.sendStream(clientSocket, xmlSource, outputFromNetwork); + Thread.sleep(2000); + System.gc(); + System.out.println("Sent Xml"); + XmlTransformServer.sendStream(clientSocket, xsltSource, outputFromNetwork); + System.gc(); + Thread.sleep(2000); + System.out.println("Sent Xslt"); + XmlTransformServer.receiveStream(clientSocket, inputFromNetwork, result); + System.gc(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + private void clearResources() throws Exception { + if (inputFromNetwork != null) { + inputFromNetwork.close(); + } + if (outputFromNetwork != null) { + outputFromNetwork.close(); + } + if (clientSocket != null) { + clientSocket.close(); + } + if (process != null) { + process.destroy(); + } + } + + public static void getHtmlFromXml(InputStream xmlSource, InputStream xsltSource, Writer results) throws Exception { + XmlTransformAsProcess xmlTransformProcess = new XmlTransformAsProcess(); + try { + InetAddress address = InetAddress.getLocalHost(); + int port = PortUtil.getInstance().getValidPort(); + System.out.println("Transform Server at port: " + port); + System.gc(); + xmlTransformProcess.launchServer(port); + xmlTransformProcess.connectToServer(address, port); + xmlTransformProcess.processXml(xmlSource, xsltSource, results); + + } finally { + xmlTransformProcess.clearResources(); + System.gc(); + } + } + + public static void main(String[] args) throws Exception { + InputStream xmlInput = new FileInputStream(args[0]); + InputStream xsltInput = new FileInputStream(args[1]); + getHtmlFromXml(xmlInput, xsltInput, new PrintWriter(System.out)); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/XmlTransformServer.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/XmlTransformServer.java new file mode 100644 index 00000000000..673c78baece --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/XmlTransformServer.java @@ -0,0 +1,203 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.xml; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.Writer; +import java.net.ServerSocket; +import java.net.Socket; +import javax.xml.transform.ErrorListener; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +/** + * @author Roberto E. Escobar + */ +public class XmlTransformServer { + + private static int MAX_PACKET_SIZE = 65536; + private static int FINISH_PROCESSING_FLAG = -1; + private static int TIMEOUT = 60000 * 3; + + private InputStream inputFromNetwork; + private OutputStream outputToNetwork; + + private Socket clientSocket; + private ServerSocket server; + private int portNumber; + private String userHome; + + public XmlTransformServer() { + this.server = null; + this.portNumber = 0; + this.userHome = System.getProperty("user.home"); + } + + private void initializeServer(int portNumber) throws Exception { + this.portNumber = portNumber; + try { + server = new ServerSocket(portNumber); + clientSocket = server.accept(); + inputFromNetwork = new BufferedInputStream(clientSocket.getInputStream()); + outputToNetwork = new BufferedOutputStream(clientSocket.getOutputStream()); + } catch (Exception ex) { + throw new Exception("Unable to launch Server and get Connection. ", ex); + } + } + + public void process() throws Exception { + performRead("xml", ".xml"); + performRead("xslt", ".xsl"); + performWrite(); + } + + private void performRead(String prefix, String extension) throws Exception { + File file = new File(userHome + File.separator + prefix + portNumber + extension); + file.createNewFile(); + FileOutputStream fos = new FileOutputStream(file); + try { + receiveStream(clientSocket, inputFromNetwork, new PrintStream(fos)); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + fos.close(); + } + } + + private void performWrite() throws Exception { + File file = new File(userHome + File.separator + "html" + portNumber + ".html"); + file.createNewFile(); + FileOutputStream fos = new FileOutputStream(file); + + File fisXml = new File(userHome + File.separator + "xml" + portNumber + ".xml"); + File fisXslt = new File(userHome + File.separator + "xslt" + portNumber + ".xsl"); + ErrorListener listener = null; + try { + System.gc(); + Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(fisXslt)); + listener = transformer.getErrorListener(); + transformer.transform(new StreamSource(fisXml), new StreamResult(fos)); + } catch (Exception ex) { + PrintWriter pw = new PrintWriter(fos); + pw.write("Error during Transform. " + listener.toString()); + ex.printStackTrace(pw); + } finally { + fos.close(); + fisXml.delete(); + fisXslt.delete(); + } + System.gc(); + + InputStream fis = new FileInputStream(file); + try { + sendStream(clientSocket, fis, outputToNetwork); + Thread.sleep(1000); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + fis.close(); + file.delete(); + } + } + + private void clearResources() throws Exception { + if (outputToNetwork != null) { + outputToNetwork.close(); + } + if (inputFromNetwork != null) { + inputFromNetwork.close(); + } + if (clientSocket != null) { + clientSocket.close(); + } + if (server != null) { + server.close(); + } + } + + static public void sendStream(Socket socket, InputStream in, OutputStream out) throws Exception { + socket.setSoTimeout(TIMEOUT); + try { + int numberOfBytes = 0; + byte[] buffer = new byte[MAX_PACKET_SIZE]; + while ((numberOfBytes = in.read(buffer, 0, buffer.length)) != -1) { + out.write(buffer, 0, numberOfBytes); + } + out.write(FINISH_PROCESSING_FLAG); + out.flush(); + } catch (Exception ex) { + throw new Exception("Error during send.", ex); + } + } + + static public void receiveStream(Socket socket, InputStream in, OutputStream out) throws Exception { + socket.setSoTimeout(TIMEOUT); + try { + int numberOfBytes = 0; + byte[] buffer = new byte[MAX_PACKET_SIZE]; + while ((numberOfBytes = in.read(buffer, 0, buffer.length)) != -1) { + if (buffer[numberOfBytes - 1] == -1) { + out.write(buffer, 0, numberOfBytes - 1); + break; + } + out.write(buffer, 0, numberOfBytes); + } + out.flush(); + } catch (Exception ex) { + throw new Exception("Error during receive.", ex); + } + } + + static public void receiveStream(Socket socket, InputStream in, Writer out) throws Exception { + socket.setSoTimeout(TIMEOUT); + try { + int numberOfBytes = 0; + byte[] buffer = new byte[MAX_PACKET_SIZE]; + while ((numberOfBytes = in.read(buffer, 0, buffer.length)) != -1) { + if (buffer[numberOfBytes - 1] == -1) { + out.write(new String(buffer, 0, numberOfBytes - 1)); + break; + } + out.write(new String(buffer, 0, numberOfBytes)); + } + out.flush(); + } catch (Exception ex) { + throw new Exception("Error during receive.", ex); + } + } + + public static void main(String args[]) { + XmlTransformServer xmlTransformServer = new XmlTransformServer(); + try { + int port = Integer.parseInt(args[0]); + xmlTransformServer.initializeServer(port); + xmlTransformServer.process(); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + try { + xmlTransformServer.clearResources(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/XmlTranslation.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/XmlTranslation.java new file mode 100644 index 00000000000..c6bc2b14f3c --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/XmlTranslation.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.xml; + +import java.io.CharArrayReader; +import java.io.CharArrayWriter; +import java.nio.CharBuffer; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Templates; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.URIResolver; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +/** + * @author Ryan D. Brooks + */ +public class XmlTranslation { + /** + * applies the xslFilename to inFilename and writes the output to outFilename. + */ + public static CharBuffer applyXsl(CharBuffer xmlBuffer, CharBuffer xslBuffer, URIResolver uriResolver) { + return applyXsl(new StreamSource(new CharArrayReader(xmlBuffer.array())), xslBuffer, uriResolver); + } + + /** + * applies the xslFilename to inFilename and writes the output to outFilename. + */ + public static CharBuffer applyXsl(Source source, CharBuffer xslBuffer, URIResolver uriResolver) { + try { + TransformerFactory factory = TransformerFactory.newInstance(); + factory.setURIResolver(uriResolver); + + Templates template = factory.newTemplates(new StreamSource(new CharArrayReader(xslBuffer.array()))); + Transformer xformer = template.newTransformer(); + + CharArrayWriter resultWriter = new CharArrayWriter(10000); + Result result = new StreamResult(resultWriter); + + xformer.transform(source, result); + return CharBuffer.wrap(resultWriter.toCharArray()); + } catch (TransformerConfigurationException ex) { + ex.printStackTrace(); + } catch (TransformerException ex) { + ex.printStackTrace(); + } + return null; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/XmlUtility.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/XmlUtility.java new file mode 100644 index 00000000000..e999e3f6a4f --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/XmlUtility.java @@ -0,0 +1,81 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.util.xml;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathFactory;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @author Paul K. Waldfogel
+ */
+public class XmlUtility {
+ public final static XPathFactory myXPathFactory = XPathFactory.newInstance();
+ public final static XPath myXPath = myXPathFactory.newXPath();
+ public final static String wordLeader1 =
+ "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" + "<?mso-application progid='Word.Document'?>";
+ public final static String wordLeader2 =
+ "<w:wordDocument xmlns:w='http://schemas.microsoft.com/office/word/2003/wordml' xmlns:v='urn:schemas-microsoft-com:vml' xmlns:w10='urn:schemas-microsoft-com:office:word' xmlns:sl='http://schemas.microsoft.com/schemaLibrary/2003/core' xmlns:aml='http://schemas.microsoft.com/aml/2001/core' xmlns:wx='http://schemas.microsoft.com/office/word/2003/auxHint' xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882' xmlns:wsp='http://schemas.microsoft.com/office/word/2003/wordml/sp2' xmlns:ns0='http://www.w3.org/2001/XMLSchema' xmlns:ns1='http://eclipse.org/artifact.xsd' xmlns:st1='urn:schemas-microsoft-com:office:smarttags' w:macrosPresent='no' w:embeddedObjPresent='no' w:ocxPresent='no' xml:space='preserve'>";
+ public final static String wordLeader = wordLeader1.concat(wordLeader2);
+ public final static String wordBody = "<w:body></w:body>";
+ public final static String wordTrailer = "</w:wordDocument> ";
+
+ public static String treatNonUTF8Characters(String contentString) {
+ String resultString = contentString;
+ String[][] nonUTF8CharactersOfInterest = { {"–", "-"}, {"’", "'"}, {"’", "'"}, {"“", "\""}, {"”", "\""}};//Wider than usual dash , smaller than usual bullet
+ for (int i = 0; i < nonUTF8CharactersOfInterest.length; i++) {
+ String[] splitsOfNonUTF8 = resultString.split(nonUTF8CharactersOfInterest[i][0]);//Wider than usual dash or bullet
+ if (splitsOfNonUTF8.length > 1) {
+ StringBuffer myStringBuffer = new StringBuffer();
+ for (int j = 0; j < splitsOfNonUTF8.length; j++) {
+ myStringBuffer.append(splitsOfNonUTF8[j]);
+ if (splitsOfNonUTF8[j].length() > 0 && j < splitsOfNonUTF8.length - 1) {
+ myStringBuffer.append(nonUTF8CharactersOfInterest[i][1]);
+ }
+ }
+ resultString = myStringBuffer.toString();
+ }
+ }
+ String[] splits = resultString.split("[^\\p{Space}\\p{Graph}]");
+ int stringPosition = 0;
+ if (splits.length > 1) {
+ StringBuffer myStringBuffer = new StringBuffer();
+ for (int i = 0; i < splits.length; i++) {
+ stringPosition = stringPosition + splits[i].length();
+ myStringBuffer.append(splits[i]);
+ stringPosition = stringPosition + 1;
+ if (splits[i].length() > 0 && i < splits.length - 1) {
+ myStringBuffer.append("-");
+ }
+ }
+ resultString = myStringBuffer.toString();
+ }
+
+ return resultString;
+ }
+
+ public static final Element appendNewElementWithTextCData(Node parentElementName, String newElementTagName, String newText) {
+ Element newElement = null;
+ try {
+ newElement = parentElementName.getOwnerDocument().createElement(newElementTagName);
+ parentElementName.appendChild(newElement);
+ if (newText != null) {
+ Node newTextNode = parentElementName.getOwnerDocument().createCDATASection(newText);
+ newElement.appendChild(newTextNode);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ ;
+ return newElement;
+ }
+}
\ No newline at end of file diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/Cell.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/Cell.java new file mode 100644 index 00000000000..b14f7c953fa --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/Cell.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.xml.excel; + +import org.eclipse.osee.framework.jdk.core.persistence.Xmlizable; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * @author Ryan D. Brooks + */ +public class Cell implements Xmlizable { + + public Element toXml(Document doc) { + return null; + } + + public void initializeFromXml(Document doc) { + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/Row.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/Row.java new file mode 100644 index 00000000000..4d7110bb656 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/Row.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.xml.excel; + +import org.eclipse.osee.framework.jdk.core.persistence.Xmlizable; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * @author Ryan D. Brooks + */ +public class Row implements Xmlizable { + + public Element toXml(Document doc) { + return null; + } + + public void initializeFromXml(Document doc) { + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/Style.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/Style.java new file mode 100644 index 00000000000..3a305bd5346 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/Style.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.xml.excel; + +import org.eclipse.osee.framework.jdk.core.persistence.Xmlizable; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * @author Ryan D. Brooks + */ +public class Style implements Xmlizable { + + public Element toXml(Document doc) { + return null; + } + + public void initializeFromXml(Document doc) { + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/Table.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/Table.java new file mode 100644 index 00000000000..818fa709607 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/Table.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.xml.excel; + +import org.eclipse.osee.framework.jdk.core.persistence.Xmlizable; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * @author Ryan D. Brooks + */ +public class Table implements Xmlizable { + + public Element toXml(Document doc) { + return null; + } + + public void initializeFromXml(Document doc) { + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/WorkBook.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/WorkBook.java new file mode 100644 index 00000000000..43b3c650610 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/WorkBook.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.xml.excel; + +import org.eclipse.osee.framework.jdk.core.persistence.Xmlizable; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * @author Ryan D. Brooks + */ +public class WorkBook implements Xmlizable { + + public Element toXml(Document doc) { + return null; + } + + public void initializeFromXml(Document doc) { + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/WorkSheet.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/WorkSheet.java new file mode 100644 index 00000000000..dca1df40aed --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/excel/WorkSheet.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.xml.excel; + +import org.eclipse.osee.framework.jdk.core.persistence.Xmlizable; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * @author Ryan D. Brooks + */ +public class WorkSheet implements Xmlizable { + + public Element toXml(Document doc) { + return null; + } + + public void initializeFromXml(Document doc) { + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/parser/GenericParser.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/parser/GenericParser.java new file mode 100644 index 00000000000..b52093dcd18 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/parser/GenericParser.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.xml.parser; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashSet; +import java.util.Set; +import org.eclipse.osee.framework.jdk.core.collection.tree.Tree; +import org.eclipse.osee.framework.jdk.core.collection.tree.TreeNode; +import org.eclipse.osee.framework.jdk.core.util.io.xml.AbstractSaxHandler; +import org.xml.sax.Attributes; +import org.xml.sax.ErrorHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLReaderFactory; + +/** + * @author Roberto E. Escobar + */ +public class GenericParser extends AbstractSaxHandler { + + private String toFind; + private boolean startCollecting; + private Tree<XmlNode> collectedTree; + private TreeNode<XmlNode> currentNode; + private Set<IXmlNodeListener> listeners; + private Set<IProcessingInstructionsListener> instructionListeners; + + public GenericParser(String startTag) { + this.toFind = startTag; + this.listeners = new HashSet<IXmlNodeListener>(); + this.instructionListeners = new HashSet<IProcessingInstructionsListener>(); + } + + public void reset() { + this.startCollecting = false; + this.currentNode = null; + this.collectedTree = null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.osee.framework.jdk.core.util.io.xml.AbstractSaxHandler#startElementFound(java.lang.String, + * java.lang.String, java.lang.String, org.xml.sax.Attributes) + */ + @Override + public void startElementFound(String uri, String localName, String qName, Attributes attributes) throws SAXException { + if (localName.equalsIgnoreCase(toFind)) { + startCollecting = true; + collectedTree = new Tree<XmlNode>(new XmlNode(localName, attributes)); + currentNode = null; + } + + if (startCollecting) { + XmlNode node = new XmlNode(localName, attributes); + if (currentNode == null) { + currentNode = collectedTree.getRoot(); + } else { + currentNode = currentNode.addChild(node); + } + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.osee.framework.jdk.core.util.io.xml.AbstractSaxHandler#endElementFound(java.lang.String, + * java.lang.String, java.lang.String) + */ + @Override + public void endElementFound(String uri, String localName, String qName) throws SAXException { + if (localName.equalsIgnoreCase(toFind)) { + startCollecting = false; + notifyTreeCollected(collectedTree); + } + + if (startCollecting) { + if (currentNode != null) { + currentNode.getSelf().setTextContent(getContents()); + if (currentNode.getSelf().getName().equalsIgnoreCase(localName)) { + // Found End of current Node Stop appending Children + TreeNode<XmlNode> parent = currentNode.getParent(); + currentNode = parent; + } + } + } + } + + public void processingInstruction(String target, String data) throws SAXException { + super.processingInstruction(target, data); + notifyProcessingInstructionChanged(target, data); + } + + synchronized public void registerInstructionListener(IProcessingInstructionsListener listener) { + if (!instructionListeners.contains(listener)) { + instructionListeners.add(listener); + } + } + + synchronized public void deregisterInstructionListener(IProcessingInstructionsListener listener) { + if (instructionListeners.contains(listener)) { + instructionListeners.remove(listener); + } + } + + synchronized public void registerXmlNodeListener(IXmlNodeListener listener) { + if (!listeners.contains(listener)) { + listeners.add(listener); + } + } + + synchronized public void deregisterXmlNodeListener(IXmlNodeListener listener) { + if (listeners.contains(listener)) { + listeners.remove(listener); + } + } + + synchronized public void notifyTreeCollected(final Tree<XmlNode> tree) { + TreeNode<XmlNode> root = tree.getRoot(); + for (IXmlNodeListener listener : listeners) { + listener.collectionChanged(root); + } + } + + synchronized public void notifyProcessingInstructionChanged(String target, String data) { + for (IProcessingInstructionsListener listener : instructionListeners) { + listener.processingInstructionChanged(target, data); + } + } + + public void process(File xmlSource) throws SAXException, IOException { + this.reset(); + process(new FileInputStream(xmlSource)); + } + + public void process(InputStream xmlSource) throws SAXException, IOException { + this.reset(); + XMLReader xmlReader; + xmlReader = XMLReaderFactory.createXMLReader(); + xmlReader.setContentHandler(this); + xmlReader.setErrorHandler(new ErrorHandler() { + + public void warning(SAXParseException exception) throws SAXException { + exception.printStackTrace(); + } + + public void fatalError(SAXParseException exception) throws SAXException { + exception.printStackTrace(); + } + + public void error(SAXParseException exception) throws SAXException { + exception.printStackTrace(); + } + + }); + xmlReader.parse(new InputSource(xmlSource)); + System.out.println(); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/parser/IProcessingInstructionsListener.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/parser/IProcessingInstructionsListener.java new file mode 100644 index 00000000000..5ebb0297c16 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/parser/IProcessingInstructionsListener.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.xml.parser; + +/** + * @author Roberto E. Escobar + */ +public interface IProcessingInstructionsListener { + + public void processingInstructionChanged(String target, String data); +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/parser/IXmlNodeListener.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/parser/IXmlNodeListener.java new file mode 100644 index 00000000000..054c77c9fdf --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/parser/IXmlNodeListener.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.xml.parser; + +import org.eclipse.osee.framework.jdk.core.collection.tree.TreeNode; + +/** + * @author Roberto E. Escobar + */ +public interface IXmlNodeListener { + + public void collectionChanged(TreeNode<XmlNode> collected); +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/parser/XmlNode.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/parser/XmlNode.java new file mode 100644 index 00000000000..6a3c79e9f84 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/parser/XmlNode.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.xml.parser; + +import java.util.HashMap; +import java.util.Map; +import org.xml.sax.Attributes; + +/** + * @author Roberto E. Escobar + */ +public class XmlNode { + + private String name; + private String textContent; + private Map<String, String> attributes; + + public XmlNode(String name, Attributes attributes) { + this.name = name; + this.attributes = new HashMap<String, String>(attributes.getLength()); + for (int i = 0; i < attributes.getLength(); i++) + this.attributes.put(attributes.getQName(i), attributes.getValue(i)); + this.textContent = ""; + } + + /** + * @return Returns the textContent. + */ + public String getTextContent() { + return textContent; + } + + /** + * @param textContent The textContent to set. + */ + public void setTextContent(String textContent) { + if (textContent != null && textContent.length() > 0) { + this.textContent = textContent; + } + } + + /** + * @param qname + * @return Returns the value of the attribute matching the qualified name. + */ + public String getAttributeValue(String qname) { + return attributes.get(qname); + } + + /** + * @return Returns the name. + */ + public String getName() { + return name; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/parser/XmlTreeUtilities.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/parser/XmlTreeUtilities.java new file mode 100644 index 00000000000..0ef3310a66a --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/xml/parser/XmlTreeUtilities.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.util.xml.parser; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; +import org.eclipse.osee.framework.jdk.core.collection.tree.TreeNode; + +/** + * @author Roberto E. Escobar + */ +public class XmlTreeUtilities { + + private static XmlTreeUtilities instance = null; + + private XmlTreeUtilities() { + } + + public static XmlTreeUtilities getInstance() { + if (instance == null) { + instance = new XmlTreeUtilities(); + } + return instance; + } + + private Stack<String> processPath(String pattern) { + Stack<String> elementPath = new Stack<String>(); + String[] path = pattern.split("/"); + for (int index = path.length - 1; index >= 0; index--) { + String entry = path[index]; + entry = entry.trim(); + if (entry.length() > 0) { + elementPath.push(entry); + } + } + return elementPath; + } + + public List<TreeNode<XmlNode>> getXmlNodesAt(String path, TreeNode<XmlNode> root) { + Stack<String> elementPath = processPath(path); + List<TreeNode<XmlNode>> toReturn = new ArrayList<TreeNode<XmlNode>>(); + List<TreeNode<XmlNode>> nodes = root.getChildren(); + while (!elementPath.empty()) { + String token = elementPath.pop(); + nodes = collectNodesMatchingToken(token, nodes); + } + if (nodes != null && nodes.size() > 0) { + toReturn.addAll(nodes); + } + + return toReturn; + } + + private List<TreeNode<XmlNode>> collectNodesMatchingToken(String token, List<TreeNode<XmlNode>> nodes) { + List<TreeNode<XmlNode>> toReturn = new ArrayList<TreeNode<XmlNode>>(); + + for (TreeNode<XmlNode> node : nodes) { + if (token.equalsIgnoreCase("*")) { + if (node.getChildren().size() > 0) { + toReturn.addAll(node.getChildren()); + } + } + if (node.getSelf().getName().equalsIgnoreCase(token)) { + toReturn.add(node); + if (node.getChildren().size() > 0) { + toReturn.addAll(node.getChildren()); + } + } + } + return toReturn; + } + + public int countNodesMatchingText(List<TreeNode<XmlNode>> nodes, String toMatch) { + int result = 0; + for (TreeNode<XmlNode> node : nodes) { + if (node != null) { + String content = node.getSelf().getTextContent(); + if (content.equalsIgnoreCase(toMatch)) { + result++; + } + } + } + return result; + } + + public XmlNode getFirstXmlNode(List<TreeNode<XmlNode>> nodes) { + XmlNode toReturn = null; + if (nodes.size() > 0) { + toReturn = nodes.get(0).getSelf(); + } + return toReturn; + } + + public String getFirstXmlNodeText(List<TreeNode<XmlNode>> nodes) { + XmlNode node = getFirstXmlNode(nodes); + return node != null ? node.getTextContent() : ""; + } + + public boolean containsNode(String path, TreeNode<XmlNode> nodes) { + List<TreeNode<XmlNode>> searchResults = getXmlNodesAt("Location", nodes); + return searchResults.size() > 0; + } + + public String getTextAtPath(String path, TreeNode<XmlNode> nodes) { + return getFirstXmlNodeText(getXmlNodesAt(path, nodes)); + } + + public XmlNode getXmlNodeAtPath(String path, TreeNode<XmlNode> nodes) { + return getFirstXmlNode(getXmlNodesAt(path, nodes)); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/ExpressionValidator.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/ExpressionValidator.java new file mode 100644 index 00000000000..e528b18c61d --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/ExpressionValidator.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.validate; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ExpressionValidator extends FieldValidator { + + public ExpressionValidator(String fieldName) { + super(fieldName); + } + + public boolean isValid() { + Object object = this.paramMap.get(fieldName); + if (object instanceof String) { + String toValidate = (String) object; + + Object expression = this.paramMap.get("expression"); + if (expression instanceof String) { + String expressionString = (String) expression; + if (expressionString.contains("matches")) { + expressionString = expressionString.replaceAll("\\s*matches\\('", ""); + expressionString = expressionString.replaceAll("\\'\\)\\s*", ""); + return matcher(toValidate, expressionString); + //return true; + } + } + } + return false; + } + + private boolean matcher(String toValidate, String regularExpression) { + Pattern pattern = Pattern.compile(regularExpression); + Matcher matcher = pattern.matcher(toValidate); + return matcher.matches(); + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/FieldValidator.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/FieldValidator.java new file mode 100644 index 00000000000..70f0a1f988d --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/FieldValidator.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.validate; + +import java.util.HashMap; +import java.util.Map; + +public abstract class FieldValidator implements IValidator { + + protected String fieldName; + private String message; + protected Map<String, Object> paramMap; + + FieldValidator(String fieldName) { + this.fieldName = fieldName; + this.message = ""; + this.paramMap = new HashMap<String, Object>(); + } + + public String getFieldName() { + return fieldName; + } + + public String getMessage() { + for (String key : paramMap.keySet()) { + message = message.replaceAll("\\$\\{" + key + "\\}", paramMap.get(key).toString()); + } + return message; + } + + void setMessage(String message) { + this.message = message; + } + + public void setItemToValidate(Object object) { + this.paramMap.put(fieldName, object); + } + + void addParam(String paramName, Object value) { + this.paramMap.put(paramName, value); + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/IValidator.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/IValidator.java new file mode 100644 index 00000000000..840961970eb --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/IValidator.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.validate; + +public interface IValidator { + + public String getFieldName(); + + public String getMessage(); + + public void setItemToValidate(Object object); + + public boolean isValid(); +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/RequiredStringValidator.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/RequiredStringValidator.java new file mode 100644 index 00000000000..4c33a052e41 --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/RequiredStringValidator.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.validate; + +public class RequiredStringValidator extends FieldValidator { + + public RequiredStringValidator(String fieldName) { + super(fieldName); + } + + public boolean isValid() { + Object object = paramMap.get(fieldName); + if (object != null && object instanceof String) { + String value = (String) object; + return (value != null && !value.equals("")); + } + return false; + } +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/RequiredValidator.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/RequiredValidator.java new file mode 100644 index 00000000000..7370c844edc --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/RequiredValidator.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.validate; + +public class RequiredValidator extends FieldValidator { + + public RequiredValidator(String fieldName) { + super(fieldName); + } + + public boolean isValid() { + return false; + } + +} diff --git a/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/Validator.java b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/Validator.java new file mode 100644 index 00000000000..492edbdf78c --- /dev/null +++ b/MS_0.6.0_20090114/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/validate/Validator.java @@ -0,0 +1,159 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.jdk.core.validate; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class Validator { + + private InputStream fileToRead; + private Map<String, List<IValidator>> validatorMap; + + private enum EntryEnum { + field; + } + + private enum FieldAttributes { + name; + } + + private enum FieldEntries { + validator; + } + + private enum FieldValidatorAttributes { + type; + } + + private enum FieldValidatorEntries { + message, param; + } + + private enum ParamAttributes { + name; + } + + private enum ValidationTypes { + requiredstring, required, expression; + } + + public Validator(InputStream fileToRead) throws Exception { + this.fileToRead = fileToRead; + this.validatorMap = new HashMap<String, List<IValidator>>(); + parseFile(); + } + + private void storeValidator(String fieldName, IValidator validator) { + List<IValidator> list = null; + if (!validatorMap.containsKey(fieldName)) { + list = new ArrayList<IValidator>(); + validatorMap.put(fieldName, list); + } else { + list = validatorMap.get(fieldName); + } + list.add(validator); + } + + private void parseMessage(Element element, FieldValidator validator) { + NodeList messageList = element.getElementsByTagName(FieldValidatorEntries.message.name()); + if (messageList.getLength() == 1) { + Node node = messageList.item(0); + if (node != null) { + String message = node.getTextContent(); + if (message != null && !message.equals("")) { + validator.setMessage(message.trim()); + } + } + } + } + + private void parseParams(Element element, FieldValidator validator) { + NodeList paramList = element.getElementsByTagName(FieldValidatorEntries.param.name()); + for (int i = 0; i < paramList.getLength(); i++) { + Element paramElement = (Element) paramList.item(i); + String paramName = paramElement.getAttribute(ParamAttributes.name.name()); + if (paramName != null && !paramName.equals("")) { + String content = paramElement.getTextContent(); + if (content != null && !content.equals("")) { + validator.addParam(paramName.trim(), content.trim()); + } + } + } + } + + private void parseValidator(Element element, String fieldName, String validatorType) { + FieldValidator validator = validatorFactory(fieldName, validatorType); + if (validator != null) { + parseMessage(element, validator); + parseParams(element, validator); + storeValidator(fieldName, validator); + } + } + + private void parseFile() throws Exception { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.parse(fileToRead); + + NodeList fields = document.getElementsByTagName(EntryEnum.field.name()); + + for (int i = 0; i < fields.getLength(); i++) { + + Element fieldElement = (Element) fields.item(i); + String fieldName = fieldElement.getAttribute(FieldAttributes.name.name()); + if (fieldName != null && !fieldName.equals("")) { + + NodeList validators = fieldElement.getElementsByTagName(FieldEntries.validator.name()); + for (int j = 0; j < validators.getLength(); j++) { + Element validatorElement = (Element) validators.item(j); + + String validatorType = validatorElement.getAttribute(FieldValidatorAttributes.type.name()); + if (validatorType != null && !validatorType.equals("")) { + parseValidator(validatorElement, fieldName.trim(), validatorType.trim()); + } + } + } + } + } + + private FieldValidator validatorFactory(String name, String type) { + FieldValidator toReturn = null; + ValidationTypes validationType = ValidationTypes.valueOf(type); + switch (validationType) { + case requiredstring: + toReturn = new RequiredStringValidator(name); + break; + case required: + toReturn = new RequiredValidator(name); + break; + case expression: + toReturn = new ExpressionValidator(name); + default: + break; + } + return toReturn; + } + + public List<IValidator> getValidator(String fieldName) { + List<IValidator> list = validatorMap.get(fieldName); + return (list != null ? list : new ArrayList<IValidator>()); + } +} |