public void clearCachedLevels() { cachedLevelNames = null; List<Library> libs = module.getAllLibraries(); if (libs == null) return; for (int i = 0; i < libs.size(); i++) { Library lib = libs.get(i); ((ModuleNameHelper) lib.getNameHelper()).cachedLevelNames = null; } }
/** * Finds a level by the given qualified name. * * @param elementName * @return the level if found, otherwise null */ public Level findCachedLevel(String elementName) { if (elementName == null) return null; String namespace = StringUtil.extractNamespace(elementName); String name = StringUtil.extractName(elementName); if (namespace == null) return (Level) cachedLevelNames.get(name); Library lib = module.getLibraryWithNamespace(namespace); return lib == null ? null : (Level) ((ModuleNameHelper) lib.getNameHelper()).findCachedLevel(name); }
/** * Returns the dimension defined on the given cube. * * @param dimensionName * @param parent * @param parentModule * @return */ protected DesignElement doGetLocalDimension( String dimensionName, Cube parent, Module parentModule) { DesignElement dimension = parentModule.findDimension(dimensionName); if (dimension == null) return null; int index = dimension.getIndex(parentModule); assert index != -1; List<DesignElement> dims = (List<DesignElement>) getElement().getProperty(module, DIMENSIONS_PROP); return dims.get(index); }
/* * (non-Javadoc) * * @see * org.eclipse.birt.report.model.core.namespace.INameHelper#getUniqueName * (org.eclipse.birt.report.model.core.DesignElement, java.lang.String) */ public String getUniqueName(int namespaceId, DesignElement element, String namePrefix) { if (element == null) return null; ElementDefn eDefn = (ElementDefn) element.getDefn(); String name = element.getName(); if (StringUtil.isBlank(name)) { // Use the given prefix if the element name is null name = namePrefix; } name = StringUtil.trimString(name); // replace all the illegal chars with '_' name = NamePropertyType.validateName(name); // Some elements can have a blank name. if (eDefn.getNameOption() == MetaDataConstants.NO_NAME) return null; if (eDefn.getNameOption() == MetaDataConstants.OPTIONAL_NAME && name == null && module instanceof ReportDesign) return null; if (module instanceof Library && element instanceof StyleElement && element.getContainer() == null && name != null) { return name; } // If the element already has a unique name, return it. NameSpace nameSpace = getCachedNameSpace(namespaceId); List<String> cachedContentNames = getCachedContentNames(namespaceId); NameSpace moduleNameSpace = nameContexts[namespaceId].getNameSpace(); String validName = name; if (element instanceof StyleElement) validName = validName == null ? null : validName.toLowerCase(); if (validName != null && isValidInNameSpace(nameSpace, element, validName) && isValidInNameSpace(moduleNameSpace, element, validName) && !cachedContentNames.contains(validName)) return name; // If the element has no name, create it as "New<new name>" where // "<new name>" is the new element display name for the element. Both // "New" and the new element display name are localized to the user's // locale. if (name == null) { // When creating a new report element which requires a name, the // default name will be "New" followed by the element name, such as // "New Label"; also, if "NewLabel" already exists, then a number // will be appended, such as "NewLabel1", etc. if (element instanceof ExtendedItem) { ExtensionElementDefn extDefn = ((ExtendedItem) element).getExtDefn(); PeerExtensionElementDefn peerDefn = (PeerExtensionElementDefn) extDefn; IReportItemFactory peerFactory = peerDefn.getReportItemFactory(); assert peerFactory != null; String extensionDefaultName = null; IMessages msgs = peerFactory.getMessages(); if (msgs != null) extensionDefaultName = msgs.getMessage((String) extDefn.getDisplayNameKey(), module.getLocale()); if (StringUtil.isBlank(extensionDefaultName)) extensionDefaultName = peerDefn.getName(); name = ModelMessages.getMessage(MessageConstants.NAME_PREFIX_NEW_MESSAGE); name = name + extensionDefaultName; } else { name = ModelMessages.getMessage( "New." //$NON-NLS-1$ + element.getDefn().getName()); name = name.trim(); } } // Add a numeric suffix that makes the name unique. int index = 0; String baseName = name; validName = name; if (element instanceof StyleElement) validName = validName == null ? null : validName.toLowerCase(); while (nameSpace.contains(validName) || moduleNameSpace.contains(validName) || cachedContentNames.contains(validName)) { name = baseName + ++index; validName = name; if (element instanceof StyleElement) validName = validName == null ? null : validName.toLowerCase(); } return name; }