Example usage for com.google.common.base CharMatcher JAVA_ISO_CONTROL

List of usage examples for com.google.common.base CharMatcher JAVA_ISO_CONTROL

Introduction

In this page you can find the example usage for com.google.common.base CharMatcher JAVA_ISO_CONTROL.

Prototype

CharMatcher JAVA_ISO_CONTROL

To view the source code for com.google.common.base CharMatcher JAVA_ISO_CONTROL.

Click Source Link

Document

Determines whether a character is an ISO control character as specified by Character#isISOControl(char) .

Usage

From source file:org.nuxeo.ecm.core.filter.CharacterFilteringServiceImpl.java

@Override
public void registerContribution(Object contrib, String point, ComponentInstance contributor) {
    if (FILTERING_XP.equals(point)) {

        desc = (CharacterFilteringServiceDescriptor) contrib;

        CharMatcher charsToPreserve = CharMatcher.anyOf("\r\n\t");
        CharMatcher allButPreserved = charsToPreserve.negate();
        charsToRemove = CharMatcher.JAVA_ISO_CONTROL.and(allButPreserved);
        charsToRemove = charsToRemove.or(CharMatcher.INVISIBLE.and(CharMatcher.WHITESPACE.negate()));

        List<String> additionalChars = desc.getDisallowedChars();
        String otherCharsToRemove = "";
        if (additionalChars != null && !additionalChars.isEmpty()) {
            for (String c : additionalChars) {
                otherCharsToRemove += StringEscapeUtils.unescapeJava(c);
            }/*  w  w  w . ja  va 2s. co m*/
            charsToRemove = charsToRemove.or(CharMatcher.anyOf(otherCharsToRemove));
        }
    } else {
        throw new RuntimeException("Unknown extension point: " + point);
    }
}

From source file:fr.obeo.ariadne.ide.connector.git.internal.explorer.AriadneCommitExplorerRunnable.java

/**
 * {@inheritDoc}//from w  ww  .  j  a v  a2s  . co  m
 * 
 * @return
 * @see java.lang.Runnable#run()
 */
@Override
public AriadneCommitExplorerEntry call() {
    // commit's settings
    Commit ariadneCommit = ScmFactory.eINSTANCE.createCommit();
    ariadneCommit.setId(this.gitCommit.getId().getName());
    ariadneCommit.setCommitTime(this.gitCommit.getCommitTime());
    ariadneCommit.setName(CharMatcher.JAVA_ISO_CONTROL.removeFrom(this.gitCommit.getName()));
    ariadneCommit.setShortMessage(CharMatcher.JAVA_ISO_CONTROL.removeFrom(this.gitCommit.getShortMessage()));
    ariadneCommit.setFullMessage(CharMatcher.JAVA_ISO_CONTROL.removeFrom(this.gitCommit.getFullMessage()));
    ariadneCommit.setAuthor(this.author);
    ariadneCommit.setCommitter(this.committer);

    // compute file diffs
    Set<ResourceChange> filesChanged = this.computeFilesChanged(gitRepository, this.gitCommit);
    ariadneCommit.getResourceChanges().addAll(filesChanged);

    return new AriadneCommitExplorerEntry(gitCommit, ariadneCommit);
}

From source file:org.apache.awf.web.http.HttpResponseImpl.java

@Override
public void setCookie(String name, String value, long expiration, String domain, String path, boolean secure,
        boolean httpOnly) {
    if (Strings.isNullOrEmpty(name)) {
        throw new IllegalArgumentException("Cookie name is empty");
    }// w  ww.  j a  v a 2s  . c  o m
    if (name.trim().startsWith("$")) {
        throw new IllegalArgumentException("Cookie name is not valid");
    }
    StringBuffer sb = new StringBuffer(name.trim() + "=" + Strings.nullToEmpty(value).trim() + "; ");
    if (CharMatcher.JAVA_ISO_CONTROL.countIn(sb) > 0) {
        throw new IllegalArgumentException("Invalid cookie " + name + ": " + value);
    }
    if (expiration >= 0) {
        if (expiration == 0) {
            sb.append("Expires=" + DateUtil.getDateAsString(new Date(0)) + "; ");
        } else {
            sb.append("Expires=" + CookieUtil.maxAgeToExpires(expiration) + "; ");
        }
    }
    if (!Strings.isNullOrEmpty(domain)) {
        sb.append("Domain=" + domain.trim() + "; ");
    }
    if (!Strings.isNullOrEmpty(path)) {
        sb.append("Path=" + path.trim() + "; ");
    }
    if (secure) {
        sb.append("Secure; ");
    }
    if (httpOnly) {
        sb.append("HttpOnly; ");
    }
    cookies.put(name, sb.toString());
}

From source file:org.gradle.api.internal.tasks.userinput.DefaultUserInputHandler.java

