Java Code Examples for org.unbescape.html.HtmlEscape#escapeHtml5()

The following examples show how to use org.unbescape.html.HtmlEscape#escapeHtml5() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmptyValueLabel.java    From onedev with MIT License 5 votes vote down vote up
private static String getNameOfEmptyValue(AnnotatedElement element) {
	NameOfEmptyValue nameOfEmptyValue = element.getAnnotation(NameOfEmptyValue.class);
	if (nameOfEmptyValue != null)
		return HtmlEscape.escapeHtml5(nameOfEmptyValue.value());
	else
		return "Not defined";
}
 
Example 2
Source File: RevisionPicker.java    From onedev with MIT License 5 votes vote down vote up
@Override
public IModel<?> getBody() {
	String iconClass;
	String label;
	if ("master".equals(revision)) { // default to use master branch when project is empty
		label = "master";
		iconClass = "fa fa-code-fork";
	} else if (revision != null) {
		ProjectAndRevision projectAndRevision = new ProjectAndRevision(projectModel.getObject(), revision);
		label = projectAndRevision.getBranch();
		if (label != null) {
			iconClass = "fa fa-code-fork";
		} else {
			label = projectAndRevision.getTag();
			if (label != null) {
				iconClass = "fa fa-tag";
			} else {
				label = revision;
				if (ObjectId.isId(label))
					label = GitUtils.abbreviateSHA(label);
				iconClass = "fa fa-ext fa-commit";
			}
		} 
		label = HtmlEscape.escapeHtml5(label);
	} else {
		label = "Choose Revision";
		iconClass = "";
	}
	
	return Model.of(String.format("<i class='%s'></i> <span>%s</span> <i class='fa fa-caret-down'></i>", iconClass, label));
}
 
Example 3
Source File: SourceViewPanel.java    From onedev with MIT License 5 votes vote down vote up
private String getJsonOfBlameInfos(boolean blamed) {
	String jsonOfBlameInfos;
	if (blamed) {
		List<BlameInfo> blameInfos = new ArrayList<>();
		
		String commitHash = context.getCommit().name();
		
		BlameCommand cmd = new BlameCommand(context.getProject().getGitDir());
		cmd.commitHash(commitHash).file(context.getBlobIdent().path);
		for (BlameBlock blame: cmd.call()) {
			BlameInfo blameInfo = new BlameInfo();
			blameInfo.commitDate = DateUtils.formatDate(blame.getCommit().getCommitter().getWhen());
			blameInfo.authorName = HtmlEscape.escapeHtml5(blame.getCommit().getAuthor().getName());
			blameInfo.hash = blame.getCommit().getHash();
			blameInfo.abbreviatedHash = GitUtils.abbreviateSHA(blame.getCommit().getHash(), 7);
			CommitDetailPage.State state = new CommitDetailPage.State();
			state.revision = blame.getCommit().getHash();
			if (context.getBlobIdent().path != null)
				state.pathFilter = PatternSet.quoteIfNecessary(context.getBlobIdent().path);
			PageParameters params = CommitDetailPage.paramsOf(context.getProject(), state);
			blameInfo.url = RequestCycle.get().urlFor(CommitDetailPage.class, params).toString();
			blameInfo.ranges = blame.getRanges();
			blameInfos.add(blameInfo);
		}
		try {
			jsonOfBlameInfos = OneDev.getInstance(ObjectMapper.class).writeValueAsString(blameInfos);
		} catch (JsonProcessingException e) {
			throw new RuntimeException(e);
		}
	} else {
		jsonOfBlameInfos = "undefined";
	}
	return jsonOfBlameInfos;
}
 
Example 4
Source File: BuildProcessor.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected String toHtml(ProjectScopedNumber referenceable, String referenceText) {
	CharSequence url = RequestCycle.get().urlFor(
			BuildDashboardPage.class, BuildDashboardPage.paramsOf(referenceable)); 
	Build build = OneDev.getInstance(BuildManager.class).find(referenceable);
	if (build != null && build.getVersion() != null)
		referenceText += " (" + HtmlEscape.escapeHtml5(build.getVersion()) + ")";
	return String.format("<a href='%s' class='build reference' data-reference='%s'>%s</a>", 
			url, referenceable.toString(), referenceText);
}
 
Example 5
Source File: RevisionSelector.java    From onedev with MIT License 4 votes vote down vote up
private Component newItem(String itemId, String itemValue) {
	String ref;
	if (itemValue.startsWith(COMMIT_FLAG))
		ref = itemValue.substring(COMMIT_FLAG.length());
	else if (itemValue.startsWith(ADD_FLAG))
		ref = itemValue.substring(ADD_FLAG.length());
	else
		ref = itemValue;
	
	AjaxLink<Void> link = new ViewStateAwareAjaxLink<Void>("link") {

		@Override
		protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
			super.updateAjaxAttributes(attributes);
			attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());
		}
		
		@Override
		public void onClick(AjaxRequestTarget target) {
			if (itemValue.startsWith(ADD_FLAG)) {
				onCreateRef(target, ref);
			} else {
				selectRevision(target, ref);
			}
		}

		@Override
		protected void onComponentTag(ComponentTag tag) {
			super.onComponentTag(tag);
			
			if (!itemValue.startsWith(ADD_FLAG)) {
				String url = getRevisionUrl(ref);
				if (url != null)
					tag.put("href", url);
			}
		}
		
	};
	if (itemValue.startsWith(COMMIT_FLAG)) {
		link.add(new Label("label", ref));
		link.add(AttributeAppender.append("class", "icon commit"));
	} else if (itemValue.startsWith(ADD_FLAG)) {
		String label;
		if (branchesActive)
			label = "<div class='name'>Create branch <b>" + HtmlEscape.escapeHtml5(ref) + "</b></div>";
		else
			label = "<div class='name'>Create tag <b>" + HtmlEscape.escapeHtml5(ref) + "</b></div>";
		label += "<div class='revision'>from " + HtmlEscape.escapeHtml5(revision) + "</div>";
		link.add(new Label("label", label).setEscapeModelStrings(false));
		link.add(AttributeAppender.append("class", "icon add"));
	} else if (ref.equals(revision)) {
		link.add(new Label("label", ref));
		link.add(AttributeAppender.append("class", "icon current"));
	} else {
		link.add(new Label("label", ref));
	}
	WebMarkupContainer item = new WebMarkupContainer(itemId);
	item.setOutputMarkupId(true);
	item.add(AttributeAppender.append("data-value", HtmlEscape.escapeHtml5(itemValue)));
	item.add(link);
	
	return item;
}