/*
(non-Javadoc)

@see
net.jawr.web.resource.bundle.generator.AbstractCSSGenerator#rewriteUrl(
net.jawr.web.resource.bundle.generator.GeneratorContext,
java.lang.String)
167773
@Override
	protected String rewriteUrl(GeneratorContext context, String content) throws IOException {

		// Here we create a new context where the bundle name is the Jawr
		// generator CSS path
		// The version of the CSS classpath for debug mode will be different
		// compare to the standard one
		JoinableResourceBundle tempBundle = new JoinableResourceBundleImpl(ResourceGenerator.CSS_DEBUGPATH, null, null,
				null, null, null, context.getConfig().getGeneratorRegistry());
		BundleProcessingStatus tempStatus = new BundleProcessingStatus(BundleProcessingStatus.FILE_PROCESSING_TYPE,
				tempBundle, context.getResourceReaderHandler(), context.getConfig());

		CSSURLPathRewriterPostProcessor postProcessor = new CSSURLPathRewriterPostProcessor();
		String resourcePath = context.getPath();
		tempStatus.setLastPathAdded(getGeneratorPrefix() + GeneratorRegistry.PREFIX_SEPARATOR + resourcePath);
		StringBuffer resourceData = postProcessor.postProcessBundle(tempStatus, new StringBuffer(content));
		return resourceData.toString();

	}
673191
@Override
	protected String getRewrittenImagePath(String originalCssPath, String newCssPath, String url) throws IOException {

		String imgUrl = null;

		// Retrieve the current CSS file from which the CSS image is referenced
		String currentCss = originalCssPath;
		boolean generatedImg = false;
		if (binaryRsHandler != null) {
			GeneratorRegistry imgRsGeneratorRegistry = binaryRsHandler.getConfig().getGeneratorRegistry();
			generatedImg = imgRsGeneratorRegistry.isGeneratedBinaryResource(url);
		}

		boolean cssGeneratorIsHandleCssImage = isCssGeneratorHandlingCssImage(currentCss);

		String rootPath = currentCss;

		// If the CSS image is taken from the classpath, add the classpath cache
		// prefix
		if (generatedImg || cssGeneratorIsHandleCssImage) {

			String tempUrl = url;

			// If it's a classpath CSS, the url of the CSS image is defined
			// relatively to it.
			if (cssGeneratorIsHandleCssImage && !generatedImg) {
				tempUrl = PathNormalizer.concatWebPath(rootPath, url);
			}

			// generate image cache URL
			imgUrl = rewriteURL(tempUrl, binaryServletPath, newCssPath, binaryRsHandler);
		} else {

			if (config.getGeneratorRegistry().isPathGenerated(rootPath)) {
				rootPath = rootPath.substring(rootPath.indexOf(GeneratorRegistry.PREFIX_SEPARATOR) + 1);
			}

			// Generate the image URL from the current CSS path
			imgUrl = PathNormalizer.concatWebPath(rootPath, url);
			imgUrl = rewriteURL(imgUrl, binaryServletPath, newCssPath, binaryRsHandler);
		}

		// This following condition should never be true.
		// If it does, it means that the image path is wrongly defined.
		if (imgUrl == null) {
			LOGGER.error("The CSS image path for '" + url + "' defined in '" + currentCss
					+ "' is out of the application context. Please check your CSS file.");
		}

		return imgUrl;
	}
1113320
public static rewriteglobal_binding get(nitro_service service) throws Exception{
		rewriteglobal_binding obj = new rewriteglobal_binding();
		rewriteglobal_binding response = (rewriteglobal_binding) obj.get_resource(service);
		return response;
	}
490900
public static void rewriteContent(@NotNull Element parent, @NotNull RewriteContentHandler rewriteContentHandler) {

    // iterate through content list and build new content list
    List<Content> originalContent = parent.getContent();
    List<Content> newContent = new ArrayList<Content>();
    for (Content contentElement : originalContent) {

      // handle element
      if (contentElement instanceof Element) {
        Element element = (Element)contentElement;

        // check if rewrite is needed for element
        List<Content> rewriteContent = rewriteContentHandler.rewriteElement(element);
        if (rewriteContent != null) {
          // element was removed
          if (rewriteContent.isEmpty()) {
            // do not add to newContent
          }

          // element is the same - rewrite child elements
          else if (rewriteContent.size() == 1 && rewriteContent.get(0) == element) { //NOPMD
            rewriteContent(element, rewriteContentHandler);
            newContent.add(element);
          }

          // element was replaced with other content - rewrite and add instead
          else {
            for (Content newContentItem : rewriteContent) {
              if (newContentItem instanceof Element) {
                Element newElement = (Element)newContentItem;
                rewriteContent(newElement, rewriteContentHandler);
              }
              newContent.add(newContentItem.clone());
            }
          }
        }

        // nothing to rewrite - do nothing, but rewrite child element
        else {
          rewriteContent(element, rewriteContentHandler);
          newContent.add(element);
        }

      }

      // handle text node
      else if (contentElement instanceof Text) {
        Text text = (Text)contentElement;

        // check if rewrite is needed for text node
        List<Content> rewriteContent = rewriteContentHandler.rewriteText(text);
        if (rewriteContent != null) {
          // element was removed
          if (rewriteContent.isEmpty()) {
            // do not add to newContent
          }

          // element is the same - ignore
          else if (rewriteContent.size() == 1 && rewriteContent.get(0) == text) { //NOPMD
            // add original element
            newContent.add(text);
          }

          // element was replaced with other content - add instead
          else {
            for (Content newContentItem : rewriteContent) {
              newContent.add(newContentItem.clone());
            }
          }
        }

        // nothing to rewrite - do nothing, but add original text element
        else {
          newContent.add(text);
        }

      }

      // unknown element - just add to new content
      else {
        newContent.add(contentElement);
      }

    }

    // replace original content with new content
    parent.removeContent();
    parent.addContent(newContent);

  }
1196122
private void writeURL(JsonGenerator jsonGenerator, Object entity) throws IOException {
        // It is exactly the same as the 'name' property.
        jsonGenerator.writeFieldName(URL);
        if (entity instanceof EntitySet) {
            jsonGenerator.writeObject(((EntitySet) entity).getName());
        } else {
            jsonGenerator.writeObject(((Singleton) entity).getName());
        }
    }
395498
@Override
    public String encodeRedirectURL(String url) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "encodeRedirectURL: " + url);
        }
        return encodeURL(url);
    }
109315
protected HttpBuilder redirect(URL url) {
        RedirectResponse resp = new RedirectResponse(url);
        RequestContext.setControllerResponse(resp);
        return new HttpBuilder(resp);
    }
1152298
public String rewrite() {
        if (sqlTokens.isEmpty()) {
            return originalSQL;
        }
        SQLBuilder result = new SQLBuilder(Collections.emptyList());
        int count = 0;
        for (SQLToken each : sqlTokens) {
            if (0 == count) {
                result.appendLiterals(originalSQL.substring(0, each.getStartIndex()));
            }
            if (each instanceof SchemaToken) {
                appendSchemaPlaceholder(originalSQL, result, (SchemaToken) each, count);
            }
            count++;
        }
        return result.toSQL(masterSlaveRule, metaData.getDataSource());
    }
1120746
private void rewriteDuplicates(final Element root) {
        // collect href and copy-to
        final Map<URI, Map<Set<URI>, List<Attr>>> refs = new HashMap<>();
        for (final Element e: getTopicrefs(root)) {
            Attr attr = e.getAttributeNode(BRANCH_COPY_TO);
            if (attr == null) {
                attr = e.getAttributeNode(ATTRIBUTE_NAME_COPY_TO);
                if (attr == null) {
                    attr = e.getAttributeNode(ATTRIBUTE_NAME_HREF);
                }
            }
            if (attr != null) {
                final URI h = stripFragment(map.resolve(attr.getValue()));
                Map<Set<URI>, List<Attr>> attrsMap = refs.computeIfAbsent(h, k -> new HashMap<>());
                final Set<URI> currentFilter = getBranchFilters(e);
                List<Attr> attrs = attrsMap.computeIfAbsent(currentFilter, k -> new ArrayList<>());
                attrs.add(attr);
            }
        }
        // check and rewrite
        for (final Map.Entry<URI, Map<Set<URI>, List<Attr>>> ref: refs.entrySet()) {
            final Map<Set<URI>, List<Attr>> attrsMaps = ref.getValue();
            if (attrsMaps.size() > 1) {
                if (attrsMaps.containsKey(Collections.EMPTY_LIST)) {
                    attrsMaps.remove(Collections.EMPTY_LIST);
                } else {
                    Set<URI> first = attrsMaps.keySet().iterator().next();
                    attrsMaps.remove(first);
                }
                int i = 1;
                for (final Map.Entry<Set<URI>, List<Attr>> attrsMap: attrsMaps.entrySet()) {
                    final String suffix = "-" + i;
                    final List<Attr> attrs = attrsMap.getValue();
                    for (final Attr attr: attrs) {
                        final String gen = addSuffix(attr.getValue(), suffix);
                        logger.info(MessageUtils.getMessage("DOTJ065I", attr.getValue(), gen)
                                .setLocation(attr.getOwnerElement()).toString());
                        if (attr.getName().equals(BRANCH_COPY_TO)) {
                            attr.setValue(gen);
                        } else {
                            attr.getOwnerElement().setAttribute(BRANCH_COPY_TO, gen);
                        }

                        final URI dstUri = map.resolve(gen);
                        if (dstUri != null) {
                            final FileInfo hrefFileInfo = job.getFileInfo(currentFile.resolve(attr.getValue()));
                            if (hrefFileInfo != null) {
                                final URI newResult = addSuffix(hrefFileInfo.result, suffix);
                                final FileInfo.Builder dstBuilder = new FileInfo.Builder(hrefFileInfo)
                                        .uri(dstUri)
                                        .result(newResult);
                                if (hrefFileInfo.format == null) {
                                    dstBuilder.format(ATTR_FORMAT_VALUE_DITA);
                                }
                                final FileInfo dstFileInfo = dstBuilder.build();
                                job.add(dstFileInfo);
                            }
                        }
                    }
                    i++;
                }
            }
        }
    }
1187654
public void rewriteParseables() {

        if (m_parseables.isEmpty()) {
            return;
        }

        I_CmsReport report = getReport();
        CmsObject cms = getCms();
        cms.getRequestContext().setAttribute(CmsLogEntry.ATTR_LOG_ENTRY, Boolean.FALSE);
        report.println(Messages.get().container(Messages.RPT_START_PARSE_LINKS_0), I_CmsReport.FORMAT_HEADLINE);
        parseLinks(cms, report);
        report.println(Messages.get().container(Messages.RPT_END_PARSE_LINKS_0), I_CmsReport.FORMAT_HEADLINE);
        m_parseables = null;
    }
255046
public void writePersistentUrl(String url, String value) throws Exception {

        store.write(url, value);
    }
1162179
@Override
  public Map<String, Object> rewrite(boolean showDebugInfo) throws IOException {
    Map<String, Object> response = new HashMap<>();
    for (String statsItem : getStatsItems()) {
      if (statsItem.equals(CodecUtil.STATS_TYPE_SUM)) {
        response.put(statsItem, valueSum);
      } else if (statsItem.equals(CodecUtil.STATS_TYPE_N)) {
        response.put(statsItem, valueN);
      } else if (statsItem.equals(CodecUtil.STATS_TYPE_MEAN)) {
        response.put(statsItem, getValue(statsItem));
      } else {
        response.put(statsItem, null);
      }
    }
    if (errorNumber > 0) {
      Map<String, Object> errorResponse = new HashMap<String, Object>();
      for (Entry<String, Integer> entry : getErrorList().entrySet()) {
        errorResponse.put(entry.getKey(), entry.getValue());
      }
      response.put("errorNumber", errorNumber);
      response.put("errorList", errorResponse);
    }
    if (showDebugInfo) {
      response.put("sourceNumber", sourceNumber);
      response.put("stats", "basic");
    }
    return response;
  }
1299961
private void rewriteProperty(JSONObject node, String key, JSONArray rewriteProperty) throws JSONException {
    if (node.get(cleanup(key)) instanceof String) {
      if (rewriteProperty.length() == 2) {
        if (rewriteProperty.get(0) instanceof String && rewriteProperty.get(1) instanceof String) {
          String pattern = rewriteProperty.getString(0);
          String replacement = rewriteProperty.getString(1);

          Pattern compiledPattern = Pattern.compile(pattern);
          Matcher matcher = compiledPattern.matcher(node.getString(cleanup(key)));
          node.put(cleanup(key), matcher.replaceAll(replacement));
        }
      }
    }
  }
163597
def _build_url_rewriter(cls, session: AppSession):
        ''''''
        if session.args.escaped_fragment or session.args.strip_session_id:
            return session.factory.new(
                'URLRewriter',
                hash_fragment=session.args.escaped_fragment,
                session_id=session.args.strip_session_id
            )
315787
def rewrite_url(self, url, is_image_src=False):
        
        rewrite = self.img_src_rewrite if is_image_src else self.link_rewrite
        if rewrite:
            return rewrite.format(url=urlquote(url))
        return url
1300612
@Override
    public void addURL(URL url)
    {
        this.finder.addURI(URI.create(url.toExternalForm()));
    }
617670
public void redirect(String url) throws IOException {
        endChangesIfNecessary();
        ResponseWriter writer = getWrapped();
        writer.startElement("redirect", null);
        writer.writeAttribute("url", url, null);
        writer.endElement("redirect");
    }