/** Removes all @import statements for css. */
 private String removeImportStatements(final String content) {
   final Matcher m = PATTERN.matcher(content);
   final StringBuffer sb = new StringBuffer();
   while (m.find()) {
     // add and check if already exist
     m.appendReplacement(sb, "");
   }
   m.appendTail(sb);
   return sb.toString();
 }
  @Override
  public DecodeQualification getDecodeQualification(Object input) {
    SystemUtils.LOG.fine("Getting decoders...");

    DecodeQualification decodeQualification = DecodeQualification.UNABLE;

    if (input instanceof File) {
      File file = (File) input;

      if (file.isFile()) {
        String fileName = file.getName();

        // first check it is a Sentinel-2 product
        Matcher matcher = PATTERN.matcher(fileName);
        if (matcher.matches()) {

          // test for granule filename first as it is more restrictive
          if (S2OrthoGranuleMetadataFilename.isGranuleFilename(fileName)) {
            level = matcher.group(4).substring(0, 3);
            S2OrthoGranuleMetadataFilename granuleMetadataFilename =
                S2OrthoGranuleMetadataFilename.create(fileName);
            if (granuleMetadataFilename != null
                && (level.equals("L1C")
                    || (level.equals("L2A")
                        && !this.getClass().equals(S2OrthoProductReaderPlugIn.class)))) {
              String tileId = granuleMetadataFilename.tileNumber;
              String epsg = tileIdentifierToEPSG(tileId);
              if (getEPSG() != null && getEPSG().equalsIgnoreCase(epsg)) {
                decodeQualification = DecodeQualification.INTENDED;
              }
            }
          } else if (S2ProductFilename.isMetadataFilename(fileName)) {
            level = matcher.group(4).substring(3);
            S2ProductFilename productFilename = S2ProductFilename.create(fileName);
            if (productFilename != null) {
              if (level.equals("L1C")
                  ||
                  // no multi-resolution for L2A products
                  (level.equals("L2A")
                      && (this instanceof S2OrthoProduct10MReaderPlugIn
                          || this instanceof S2OrthoProduct20MReaderPlugIn
                          || this instanceof S2OrthoProduct60MReaderPlugIn))) {
                crsCache.ensureIsCached(file.getAbsolutePath());
                if (getEPSG() != null && crsCache.hasEPSG(file.getAbsolutePath(), getEPSG())) {
                  decodeQualification = DecodeQualification.INTENDED;
                }
              }
            }
          }
        }
      }
    }

    return decodeQualification;
  }
    @Override
    protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {
      ServiceTarget serviceTarget = context.getServiceTarget();
      RuntimeCapability<Void> runtimeCapability =
          REALM_MAPPER_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
      ServiceName realmMapperName = runtimeCapability.getCapabilityServiceName(RealmMapper.class);

      final String pattern = PATTERN.resolveModelAttribute(context, model).asString();

      ModelNode realmMapList = REALM_REALM_MAP.resolveModelAttribute(context, model);
      Set<String> names = realmMapList.keys();
      final Map<String, String> realmRealmMap = new HashMap<String, String>(names.size());
      names.forEach((String s) -> realmRealmMap.put(s, realmMapList.require(s).asString()));

      String delegateRealmMapper = asStringIfDefined(context, DELEGATE_REALM_MAPPER, model);

      final InjectedValue<RealmMapper> delegateRealmMapperInjector =
          new InjectedValue<RealmMapper>();

      TrivialService<RealmMapper> realmMapperService =
          new TrivialService<RealmMapper>(
              () -> {
                RealmMapper delegate = delegateRealmMapperInjector.getOptionalValue();
                Pattern compiledPattern = Pattern.compile(pattern);
                if (delegate == null) {
                  return new MappedRegexRealmMapper(compiledPattern, realmRealmMap);
                } else {
                  return new MappedRegexRealmMapper(compiledPattern, delegate, realmRealmMap);
                }
              });

      ServiceBuilder<RealmMapper> realmMapperBuilder =
          serviceTarget.addService(realmMapperName, realmMapperService);

      if (delegateRealmMapper != null) {
        String delegateCapabilityName =
            RuntimeCapability.buildDynamicCapabilityName(
                REALM_MAPPER_CAPABILITY, delegateRealmMapper);
        ServiceName delegateServiceName =
            context.getCapabilityServiceName(delegateCapabilityName, RealmMapper.class);

        realmMapperBuilder.addDependency(
            delegateServiceName, RealmMapper.class, delegateRealmMapperInjector);
      }

      commonDependencies(realmMapperBuilder).setInitialMode(Mode.LAZY).install();
    }
