wt.ixb.handlers.netmarkets
Class ProjectIXUtils

java.lang.Object
  extended bywt.ixb.handlers.netmarkets.ProjectIXUtils

public class ProjectIXUtils
extends Object


Field Summary
private static String _rb
           
private static int[] DEF_FROM_INDEXES
           
private static Object[] DEF_PARAMS
           
private static String DEFAULT_ENCODING
           
private static String DEFAULT_LIFECYCLE
           
static String DOMAIN_ID
           
private static Map domainPaths
           
private static Object[] EMPTY_ARRAY
           
private static NMProjectConstants.EngineRuleInfo engineTags
           
private static Class ENUM_TYPE_CLASS
           
private static String EPM_NAVIGATOR
           
private static String HEADER_ENCODING
           
private static NMProjectConstants.ProjectMemberInfo memberTags
           
private static Class OBJ_REF_CLASS
           
private static NMProjectConstants.ObjectIDInfo oidInfoTags
           
private static String PJL_NULL
           
private static PrepMapFile pmf
           
private static String PROJ_MGMT_KEY
           
(package private) static String USER_KEY
           
private static boolean VERBOSE
           
private static Class WT_OBJECT_CLASS
           
 
Constructor Summary
ProjectIXUtils()
           
 
Method Summary
static void addRoleElem(IxbElement elem, Role role)
          Adds a role element to the passed element.
static boolean checkBufferSanity(StringBuffer strBuff)
           
static PushbackInputStream checkStreamSanity(InputStream in)
          This method performs a sanity check on an input stream.
static void checkTag(IxbElement elem, String expected_tag)
          
static void checkTags(IxbElement elem, String[] possibletags)
           
private static DirectoryContextProvider[] computeContexts(WTContainerRef contRef)
           
static StringBuffer convertCsv2XML(StringBuffer buffer)
          Converts the passed in stringbuffer which had better correspond to a CSV stream into a stringbuffer to the corresponding XML.
static void copyStream(InputStream in, OutputStream out)
          Copies an input stream to an output stream.
static File exportDocumentToJarFile(WTContainerRef contRef, WTDocument document, File tmpFile)
           
static File exportFolderStructureToJarFile(WTContainerRef contRef, Folder folder, File tmpFile)
           
static File exportProductStructureToJarFile(WTContainerRef contRef, List parts, File tmpFile)
           
static File exportProjectToJarFile(WTContainerRef contRef, Project2 project, File tmpFile)
           
static void exportReference(Persistable pers_obj, IxbElement elem, Exporter exporter)
          
static File exportToJarFile(WTContainerRef contRef, Persistable persistObj, File tmpFile)
           
static void exportWTDocument(WTDocument doc, IxbElement elem, Exporter exporter)
          Exports a document into the given IxbElement.
static void exportWTPart(WTPart part, IxbElement elem, Exporter exporter)
           
static IxbDocument generateExportMappingRules()
           
static IxbDocument generateFolderMappingRules(Folder theFolder)
          This generates mapping rules for the savePath.
static IxbDocument generateImportMappingRules()
           
private static IxbDocument generateImportMappingRules(NotebookFolder notebook_folder)
           
static AdminDomainRef getAdminDomainRefFromRelativePath(WTContainerRef contRef, String relativePath)
           
static ConfigSpec getConfigSpecForSandbox(WTContainerRef contRef)
           
private static WTGroup getContainerGroup(ContainerTeamManaged ctm, String groupKey, String princName)
           
static QueryResult getDocuments(WTContainerRef cont_ref)
          Returns documents contained in project.
static String getEncoding(File xmlFile)
          Get the character encoding that is specified in the XML file.
static String getEncoding(String xmlText)
          Get the character encoding that is specified in the XML text.
private static String getEncodingFromHeader(String header)
          Get the character encoding that is specified in the given XML header.
static QueryResult getEPMDocuments(WTContainerRef cont_ref)
          Returns epm documents contained in project.
private static String getFolderPath(NotebookFolder folder)
           
static String getFullyQualifiedDomainPath(WTContainerRef contRef, String relativePath)
           
static WTGroup getGroupByName(WTContainerRef contRef, String princName)
           
private static String getHeader(File file)
          Get the
private static String getHeader(InputStream is)
          Get the
private static String getHeader(String content)
          Get the
private  ObjectIdentifier getId(Object obj)
           
private static String getIdStr(Object obj)
           
static Iterated getIteratedObject(WTContainerRef contRef, Class theClass, String attrName, String attrValue)
           
static QueryResult getObjects(WTContainerRef cont_ref, Class object_class)
          Returns objects of a given class contained in project.
