com.ptc.windchill.structconf.xconf
Class UpdateXconf

java.lang.Object
  extended bycom.ptc.windchill.structconf.xconf.UpdateXconf

public class UpdateXconf
extends Object

Tool to add, remove, or update entries in site-specific xconf file. The preferred method of changing Xconf files is to execute StructConfManagerCommands via a StructConfManager. This will ensure semantic integrity of all xconf values for a site.


Field Summary
private  boolean dirty_
           
private  Document document_
           
private  int mode_
           
private  File xconfFile_
           
 
Constructor Summary
UpdateXconf(File file, int mode)
           
UpdateXconf(int mode)
           
 
Method Summary
 void addInclude(String path_to_include)
           
 void addOrUpdate(String property_name, String property_value, File target_file)
          Update the site property to the new value.
 void addOrUpdate(String property_name, String property_value, File target_file, String comment)
          Removes all elements in the document that change the specified property then adds a <Property gt; element to the end of the document body to set the site value to the specified value.
 void addToProperty(String property_name, String property_value)
          Appends an <AddToProperty ...> element to the end of the document body without touching any other elements which may change the value of the specified propery.
private  void assertDeclMode()
           
private  void assertSiteMode()
           
private  Node[] cleanRemove(Node parent, Node child)
           
private  void cleanRemoveAll(Element root, Collection to_remove)
           
private  ArrayList getAllElementsMatching(Element root, String element_name, Map attributes)
           
private  Document getXconfDocument()
           
private  String relativizePathToProductRoot(File path)
           
private  String relativizePathToTargetRoot(File path)
           
private  void removeAllPropElements(Element root, String property_name)
           
 void removeFromProperty(String property_name, String property_value)
          Appends a <RenoveFromProperty ...> element to the end of the document body without touching any other elements which may change the value of the specified propery.
 void resetToDefault(String property_name)
          Removes all elements in the document that change the specified property then adds a <ResetProperty ...> element to the end of the document body to reset the property to its declared default value.
 void resetToDefault(String property_name, File target_file)
          Deprecated. Target file is ignored now. Use resetToDefault(java.lang.String).
 void save()
           
 void save(boolean force)
           
private  String standardizePath(String path)
           
private  Node[] stripPrecedingComment(Node parent, Node child)
           
private  Node[] stripTrailingWhiteSpace(Node parent, Node child)
           
private  void undefineOrResetToDefaultProperty(String property_name, String element_name, String name_attribute_name)
          Removes all elements in the document that change the specified property then adds an element to the end of the document to either Reset or Undefine the property (which one depends on the value of the element_name parameter.
private  void undefineOrResetToDefaultProperty(String property_name, String element_name, String name_attribute_name, File target_file)
          Deprecated. Target file is ignored now. Use #undefineOrResetToDefaultProperty(java.lang.String).
 void undefineProperty(String property_name)
          Removes all elements in the document that change the specified property then adds an <UndefineProperty ...> element to the end of the document body to undefine the property.
 void undefineProperty(String property_name, File target_file)
          Deprecated. Target file is ignored now. Use undefineProperty(java.lang.String).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mode_

private int mode_

document_

private Document document_

dirty_

private boolean dirty_

xconfFile_

private File xconfFile_
Constructor Detail

UpdateXconf

public UpdateXconf(int mode)

UpdateXconf

public UpdateXconf(File file,
                   int mode)
Method Detail

getXconfDocument

private Document getXconfDocument()
                           throws XconfException
Throws:
XconfException

assertSiteMode

private void assertSiteMode()
                     throws XconfException
Throws:
XconfException

assertDeclMode

private void assertDeclMode()
                     throws XconfException
Throws:
XconfException

addInclude

public void addInclude(String path_to_include)
                throws XconfException
Throws:
XconfException

standardizePath

private String standardizePath(String path)
                        throws XconfException
Returns:
an string containing the URL if the path looks like an URL or a relative path from the product root.
Throws:
XconfException

relativizePathToTargetRoot

private String relativizePathToTargetRoot(File path)

relativizePathToProductRoot

private String relativizePathToProductRoot(File path)

addOrUpdate

public void addOrUpdate(String property_name,
                        String property_value,
                        File target_file)
                 throws XconfException
Update the site property to the new value.

Parameters:
target_file - optionally specify the properties target file
Throws:
XconfException

addOrUpdate

public void addOrUpdate(String property_name,
                        String property_value,
                        File target_file,
                        String comment)
                 throws XconfException
Removes all elements in the document that change the specified property then adds a <Property gt; element to the end of the document body to set the site value to the specified value.

Parameters:
target_file - optionally specify the properties target file. If it is null then the current value for the target file will be retained
comment - optionally add a comment before the element
Throws:
XconfException

addToProperty

public void addToProperty(String property_name,
                          String property_value)
                   throws XconfException
Appends an <AddToProperty ...> element to the end of the document body without touching any other elements which may change the value of the specified propery.

Throws:
XconfException

removeFromProperty

public void removeFromProperty(String property_name,
                               String property_value)
                        throws XconfException
Appends a <RenoveFromProperty ...> element to the end of the document body without touching any other elements which may change the value of the specified propery.

Throws:
XconfException

resetToDefault

public void resetToDefault(String property_name,
                           File target_file)
                    throws XconfException
Deprecated. Target file is ignored now. Use resetToDefault(java.lang.String).

Throws:
XconfException

resetToDefault

public void resetToDefault(String property_name)
                    throws XconfException
Removes all elements in the document that change the specified property then adds a <ResetProperty ...> element to the end of the document body to reset the property to its declared default value.

Throws:
XconfException

undefineProperty

public void undefineProperty(String property_name,
                             File target_file)
                      throws XconfException
Deprecated. Target file is ignored now. Use undefineProperty(java.lang.String).

Throws:
XconfException

undefineProperty

public void undefineProperty(String property_name)
                      throws XconfException
Removes all elements in the document that change the specified property then adds an <UndefineProperty ...> element to the end of the document body to undefine the property.

Throws:
XconfException

undefineOrResetToDefaultProperty

private void undefineOrResetToDefaultProperty(String property_name,
                                              String element_name,
                                              String name_attribute_name,
                                              File target_file)
                                       throws XconfException
Deprecated. Target file is ignored now. Use #undefineOrResetToDefaultProperty(java.lang.String).

Throws:
XconfException

undefineOrResetToDefaultProperty

private void undefineOrResetToDefaultProperty(String property_name,
                                              String element_name,
                                              String name_attribute_name)
                                       throws XconfException
Removes all elements in the document that change the specified property then adds an element to the end of the document to either Reset or Undefine the property (which one depends on the value of the element_name parameter.

Throws:
XconfException

cleanRemoveAll

private void cleanRemoveAll(Element root,
                            Collection to_remove)

cleanRemove

private Node[] cleanRemove(Node parent,
                           Node child)

getAllElementsMatching

private ArrayList getAllElementsMatching(Element root,
                                         String element_name,
                                         Map attributes)

removeAllPropElements

private void removeAllPropElements(Element root,
                                   String property_name)

stripPrecedingComment

private Node[] stripPrecedingComment(Node parent,
                                     Node child)

stripTrailingWhiteSpace

private Node[] stripTrailingWhiteSpace(Node parent,
                                       Node child)

save

public void save()
          throws XconfException
Throws:
XconfException

save

public void save(boolean force)
          throws XconfException
Throws:
XconfException