/** * Helper method. Construct a filename for *this* particular XLIFF translation file.<br> * (Not the fileName of the ZIP to be served later).<br> * Format will be [moduleName]_[targetLangISO].properties.xml */ private static String getXliffFileName(PropertyFileDescriptor sourceDescriptor, PropertyFileDescriptor targetDescriptor) { return targetDescriptor.getLocation().path() + ".xlf"; }
/** * Helper method. Create Map with K=Template Name, V=Descriptor.<br> * * This associates a property descriptor with the path of its respective template for faster lookups.<br> */ private Map<String, PropertyFileDescriptor> loadDescriptorsForLocale(Locale locale) { Map<String, PropertyFileDescriptor> ret = new LinkedHashMap<String, PropertyFileDescriptor>(); List<PropertyFileDescriptor> descriptors = null; /* * Load the List of descriptors available for this locale.<br> * Note that a null locale implies that either no source language was selected, or the * selected source language is the template language.<br> */ if (locale == null) { descriptors = projectVersion.getTemplate().getDescriptors(); } else { descriptors = projectVersion.getProjectLocale(locale).getDescriptors(); } for (PropertyFileDescriptor descriptor : descriptors) { ret.put(descriptor.isMaster() ? descriptor.getLocation().toString() : descriptor.getMaster().getLocation().toString(), descriptor); } return ret; }
@SuppressWarnings("unchecked") private void addChildrenToArchive(ZipOutputStream out, Resolvable<?, ?> parent) throws IOException { EList<Resolvable<?, ?>> children = (EList<Resolvable<?, ?>>) parent.getChildren(); for (Resolvable<?, ?> child : children) { if (child instanceof PropertyFileDescriptor) { PropertyFileDescriptor descriptor = (PropertyFileDescriptor) child; File file = new File(descriptor.absoluteFilePath().path()); if(!file.exists()) continue; out.putNextEntry(new ZipEntry(((PropertyFileDescriptor) child).getLocation().path())); writeFileToStream(file, out); } else addChildrenToArchive(out, child); } }
@Override protected void onSubmit() { super.onSubmit(); for (FileUpload fileUpload : fileUploadField.getFileUploads()) { PropertyFileDescriptor descriptor = getModel().getObject(); try { PropertyFile file = descriptor.loadProperties(fileUpload.getInputStream()); persist(file); } catch (IOException e) { LOG.error("Failed to retrieve uploaded file for"+descriptor.getLocation(),e); } } }
protected PropertyFileDescriptor findDescriptor(URI path) { PropertyScanner scanner = PropertyResourceUtil.createScanner(this); Locale variant = scanner.getLocale(new File(path.path())); ProjectLocale locale = variant == null ? getTemplate() : getProjectLocale(variant); if (locale == null) return null; EList<PropertyFileDescriptor> descriptors = locale.getDescriptors(); for (PropertyFileDescriptor descriptor : descriptors) { if (path.equals(descriptor.getLocation())) { return descriptor; } } return null; }
BooleanQuery query = new BooleanQuery(); query.add(new TermQuery(new Term(QueryService.FIELD_TEMPLATE_LOCATION, master.getLocation().toString())), Occur.MUST); query.add(new TermQuery(new Term(QueryService.FIELD_KEY, pair.getKey())), Occur.MUST);
BooleanQuery query = new BooleanQuery(); if(!ProjectLocale.TEMPLATE_LOCALE.equals(language)) // for the template. this field is not set query.add(new TermQuery(new Term(QueryService.FIELD_TEMPLATE_LOCATION, descriptor.getLocation().toString())), Occur.MUST); query.add(new TermQuery(new Term(QueryService.FIELD_LOCALE, language==null ? "" : language.toString())), Occur.MUST); query.add(new TermQuery(new Term(QueryService.FIELD_KEY, key)), Occur.MUST);
Field uriField = new Field(QueryService.FIELD_URI, descriptor.getLocation().toString(), Store.YES, Index.NOT_ANALYZED); doc.add(uriField); Field pathField = new Field(QueryService.FIELD_FULL_PATH, descriptor.fullPath().toString(), Store.YES, Index.NOT_ANALYZED); Field value = new Field(QueryService.FIELD_VALUE, nullSafe(property.getValue()), Store.YES, Index.ANALYZED); doc.add(value); String templateLocation = descriptor.getMaster() == null ? "" : descriptor.getMaster().getLocation().toString(); Field templateLoc = new Field(QueryService.FIELD_TEMPLATE_LOCATION, templateLocation, Store.YES, Index.NOT_ANALYZED); doc.add(templateLoc);
@SuppressWarnings({ "unchecked", "rawtypes" }) public static void addNewLocalizedDescriptor(PropertyFileDescriptor descriptor, ProjectLocale locale) { if (!descriptor.eIsSet(PropertiesPackage.Literals.PROPERTY_FILE_DESCRIPTOR__LOCATION)) throw new IllegalArgumentException("Property File Descriptor location is not set"); ProjectVersion version = locale.getParent(); ProjectLocale templateLocale = version.getTemplate(); URI templateResourceLocation = computeTemplateResourceLocation(locale.getLocale(), descriptor.getLocation(), templateLocale.getLocale(),version); Resolvable<?, ?> resolved = templateLocale.resolveChild(templateResourceLocation); PropertyFileDescriptor template = null; if (resolved instanceof PropertyFileDescriptor) { template = (PropertyFileDescriptor) resolved; } if (template == null) throw new IllegalArgumentException("Template property " + templateResourceLocation + " doesn't exist"); Resolvable container = getOrCreateFolder(locale, descriptor.getLocation().trimSegments(1).segments()); if (container.getChild(descriptor.getLocation().lastSegment()) != null) { PropertyFileDescriptor child = (PropertyFileDescriptor) container.getChild(descriptor.getLocation().lastSegment()); child.setMaster(null); container.getChildren().set(container.getChildren().indexOf(child), descriptor); locale.getDescriptors().remove(child); } else { container.getChildren().add(descriptor); } descriptor.setMaster(template); locale.getDescriptors().add(descriptor); }
for (Review review : descriptor.getReviews()) { if (Review.KIND_SUGGESTION.equals(review.getReviewType())) reviews.put(descriptor.getLocation(), review); Collection<Review> currentReviews = reviews.get(descriptor.getLocation()); descriptor.getReviews().addAll(currentReviews); descriptor.updatePercentComplete();
if (fileName.equals(descriptor.getLocation().path())) { int updated = merge(properties, descriptor); if (updated > 0) {
if (next instanceof PropertyFileDescriptor) { PropertyFileDescriptor descriptor = (PropertyFileDescriptor) next; mon.subTask(descriptor.getLocation().toString()); List<Document> documents = analyzer.createDocuments(descriptor); for (Document document : documents) {
for (ProjectLocale locale : version.getChildren()) { Resolvable parent = locale; String[] descriptorPart = descriptor.getLocation().segments(); URI derivedLocation = computeLocaleResourceLocation(locale.getLocale(), version, descriptor.getLocation()); descriptor.setName(descriptor.getLocation().lastSegment()); version.getTemplate().getDescriptors().add(descriptor); descriptor.updatePercentComplete();
setResponsePage(ResourcePage.class, getPage().getPageParameters()); } catch (ExecutionException e) { LOG.error("Failed to merge uploaded properties with "+getModelObject().getLocation(),e); getSession().success(new StringResourceModel("message.upload.failed", this, null,e.getMessage()).getString());
private static void createMissingChildren(ProjectLocale template, ProjectLocale other) { EList<PropertyFileDescriptor> descriptors = template.getDescriptors(); for (PropertyFileDescriptor descriptor : descriptors) { URI derivedLocation = computeLocaleResourceLocation(other.getLocale(), other.getParent(), descriptor.getLocation()); Resolvable<?, ?> child = other.resolveChild(derivedLocation); if(child==null){ Resolvable<?, ?> folder = getOrCreateFolder(other, derivedLocation.trimSegments(1).segments()); PropertyFileDescriptor localeDescriptor = PropertiesFactory.eINSTANCE.createPropertyFileDescriptor(); localeDescriptor.setMaster(descriptor); localeDescriptor.setVariant(other.getLocale()); localeDescriptor.setLocation(derivedLocation); localeDescriptor.setProjectLocale(other); localeDescriptor.setParent(folder); localeDescriptor.setName(URI.decode(derivedLocation.lastSegment())); } } }