static Object getObjFromObjectIDElement(IxbElement objId, Importer imp)
          ObjectIds may come in two flavors.
static Object getObjFromObjRefElem(IxbElement objRef, Importer imp)
          ObjectReferences can come in three flavors localId, ufid, and custom.
private static ObjectIdentifier getOid(Object obj)
           
static QueryResult getParts(WTContainerRef cont_ref)
          Returns parts contained in project.
static WTPrincipal getPrincipalByDN(String dnName)
           
static WTPrincipal getPrincipalByName(WTContainerRef contRef, String princName)
           
static Set getProductStructSet(WTContainerRef cont_ref)
           
static Project2 getProject(String project_name)
           
static Reader getReader(File xmlFile)
          Get a Reader on the contents of the specified File.
static ObjectReference getReference(String ref_str, Importer imp)
           
static Role getRole(IxbElement role_elem)
          Returns a role given an IxbElement corresponding to the Role tag.
static WTUser getUserByDN(String dnName)
           
static EmailUser getUserFromMembershipTag(IxbElement elem, WTContainerRef contRef)
           
static boolean hasTag(IxbElement elem, String expected_tag)
           
static boolean importFromJarFile(Object obj, String file_name)
           
static boolean importFromJarFile(WTContainerRef contRef, Object obj, String file_name)
           
static boolean importFromJarFileToContainer(WTContainerRef target, File tmpFile)
           
static boolean importFromJarFileToFolder(Folder folder, File tmpFile)
           
static boolean importFromJarFileToNotebook(NotebookFolder notebook_folder, File tmpFile)
           
static boolean importFromJarFileToProject(WTContainerRef target, File tmpFile)
           
static boolean isRootDomain(AdministrativeDomain domain, WTContainer container)
           
private static List populateContextProviders(WTContainerRef contRef, List contextList)
           
static Rule populateEngineBaseInfo(IxbElement elem, String ruleType, Importer imp)
          This method initializes all the base rule information except the enabled status.
static void postExportFeedback(String rb, String key)
           
static void postExportFeedback(String rb, String key, Object[] params)
           
static void postFeedback(Importer imp, String rb, String key, Object[] params, int level)
          Posts message to the logger.
private static boolean processBooleanStr(String str)
           
static Rule setRuleEnabledStatus(Rule rule, IxbElement elem)
          Set the enabled status of the rule to the specified value.
static void setTmpId(IxbElement elem, Importer imp)
          Takes an ObjectId object and if the object id is a localId, we store the tmpId.
static String showObjs(Collection objs)
           
private static void updateFolderPathRules(IxbElement rootElem, String path, String value, String newValue)
           
private static void updateLifecyclePathRules(IxbElement rootElement)
           
static boolean validateXMLInputStream(InputStream in)
          This method does some simple validation on the input stream to verify that its contents do in fact contain an XML file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERBOSE

private static final boolean VERBOSE
See Also:
Constant Field Values

EPM_NAVIGATOR

private static final String EPM_NAVIGATOR
See Also:
Constant Field Values

USER_KEY

static final String USER_KEY
See Also:
Constant Field Values

_rb

private static final String _rb
See Also:
Constant Field Values

PJL_NULL

private static final String PJL_NULL
See Also:
Constant Field Values

PROJ_MGMT_KEY

private static final String PROJ_MGMT_KEY

DEFAULT_LIFECYCLE

private static final String DEFAULT_LIFECYCLE

DEF_PARAMS

private static final Object[] DEF_PARAMS

ENUM_TYPE_CLASS

private static final Class ENUM_TYPE_CLASS

OBJ_REF_CLASS

private static final Class OBJ_REF_CLASS

WT_OBJECT_CLASS

private static final Class WT_OBJECT_CLASS

DEFAULT_ENCODING

private static final String DEFAULT_ENCODING

HEADER_ENCODING

private static final String HEADER_ENCODING

oidInfoTags

private static final NMProjectConstants.ObjectIDInfo oidInfoTags

memberTags

private static final NMProjectConstants.ProjectMemberInfo memberTags

engineTags

private static final NMProjectConstants.EngineRuleInfo engineTags

pmf

private static final PrepMapFile pmf

DOMAIN_ID

public static final String DOMAIN_ID

domainPaths

private static Map domainPaths

DEF_FROM_INDEXES

private static final int[] DEF_FROM_INDEXES

EMPTY_ARRAY

private static final Object[] EMPTY_ARRAY
Constructor Detail

ProjectIXUtils

public ProjectIXUtils()
Method Detail