Example #4
0
 /** Opposite of {@link #toString()}. */
 public static Area parse(String s) {
   Matcher m = PATTERN.matcher(s);
   if (m.matches()) return new Area(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)));
   return null;
 }
  @Override
  public void startElement(
      final String namespaceURI, final String lName, final String qName, final Attributes attrs)
      throws SAXException {
    if (qName.equals("category")) {
      final String catName = attrs.getValue("name");
      final String priorityStr = attrs.getValue("priority");
      // int prio = 0;
      if (priorityStr != null) {
        category = new Category(catName, Integer.parseInt(priorityStr));
      } else {
        category = new Category(catName);
      }

      if ("off".equals(attrs.getValue(DEFAULT))) {
        category.setDefaultOff();
      }

    } else if (qName.equals("rules")) {
      final String languageStr = attrs.getValue("targetLang");
      language = Language.getLanguageForShortName(languageStr);
      if (language == null) {
        throw new SAXException("Unknown language '" + languageStr + "'");
      }
    } else if (qName.equals("rule")) {
      id = attrs.getValue("id");
      if (inRuleGroup) subId++;
      if (!(inRuleGroup && defaultOff)) {
        defaultOff = "off".equals(attrs.getValue(DEFAULT));
      }

      if (!(inRuleGroup && defaultOn)) {
        defaultOn = "on".equals(attrs.getValue(DEFAULT));
      }
      if (inRuleGroup && id == null) {
        id = ruleGroupId;
      }
      description = attrs.getValue("name");
      if (inRuleGroup && description == null) {
        description = ruleGroupDescription;
      }
      correctExamples = new ArrayList<StringPair>();
      incorrectExamples = new ArrayList<IncorrectBitextExample>();
      if (suggestionMatches != null) {
        suggestionMatches.clear();
      }
    } else if (PATTERN.equals(qName) || "target".equals(qName)) {
      startPattern(attrs);
    } else if (AND.equals(qName)) {
      inAndGroup = true;
    } else if (UNIFY.equals(qName)) {
      inUnification = true;
      uniNegation = YES.equals(attrs.getValue(NEGATE));
    } else if (qName.equals("feature")) {
      uFeature = attrs.getValue("id");
    } else if (qName.equals(TYPE)) {
      uType = attrs.getValue("id");
      uTypeList.add(uType);
    } else if (qName.equals(TOKEN)) {
      setToken(attrs);
    } else if (qName.equals(EXCEPTION)) {
      setExceptions(attrs);
    } else if (qName.equals(EXAMPLE) && attrs.getValue(TYPE).equals("correct")) {
      inCorrectExample = true;
      correctExample = new StringBuilder();
    } else if (EXAMPLE.equals(qName) && attrs.getValue(TYPE).equals("incorrect")) {
      inIncorrectExample = true;
      incorrectExample = new StringBuilder();
      exampleCorrection = new StringBuilder();
      if (attrs.getValue("correction") != null) {
        exampleCorrection.append(attrs.getValue("correction"));
      }
    } else if (MESSAGE.equals(qName)) {
      inMessage = true;
      message = new StringBuilder();
    } else if (qName.equals("short")) {
      inShortMessage = true;
      shortMessage = new StringBuilder();
    } else if (qName.equals(RULEGROUP)) {
      ruleGroupId = attrs.getValue("id");
      ruleGroupDescription = attrs.getValue("name");
      defaultOff = "off".equals(attrs.getValue(DEFAULT));
      defaultOn = "on".equals(attrs.getValue(DEFAULT));
      inRuleGroup = true;
      subId = 0;
    } else if (qName.equals("suggestion") && inMessage) {
      message.append("<suggestion>");
      inSuggestion = true;
    } else if (qName.equals("match")) {
      setMatchElement(attrs);
    } else if (qName.equals(MARKER) && inCorrectExample) {
      correctExample.append("<marker>");
    } else if (qName.equals(MARKER) && inIncorrectExample) {
      incorrectExample.append("<marker>");
    } else if (qName.equals("unification")) {
      uFeature = attrs.getValue("feature");
      inUnificationDef = true;
    } else if (qName.equals("equivalence")) {
      uType = attrs.getValue(TYPE);
    } else if (qName.equals("phrases")) {
      inPhrases = true;
    } else if (qName.equals("includephrases")) {
      phraseElementInit();
    } else if (qName.equals("phrase") && inPhrases) {
      phraseId = attrs.getValue("id");
    } else if (qName.equals("phraseref") && (attrs.getValue("idref") != null)) {
      preparePhrase(attrs);
    } else if (qName.equals("source")) {
      srcLang = Language.getLanguageForShortName(attrs.getValue("lang"));
    }
  }