private String sanitizeInput(String input) {
    return CharMatcher.JAVA_ISO_CONTROL.removeFrom(StringUtils.trim(input));
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.EditableTextComponent.java

/**
 * Fires the {@link #EDIT_PROPERTY} property and returns to non-edit mode
 *//*  w w w  . j a v a  2 s . c o  m*/
private void save() {
    this.text = CharMatcher.JAVA_ISO_CONTROL.removeFrom(textPane.getText());
    if (this.text.trim().isEmpty() && !permitEmpty) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                EditableTextComponent.this.text = originalText;
                editField(false);
            }
        });
        return;
    }

    firePropertyChange(EDIT_PROPERTY, originalText, text);
    originalText = text;

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            editField(false);
        }
    });
}

From source file:io.spikex.filter.output.InfluxDb.java

private String escapeSpecialChars(final String str) {
    String escaped = str;/* w ww.  jav a 2 s.  c om*/
    escaped = CharMatcher.is('\\').replaceFrom(escaped, '/'); // Backslash (must be first)
    escaped = CharMatcher.is('@').removeFrom(escaped); // Remove "at" chars (@value => value)
    escaped = CharMatcher.is(',').replaceFrom(escaped, "\\,"); // Comma
    escaped = CharMatcher.is(' ').replaceFrom(escaped, "\\ "); // Space
    escaped = CharMatcher.is('=').replaceFrom(escaped, "\\="); // Equals sign
    escaped = CharMatcher.JAVA_ISO_CONTROL.replaceFrom(escaped, "\\ "); // New line
    return escaped;
}

From source file:fr.obeo.ariadne.ide.connector.git.internal.explorer.GitExplorer.java

/**
 * Gets or creates the Ariadne Person matching the given Git PersonIdent obtained from the Git repository.
 * //www .j  av  a2s . c  om
 * @param ariadneRepository
 *            The Ariadne repository.
 * @param committerIdent
 *            The identity of the committer
 * @return The Ariadne person created or null if none could be created
 */
private Person getOrCreatePerson(fr.obeo.ariadne.model.scm.Repository ariadneRepository,
        PersonIdent committerIdent) {
    Person person = null;
    // Look for an existing person in the whole resource set
    List<Resource> resources = this.resourceSet.getResources();
    for (Resource resource : resources) {
        TreeIterator<EObject> allContents = resource.getAllContents();
        while (allContents.hasNext()) {
            EObject eObject = allContents.next();
            if (eObject instanceof Organization) {
                Organization organization = (Organization) eObject;
                List<Person> persons = organization.getPersons();
                for (Person aPerson : persons) {
                    if (aPerson.getName().equals(committerIdent.getName())) {
                        person = aPerson;
                    }
                }
            } else if (eObject instanceof Person) {
                Person aPerson = (Person) eObject;
                if (aPerson.getName().equals(committerIdent.getName())) {
                    person = aPerson;
                }
            }
            if (person != null) {
                return person;
            }
        }
    }

    // If we haven't find anyone matching the name and email of our choice, create it in the organization
    // of the repository
    EObject eContainer = ariadneRepository.eContainer();
    if (eContainer instanceof Organization) {
        Organization organization = (Organization) eContainer;
        person = CoreFactory.eINSTANCE.createPerson();
        person.setName(CharMatcher.JAVA_ISO_CONTROL.removeFrom(committerIdent.getName()));
        person.setEmail(CharMatcher.JAVA_ISO_CONTROL.removeFrom(committerIdent.getEmailAddress()));
        organization.getPersons().add(person);
    }
    return person;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java

/**
 * Modifies the passed components depending on the value of the
 * passed flag.//from   ww  w  . j  a  va2  s. co  m
 * 
 * @param panel     The panel to handle.
 * @param field      The field to handle.
 * @param editable   Pass <code>true</code> if  to <code>edit</code>,
 *                <code>false</code> otherwise.
 */
private void editField(JComponent field) {
    if (field == namePane) {
        namePane.setEditable(true);
        namePane.setBorder(EDIT_BORDER_BLACK);
        field.requestFocus();

        namePane.getDocument().removeDocumentListener(this);
        String text = namePane.getText();
        if (text != null)
            text = text.trim();

        // the user might have finished editing by hitting return key, therefore
        // remove line break characters
        modifiedName = CharMatcher.JAVA_ISO_CONTROL.removeFrom(modifiedName);
        namePane.setText(modifiedName);
        namePane.setMaximumSize(namePane.getSize());
        namePane.setLineWrap(true);

        namePane.getDocument().addDocumentListener(this);
        namePane.select(0, 0);
        namePane.setCaretPosition(0);
    } else if (field == descriptionWiki) {
        descriptionWiki.setEnabled(true);
        descriptionScrollPane.setBorder(EDIT_BORDER_BLACK);
        field.requestFocus();
    }
}