exportReference

public static void exportReference(Persistable pers_obj,
                                   IxbElement elem,
                                   Exporter exporter)
                            throws WTException
 
 
This implementation is limited to the localId option.

Throws:
WTException

checkTag

public static void checkTag(IxbElement elem,
                            String expected_tag)
                     throws WTException

Throws:
WTException

checkTags

public static void checkTags(IxbElement elem,
                             String[] possibletags)
                      throws WTException
Throws:
WTException

hasTag

public static boolean hasTag(IxbElement elem,
                             String expected_tag)
                      throws WTException
Throws:
WTException

getReference

public static ObjectReference getReference(String ref_str,
                                           Importer imp)
                                    throws WTException
Throws:
WTException

getObjFromObjectIDElement

public static Object getObjFromObjectIDElement(IxbElement objId,
                                               Importer imp)
                                        throws WTException
ObjectIds may come in two flavors. One with a local identifier such as PROJECT_1, and the other would be an explicit object identifer as one would get from the export of a non-federatable object. This looks like wt.part.WTPart:3432. This function unifies the logic of checking which type of object to get.

Throws:
WTException - if the tag is not an ObjectID tag.

getObjFromObjRefElem

public static Object getObjFromObjRefElem(IxbElement objRef,
                                          Importer imp)
                                   throws WTException
ObjectReferences can come in three flavors localId, ufid, and custom. This method only assumes localId since custom is for a very specific scenario, and ufid is handled elsewhere.

Throws:
WTException

setTmpId

public static void setTmpId(IxbElement elem,
                            Importer imp)
                     throws WTException
Takes an ObjectId object and if the object id is a localId, we store the tmpId. This is only relevent for interfacing with WTDocument and WTPart in netmarkets scenarios

Throws:
WTException

populateEngineBaseInfo

public static Rule populateEngineBaseInfo(IxbElement elem,
                                          String ruleType,
                                          Importer imp)
                                   throws WTException
This method initializes all the base rule information except the enabled status.

Throws:
WTException
See Also:
setRuleEnabledStatus

setRuleEnabledStatus

public static final Rule setRuleEnabledStatus(Rule rule,
                                              IxbElement elem)
                                       throws WTException
Set the enabled status of the rule to the specified value. Setting the enabled status causes the rule to be persisted (if it is a PersistentRule).

Parameters:
rule - the rule whose enabled status should be set
elem - the element containing the enabled status info
Returns:
a persisted rule with the specified enabled status
Throws:
WTException

validateXMLInputStream

public static boolean validateXMLInputStream(InputStream in)
                                      throws WTException
This method does some simple validation on the input stream to verify that its contents do in fact contain an XML file. It also validates the XML file. It returns true if the file is valid, and returns false otherwise. This method should only be used in development scenarios since it does more extra checks than the default parser code. This method will throw a WTException with a diagnostic method on failure. It returns true on success. The InputStream passed to this method cannot be re-used.

Throws:
WTException

checkBufferSanity

public static boolean checkBufferSanity(StringBuffer strBuff)
                                 throws WTException
Throws:
WTException

checkStreamSanity

public static PushbackInputStream checkStreamSanity(InputStream in)
                                             throws WTException
