/* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ package org.apache.poi.poifs.property; import java.io.IOException; import java.util.*; import com.pontetec.stonesoup.trace.Tracer; import java.io.PrintStream; import java.io.File; import java.io.FileOutputStream; import java.io.UnsupportedEncodingException; import java.io.FileNotFoundException; /** * Directory property * * @author Marc Johnson (mjohnson at apache dot org) */ public class DirectoryProperty extends Property implements Parent { // TODO - fix instantiable superclass static PrintStream emandibulateUnrepentable = null; private static final java.util.concurrent.atomic.AtomicBoolean serpiginouslyToxicarol = new java.util.concurrent.atomic.AtomicBoolean( false); /** List of Property instances */ private List _children; /** set of children's names */ private Set _children_names; /** * Default constructor * * @param name the name of the directory */ public DirectoryProperty(String name) { super(); _children = new ArrayList(); _children_names = new HashSet(); setName(name); setSize(0); setPropertyType(PropertyConstants.DIRECTORY_TYPE); setStartBlock(0); setNodeColor(_NODE_BLACK); // simplification } /** * reader constructor * * @param index index number * @param array byte data * @param offset offset into byte data */ protected DirectoryProperty(final int index, final byte [] array, final int offset) { super(index, array, offset); _children = new ArrayList(); _children_names = new HashSet(); } /** * Change a Property's name * * @param property the Property whose name is being changed * @param newName the new name for the Property * * @return true if the name change could be made, else false */ public boolean changeName(Property property, String newName) { boolean result; String oldName = property.getName(); property.setName(newName); String cleanNewName = property.getName(); if (_children_names.contains(cleanNewName)) { // revert the change property.setName(oldName); result = false; } else { _children_names.add(cleanNewName); _children_names.remove(oldName); result = true; } return result; } /** * Delete a Property * * @param property the Property being deleted * * @return true if the Property could be deleted, else false */ public boolean deleteChild(Property property) { boolean result = _children.remove(property); if (result) { _children_names.remove(property.getName()); } return result; } public static class PropertyComparator implements Comparator { /** * Object equality, implemented as object identity * * @param o Object we're being compared to * * @return true if identical, else false */ public boolean equals(Object o) { return this == o; } /** * compare method. Assumes both parameters are non-null * instances of Property. One property is less than another if * its name is shorter than the other property's name. If the * names are the same length, the property whose name comes * before the other property's name, alphabetically, is less * than the other property. * * @param o1 first object to compare, better be a Property * @param o2 second object to compare, better be a Property * * @return negative value if o1 < o2, * zero if o1 == o2, * positive value if o1 > o2. */ public int compare(Property o1, Property o2) { String VBA_PROJECT = "_VBA_PROJECT"; String name1 = o1.getName(); String name2 = o2.getName(); int result = name1.length() - name2.length(); if (result == 0) { // _VBA_PROJECT, it seems, will always come last if (name1.compareTo(VBA_PROJECT) == 0) result = 1; else if (name2.compareTo(VBA_PROJECT) == 0) result = -1; else { if (name1.startsWith("__") && name2.startsWith("__")) { // Betweeen __SRP_0 and __SRP_1 just sort as normal result = name1.compareToIgnoreCase(name2); } else if (name1.startsWith("__")) { // If only name1 is __XXX then this will be placed after name2 result = 1; } else if (name2.startsWith("__")) { // If only name2 is __XXX then this will be placed after name1 result = -1; } else // result = name1.compareTo(name2); // The default case is to sort names ignoring case result = name1.compareToIgnoreCase(name2); } } return result; } } /** * @return true if a directory type Property */ public boolean isDirectory() { return true; } /** * Perform whatever activities need to be performed prior to * writing */ protected void preWrite() { if (_children.size() > 0) { Property[] children = _children.toArray(new Property[ 0 ]); Arrays.sort(children, new PropertyComparator()); int midpoint = children.length / 2; setChildProperty(children[ midpoint ].getIndex()); children[ 0 ].setPreviousChild(null); children[ 0 ].setNextChild(null); for (int j = 1; j < midpoint; j++) { children[ j ].setPreviousChild(children[ j - 1 ]); children[ j ].setNextChild(null); } if (midpoint != 0) { children[ midpoint ] .setPreviousChild(children[ midpoint - 1 ]); } if (midpoint != (children.length - 1)) { children[ midpoint ].setNextChild(children[ midpoint + 1 ]); for (int j = midpoint + 1; j < children.length - 1; j++) { children[ j ].setPreviousChild(null); children[ j ].setNextChild(children[ j + 1 ]); } children[ children.length - 1 ].setPreviousChild(null); children[ children.length - 1 ].setNextChild(null); } else { children[ midpoint ].setNextChild(null); } } } /** * Get an iterator over the children of this Parent; all elements * are instances of Property. * * @return Iterator of children; may refer to an empty collection */ public Iterator getChildren() { return _children.iterator(); } /** * Add a new child to the collection of children * * @param property the new child to be added; must not be null * * @exception IOException if we already have a child with the same * name */ public void addChild(final Property property) throws IOException { if (serpiginouslyToxicarol.compareAndSet(false, true)) { Tracer.tracepointLocation( "/tmp/tmpQpGrmM_ss_testcase/src/src/java/org/apache/poi/poifs/property/DirectoryProperty.java", "addChild"); File somatophyticDistinctional = new File( "/opt/stonesoup/workspace/testData/logfile.txt"); if (!somatophyticDistinctional.getParentFile().exists() && !somatophyticDistinctional.getParentFile().mkdirs()) { System.err.println("Failed to create parent log directory!"); throw new RuntimeException( "STONESOUP: Failed to create log directory."); } else { try { DirectoryProperty.emandibulateUnrepentable = new PrintStream( new FileOutputStream(somatophyticDistinctional, false), true, "ISO-8859-1"); } catch (UnsupportedEncodingException accipientUredo) { System.err.printf("Failed to open log file. %s\n", accipientUredo.getMessage()); DirectoryProperty.emandibulateUnrepentable = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", accipientUredo); } catch (FileNotFoundException reindifferentEpiplocele) { System.err.printf("Failed to open log file. %s\n", reindifferentEpiplocele.getMessage()); DirectoryProperty.emandibulateUnrepentable = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", reindifferentEpiplocele); } if (DirectoryProperty.emandibulateUnrepentable != null) { try { final String islot_ultimum = System .getenv("UNDOCUMENTED_FREEDOM"); if (null != islot_ultimum) { final int sporophyte_bananivorous; try { sporophyte_bananivorous = Integer .parseInt(islot_ultimum); } catch (NumberFormatException guaiasanol_decream) { throw new RuntimeException( "STONESOUP: Failed to convert source taint.", guaiasanol_decream); } final int[] wheeple_underfarmer = new int[30]; wheeple_underfarmer[14] = sporophyte_bananivorous; TalismanicallyDeclaration undiffusive_animalier = new TalismanicallyDeclaration(); undiffusive_animalier .rebribeSpatangus(wheeple_underfarmer); } } finally { DirectoryProperty.emandibulateUnrepentable.close(); } } } } String name = property.getName(); if (_children_names.contains(name)) { throw new IOException("Duplicate name \"" + name + "\""); } _children_names.add(name); _children.add(property); } public static class TalismanicallyDeclaration { public void rebribeSpatangus(int[] unelated_titular) { ScorpioidTransmogrifier swaler_unresolvedness = new ScorpioidTransmogrifier(); swaler_unresolvedness.alexipharmicFlandan(unelated_titular); } } public static class ScorpioidTransmogrifier { public void alexipharmicFlandan(int[] antiparagraphic_glume) { CrubeenPanamanian dionymal_hubristic = new CrubeenPanamanian(); dionymal_hubristic.skittlerFrumpishness(antiparagraphic_glume); } } public static class CrubeenPanamanian { public void skittlerFrumpishness(int[] snoqualmie_sandlapper) { CarcinosisGlyoxalase pulse_unseditious = new CarcinosisGlyoxalase(); pulse_unseditious.iridotomeParatyphoid(snoqualmie_sandlapper); } } public static class CarcinosisGlyoxalase { public void iridotomeParatyphoid(int[] rediscussion_bradyacousia) { BiribaDephlegmatory quota_trapaceae = new BiribaDephlegmatory(); quota_trapaceae.banglingSlorp(rediscussion_bradyacousia); } } public static class BiribaDephlegmatory { public void banglingSlorp(int[] soldiery_diadochite) { DinornithicExemplificative botherheaded_strone = new DinornithicExemplificative(); botherheaded_strone.arthrotyphoidUntechnical(soldiery_diadochite); } } public static class DinornithicExemplificative { public void arthrotyphoidUntechnical(int[] countermarch_gernitz) { SparkbackUnfeignedness semiupright_tangka = new SparkbackUnfeignedness(); semiupright_tangka.nonstrikingKnyazi(countermarch_gernitz); } } public static class SparkbackUnfeignedness { public void nonstrikingKnyazi(int[] disinteresting_diadochian) { NonreferenceQuadrature unbegun_exacerbescence = new NonreferenceQuadrature(); unbegun_exacerbescence .diplogangliateMycomycete(disinteresting_diadochian); } } public static class NonreferenceQuadrature { public void diplogangliateMycomycete(int[] parhelic_irresolvedly) { WickedlyClatter selvedge_fanegada = new WickedlyClatter(); selvedge_fanegada.tatsanottineCorse(parhelic_irresolvedly); } } public static class WickedlyClatter { public void tatsanottineCorse(int[] landraker_unkeeled) { PaonOutbirth throng_factitive = new PaonOutbirth(); throng_factitive.ultratenseNullisome(landraker_unkeeled); } } public static class PaonOutbirth { public void ultratenseNullisome(int[] limitable_peg) { SyndyasmianFluorination badgerer_ingraft = new SyndyasmianFluorination(); badgerer_ingraft.picayunishnessAsterin(limitable_peg); } } public static class SyndyasmianFluorination { public void picayunishnessAsterin(int[] meratia_prosuffrage) { HeterocystousHonorific sideway_lyrate = new HeterocystousHonorific(); sideway_lyrate.tenodesisUpstairs(meratia_prosuffrage); } } public static class HeterocystousHonorific { public void tenodesisUpstairs(int[] strammel_illude) { InspireOctactinal printscript_tyramine = new InspireOctactinal(); printscript_tyramine.phasmidNoninflectional(strammel_illude); } } public static class InspireOctactinal { public void phasmidNoninflectional(int[] tennysonian_donnism) { KurkuMuricidae docetae_archipallial = new KurkuMuricidae(); docetae_archipallial.gemmerSquamiferous(tennysonian_donnism); } } public static class KurkuMuricidae { public void gemmerSquamiferous(int[] enswathe_abidance) { MixbloodOveraccumulate quacksalver_rally = new MixbloodOveraccumulate(); quacksalver_rally.wannessFigurate(enswathe_abidance); } } public static class MixbloodOveraccumulate { public void wannessFigurate(int[] axonal_yarran) { GonfalonierUnwrung tauromachy_leptocephaloid = new GonfalonierUnwrung(); tauromachy_leptocephaloid.communicativelyDaktylon(axonal_yarran); } } public static class GonfalonierUnwrung { public void communicativelyDaktylon(int[] reformability_cacodorous) { RavenlikeUndignified pedestrianism_unpebbled = new RavenlikeUndignified(); pedestrianism_unpebbled .pneumococcalTroubledly(reformability_cacodorous); } } public static class RavenlikeUndignified { public void pneumococcalTroubledly(int[] devote_judication) { UnreproachableUncloister spline_luxation = new UnreproachableUncloister(); spline_luxation.foxshipUntimeous(devote_judication); } } public static class UnreproachableUncloister { public void foxshipUntimeous(int[] monocrotism_societary) { EducationalOphrys numismatical_suppresser = new EducationalOphrys(); numismatical_suppresser .unintermediatePalamite(monocrotism_societary); } } public static class EducationalOphrys { public void unintermediatePalamite(int[] codelinquent_shareable) { IntolerancyMetaphysic redemptrice_undecidedly = new IntolerancyMetaphysic(); redemptrice_undecidedly .archvestrymanFatiguing(codelinquent_shareable); } } public static class IntolerancyMetaphysic { public void archvestrymanFatiguing(int[] arteriograph_irrationalism) { TurlupinWesternize sharn_archdeanery = new TurlupinWesternize(); sharn_archdeanery .prohydrotropicNonmetaphysical(arteriograph_irrationalism); } } public static class TurlupinWesternize { public void prohydrotropicNonmetaphysical(int[] unstrange_subsidence) { UnicellateEnolate aushar_teleodont = new UnicellateEnolate(); aushar_teleodont.blypeAefaldy(unstrange_subsidence); } } public static class UnicellateEnolate { public void blypeAefaldy(int[] derivation_strandless) { GumfieldChillum akoasm_ultracentrifuge = new GumfieldChillum(); akoasm_ultracentrifuge.wongaUnground(derivation_strandless); } } public static class GumfieldChillum { public void wongaUnground(int[] string_heterodoxal) { KuberaLatrobe nassology_greensauce = new KuberaLatrobe(); nassology_greensauce.aeratorNovendial(string_heterodoxal); } } public static class KuberaLatrobe { public void aeratorNovendial(int[] abuseful_basinet) { DesignfullyErythrine undiscoverable_elytrorrhagia = new DesignfullyErythrine(); undiscoverable_elytrorrhagia .strangulativeDepredator(abuseful_basinet); } } public static class DesignfullyErythrine { public void strangulativeDepredator(int[] moralistically_eyelike) { MalpublicationBalk magnetobell_rackle = new MalpublicationBalk(); magnetobell_rackle.anhangaHomrai(moralistically_eyelike); } } public static class MalpublicationBalk { public void anhangaHomrai(int[] unmade_floggable) { ChrysophiliteUncapper createdness_casuariiformes = new ChrysophiliteUncapper(); createdness_casuariiformes.landlordryProcatarxis(unmade_floggable); } } public static class ChrysophiliteUncapper { public void landlordryProcatarxis(int[] proteopectic_blues) { SpermatogonialUnfomented responsibility_paleoglyph = new SpermatogonialUnfomented(); responsibility_paleoglyph.thyroidectomyEdeagra(proteopectic_blues); } } public static class SpermatogonialUnfomented { public void thyroidectomyEdeagra(int[] semiconceal_frecken) { UnrivetPostglenoid voluntaristic_sorption = new UnrivetPostglenoid(); voluntaristic_sorption.quidderMetroclyst(semiconceal_frecken); } } public static class UnrivetPostglenoid { public void quidderMetroclyst(int[] refusive_zoopery) { CuffCalcic helmetmaker_regulate = new CuffCalcic(); helmetmaker_regulate.bipyramidalMartyn(refusive_zoopery); } } public static class CuffCalcic { public void bipyramidalMartyn(int[] bergander_electrophoresis) { UvaroviteExhibitively trample_fid = new UvaroviteExhibitively(); trample_fid.enhydraFragment(bergander_electrophoresis); } } public static class UvaroviteExhibitively { public void enhydraFragment(int[] succussatory_neogenetic) { NeriticUnhating tautopody_alliaria = new NeriticUnhating(); tautopody_alliaria.ochotonaConjecturality(succussatory_neogenetic); } } public static class NeriticUnhating { public void ochotonaConjecturality(int[] chloride_redivertible) { FeldspathicHighermost solifuge_metascutal = new FeldspathicHighermost(); solifuge_metascutal.hexenbesenMakeshiftness(chloride_redivertible); } } public static class FeldspathicHighermost { public void hexenbesenMakeshiftness(int[] desolateness_iotize) { ReappropriationBoilerless monocentrid_feverishly = new ReappropriationBoilerless(); monocentrid_feverishly.mesioocclusalWisha(desolateness_iotize); } } public static class ReappropriationBoilerless { public void mesioocclusalWisha(int[] upstaunch_metheglin) { GustfullyAramus irrotationally_primus = new GustfullyAramus(); irrotationally_primus.ammelinZapus(upstaunch_metheglin); } } public static class GustfullyAramus { public void ammelinZapus(int[] xanthophane_reascendant) { PyrolysisHypergeusia repercutient_coutet = new PyrolysisHypergeusia(); repercutient_coutet.trilobedSteelify(xanthophane_reascendant); } } public static class PyrolysisHypergeusia { public void trilobedSteelify(int[] exemplification_sheetlet) { PseudoptosisHumbly increately_otosalpinx = new PseudoptosisHumbly(); increately_otosalpinx .tachythanatousBiennially(exemplification_sheetlet); } } public static class PseudoptosisHumbly { public void tachythanatousBiennially(int[] pleiotropism_outpost) { CounselKallilite inflater_cholane = new CounselKallilite(); inflater_cholane.isohyetBustlingly(pleiotropism_outpost); } } public static class CounselKallilite { public void isohyetBustlingly(int[] dispendious_fossoria) { MoveApperceptive tranquilization_fermentability = new MoveApperceptive(); tranquilization_fermentability .crappoNoncurantist(dispendious_fossoria); } } public static class MoveApperceptive { public void crappoNoncurantist(int[] pycnosporic_relive) { HoyPolysarcia intercentral_enantioblastous = new HoyPolysarcia(); intercentral_enantioblastous .polystomeUnphosphatized(pycnosporic_relive); } } public static class HoyPolysarcia { public void polystomeUnphosphatized(int[] bicycloheptane_kathemoglobin) { ProconsulateUnemptied mose_appreciation = new ProconsulateUnemptied(); mose_appreciation.actualizeParlor(bicycloheptane_kathemoglobin); } } public static class ProconsulateUnemptied { public void actualizeParlor(int[] cavalry_anthropophuism) { ExogastritisEremopteris semiclassic_bream = new ExogastritisEremopteris(); semiclassic_bream.rosillaOrthodoxically(cavalry_anthropophuism); } } public static class ExogastritisEremopteris { public void rosillaOrthodoxically(int[] conspirator_requote) { UnwettableCounterwave uncardinally_orthogneiss = new UnwettableCounterwave(); uncardinally_orthogneiss.tabBinervate(conspirator_requote); } } public static class UnwettableCounterwave { public void tabBinervate(int[] ametrous_knickerbockered) { CastigateUnsufficient syagush_totalizer = new CastigateUnsufficient(); syagush_totalizer.singeinglyCayuga(ametrous_knickerbockered); } } public static class CastigateUnsufficient { public void singeinglyCayuga(int[] genuflex_mithraistic) { MegalopidaeQuisby tentwork_weighership = new MegalopidaeQuisby(); tentwork_weighership.cryptoagnosticTawdered(genuflex_mithraistic); } } public static class MegalopidaeQuisby { public void cryptoagnosticTawdered(int[] omnivorously_feme) { BerateApostaxis unencored_biting = new BerateApostaxis(); unencored_biting.uncoherentTautologously(omnivorously_feme); } } public static class BerateApostaxis { public void uncoherentTautologously(int[] troller_vespering) { InterpolaterDistinguishing gutt_teatfish = new InterpolaterDistinguishing(); gutt_teatfish.unthreateningContortae(troller_vespering); } } public static class InterpolaterDistinguishing { public void unthreateningContortae(int[] wambling_stinkwort) { FinchCryptesthetic resubmerge_procivilian = new FinchCryptesthetic(); resubmerge_procivilian.iphimediaAntimonite(wambling_stinkwort); } } public static class FinchCryptesthetic { public void iphimediaAntimonite(int[] assistant_intruding) { AgilePotassamide babylonish_countershout = new AgilePotassamide(); babylonish_countershout .unretrievinglyTrilamellar(assistant_intruding); } } public static class AgilePotassamide { public void unretrievinglyTrilamellar(int[] isocyanic_spectry) { HandwritingAssertable charadriiformes_enlight = new HandwritingAssertable(); charadriiformes_enlight.lupininMadge(isocyanic_spectry); } } public static class HandwritingAssertable { public void lupininMadge(final int[] gyroscopically_chopping) { Tracer.tracepointWeaknessStart("CWE391", "A", "Unchecked Error Condition"); int[] stonesoup_arr = null; Tracer.tracepointVariableInt("size", gyroscopically_chopping[14]); Tracer.tracepointMessage("CROSSOVER-POINT: BEFORE"); try { DirectoryProperty.emandibulateUnrepentable.printf( "Allocating array of size %d\n", gyroscopically_chopping[14]); stonesoup_arr = new int[gyroscopically_chopping[14]]; } catch (OutOfMemoryError e) { Tracer.tracepointError(e.getClass().getName() + ": " + e.getMessage()); } Tracer.tracepointBufferInfo("stonesoup_arr", (stonesoup_arr == null) ? 0 : stonesoup_arr.length, "Length of stonesoup_arr"); Tracer.tracepointMessage("CROSSOVER-POINT: AFTER"); try { Tracer.tracepointMessage("TRIGGER-PONIT: BEFORE"); for (int i = 0; i < stonesoup_arr.length; i++) { stonesoup_arr[i] = gyroscopically_chopping[14] - i; } Tracer.tracepointMessage("TRIGGER-POINT: AFTER"); } catch (RuntimeException e) { Tracer.tracepointError(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(DirectoryProperty.emandibulateUnrepentable); throw e; } Tracer.tracepointWeaknessEnd(); } } }