This method performs a sanity check on an input stream. It does so by chaining the InputStream to a PushbackInputStream. A minimal sanity check is performed on the xml file. (Check for null, nothing but whitespacr, and that it begins with the string Since actual version numbers may change in the future we do not check for 1.0 The returned input stream is ready to be passed into the parser.

Throws:
WTException

exportToJarFile

public static File exportToJarFile(WTContainerRef contRef,
                                   Persistable persistObj,
                                   File tmpFile)
                            throws WTException
Throws:
WTException

exportDocumentToJarFile

public static File exportDocumentToJarFile(WTContainerRef contRef,
                                           WTDocument document,
                                           File tmpFile)
                                    throws WTException
Throws:
WTException

exportProductStructureToJarFile

public static File exportProductStructureToJarFile(WTContainerRef contRef,
                                                   List parts,
                                                   File tmpFile)
                                            throws WTException
Throws:
WTException

exportFolderStructureToJarFile

public static File exportFolderStructureToJarFile(WTContainerRef contRef,
                                                  Folder folder,
                                                  File tmpFile)
                                           throws WTException
Throws:
WTException

exportProjectToJarFile

public static File exportProjectToJarFile(WTContainerRef contRef,
                                          Project2 project,
                                          File tmpFile)
                                   throws WTException
Throws:
WTException

importFromJarFile

public static boolean importFromJarFile(Object obj,
                                        String file_name)
                                 throws WTException
Throws:
WTException

importFromJarFile

public static boolean importFromJarFile(WTContainerRef contRef,
                                        Object obj,
                                        String file_name)
                                 throws WTException
Throws:
WTException

importFromJarFileToProject

public static boolean importFromJarFileToProject(WTContainerRef target,
                                                 File tmpFile)
                                          throws WTException
Throws:
WTException

importFromJarFileToContainer

public static boolean importFromJarFileToContainer(WTContainerRef target,
                                                   File tmpFile)
                                            throws WTException
Throws:
WTException

importFromJarFileToFolder

public static boolean importFromJarFileToFolder(Folder folder,
                                                File tmpFile)
                                         throws WTException
Throws:
WTException

importFromJarFileToNotebook

public static boolean importFromJarFileToNotebook(NotebookFolder notebook_folder,
                                                  File tmpFile)
                                           throws WTException
Throws:
WTException

generateImportMappingRules

private static IxbDocument generateImportMappingRules(NotebookFolder notebook_folder)
                                               throws WTException
Throws:
WTException

generateFolderMappingRules

public static IxbDocument generateFolderMappingRules(Folder theFolder)
                                              throws WTException
This generates mapping rules for the savePath. What happens is that all folder names will get mapped to the existing folder name. Sample usage scenario. I am importing into folder foo. //Step one create an instance of NMHandler. NMHandler nh = new NMHandler () IxbDocument mapDoc = ProjectIXUtils.generateMappingRules ("/system/docs"); Importer imp = IxbHelper.newImporter (myHandler, IxbHelper.STANDARD_DTD, mapDoc); InputStream is= getInputStreamContaingingXMLFile ( whatever data is needed). imp.doImport (is, validateFlag); imp.finalizeImport (); if null is passed in, the default folder will be used.

Throws:
WTException

generateExportMappingRules

public static IxbDocument generateExportMappingRules()
                                              throws WTException
Throws:
WTException

generateImportMappingRules

public static IxbDocument generateImportMappingRules()
                                              throws WTException
Throws:
WTException

updateLifecyclePathRules

private static final void updateLifecyclePathRules(IxbElement rootElement)
                                            throws WTException
Throws:
WTException

updateFolderPathRules

private static final void updateFolderPathRules(IxbElement rootElem,
                                                String path,
                                                String value,
                                                String newValue)
                                         throws WTException
Throws:
WTException

copyStream

public static void copyStream(InputStream in,
                              OutputStream out)
                       throws WTException
Copies an input stream to an output stream. Caller is responsible for closing after completion.

Throws:
WTException

postFeedback

public static void postFeedback(Importer imp,
                                String rb,
                                String key,
                                Object[] params,
                                int level)
                         throws WTException
Posts message to the logger.

Throws:
WTException

postExportFeedback

public static void postExportFeedback(String rb,
                                      String key)
                               throws WTException
Throws:
WTException

postExportFeedback

public static void postExportFeedback(String rb,
                                      String key,
                                      Object[] params)
                               throws WTException
Throws:
WTException

getDocuments

public static QueryResult getDocuments(WTContainerRef cont_ref)
                                throws WTException
Returns documents contained in project.

Throws:
WTException

getEPMDocuments

public static QueryResult getEPMDocuments(WTContainerRef cont_ref)
                                   throws WTException
Returns epm documents contained in project.

Throws:
WTException

getParts

public static QueryResult getParts(WTContainerRef cont_ref)
                            throws WTException
Returns parts contained in project.

Throws:
WTException

getProductStructSet

public static Set getProductStructSet(WTContainerRef cont_ref)
                               throws WTException
Throws:
WTException

getObjects

public static QueryResult getObjects(WTContainerRef cont_ref,
                                     Class object_class)
                              throws WTException
Returns objects of a given class contained in project.

Throws:
WTException

getProject

public static Project2 getProject(String project_name)
                           throws WTException
Throws:
WTException

getRole

public static Role getRole(IxbElement role_elem)
                    throws WTException
Returns a role given an IxbElement corresponding to the Role tag. Used during import.

Returns:
the Role object for which the role is the name.
Throws:
WTException

addRoleElem

public static void addRoleElem(IxbElement elem,
                               Role role)
                        throws WTException
Adds a role element to the passed element. Used during export.

Throws:
WTException

getReader

public static Reader getReader(File xmlFile)
                        throws IOException
Get a Reader on the contents of the specified File. Make sure the correct character encoding is used when reading the XML file content.

Parameters:
xmlFile - the file containg the XML
Throws:
IOException

getEncoding

public static String getEncoding(String xmlText)
                          throws IOException
Get the character encoding that is specified in the XML text. Return null if no encoding is specified in the file.

Parameters:
xmlText - a string containing well-formed XML text
Returns:
the encoding specified in the XML text or null if no encoding is specified
Throws:
IOException

getEncoding

public static String getEncoding(File xmlFile)
                          throws IOException
Get the character encoding that is specified in the XML file. Return null if no encoding is specified in the file.

Parameters:
xmlFile - a file containing well-formed XML text
Returns:
the encoding specified in the XML text or null if no encoding is specified
Throws:
IOException

getEncodingFromHeader

private static String getEncodingFromHeader(String header)
Get the character encoding that is specified in the given XML header. Return null if no encoding is specified in the declaration.

Returns:
the encoding specified in the XML header or null if no encoding is specified

getHeader

private static String getHeader(String content)
                         throws IOException
Get the
Parameters:
content - a string containing well-formed XML
Throws:
IOException

getHeader

private static String getHeader(File file)
                         throws IOException
Get the
Throws:
IOException

getHeader

private static String getHeader(InputStream is)
                         throws IOException
Get the null if the header is not well-formed or cannot be found.

Throws:
IOException

getFolderPath

private static String getFolderPath(NotebookFolder folder)
                             throws WTException
Throws:
WTException

getId

private ObjectIdentifier getId(Object obj)

processBooleanStr

private static boolean processBooleanStr(String str)

getIteratedObject

public static Iterated getIteratedObject(WTContainerRef contRef,
                                         Class theClass,
                                         String attrName,
                                         String attrValue)
                                  throws WTException
Throws:
WTException

getPrincipalByName

public static WTPrincipal getPrincipalByName(WTContainerRef contRef,
                                             String princName)
                                      throws WTException
Throws:
WTException

computeContexts

private static DirectoryContextProvider[] computeContexts(WTContainerRef contRef)
                                                   throws WTException
Throws:
WTException

populateContextProviders

private static List populateContextProviders(WTContainerRef contRef,
                                             List contextList)
                                      throws WTException
Throws:
WTException

getUserFromMembershipTag

public static EmailUser getUserFromMembershipTag(IxbElement elem,
                                                 WTContainerRef contRef)
                                          throws WTException
Throws:
WTException

getGroupByName

public static WTGroup getGroupByName(WTContainerRef contRef,
                                     String princName)
                              throws WTException
Throws:
WTException

getContainerGroup

private static WTGroup getContainerGroup(ContainerTeamManaged ctm,
                                         String groupKey,
                                         String princName)
                                  throws WTException
Throws:
WTException

convertCsv2XML

public static StringBuffer convertCsv2XML(StringBuffer buffer)
                                   throws WTException
Converts the passed in stringbuffer which had better correspond to a CSV stream into a stringbuffer to the corresponding XML.

Throws:
WTException

getConfigSpecForSandbox

public static ConfigSpec getConfigSpecForSandbox(WTContainerRef contRef)
                                          throws WTException
Throws:
WTException

getFullyQualifiedDomainPath

public static String getFullyQualifiedDomainPath(WTContainerRef contRef,
                                                 String relativePath)
                                          throws WTException
Throws:
WTException

getAdminDomainRefFromRelativePath

public static AdminDomainRef getAdminDomainRefFromRelativePath(WTContainerRef contRef,
                                                               String relativePath)
                                                        throws WTException
Throws:
WTException

isRootDomain

public static boolean isRootDomain(AdministrativeDomain domain,
                                   WTContainer container)
                            throws WTException
Throws:
WTException

getPrincipalByDN

public static WTPrincipal getPrincipalByDN(String dnName)
                                    throws WTException
Throws:
WTException

getUserByDN

public static WTUser getUserByDN(String dnName)
                          throws WTException
Throws:
WTException

getIdStr

private static String getIdStr(Object obj)
                        throws WTException
Throws:
WTException

showObjs

public static String showObjs(Collection objs)
                       throws WTException
Throws:
WTException

exportWTDocument

public static void exportWTDocument(WTDocument doc,
                                    IxbElement elem,
                                    Exporter exporter)
                             throws WTException
Exports a document into the given IxbElement. This method should be in the WT document handler. It is here so not to change the basic framework.

Throws:
WTException

exportWTPart

public static void exportWTPart(WTPart part,
                                IxbElement elem,
                                Exporter exporter)
                         throws WTException
Throws:
WTException

getOid

private static ObjectIdentifier getOid(Object obj)
                                throws WTException
Throws:
WTException